inet_ntoa and inet_aton functions for Postgresql

These functions can be used to convert integer to ip and visa verse. This sometimes also called inet_itoa and inet_atoi.


create or replace function inet_aton(inet) returns bigint as '
select inetmi($1,''0.0.0.0'');'
language sql immutable;
create or replace function inet_ntoa(int) returns inet as '
select ''0.0.0.0''::inet+$1;'
language sql immutable;

=> select inet_ntoa(16843265);
inet_itoa
———–
1.1.2.1
(1 row)

=> select inet_aton(’1.1.2.1′);
inet_atoi
———–
16843265
(1 row)