-- $Id: wfwl_functions 704 2020-06-08 19:39:51Z bhockney $
--
CREATE OR REPLACE FUNCTION $WFWL_SCHEMA.webfwlog_ntoa (int8) RETURNS text
AS 'SELECT
	(mod((trunc ($1 / 2^24))::int4, 256))::text || ''.'' ||
	(mod((trunc ($1 / 2^16))::int4, 256))::text || ''.'' ||
	(mod((trunc ($1 / 2^ 8))::int4, 256))::text || ''.'' ||
	(mod((trunc ($1 / 2^ 0))::int8, 256::int8))::text'
LANGUAGE 'sql'
STRICT
IMMUTABLE;
--
CREATE OR REPLACE FUNCTION $WFWL_SCHEMA.webfwlog_aton (text) RETURNS int8
AS 'SELECT
	   (split_part($1, ''.'', 1)::int8 * 2^24)::int8
	 + (split_part($1, ''.'', 2)::int8 * 2^16)::int8
	 + (split_part($1, ''.'', 3)::int8 * 2^8 )::int8
	 + (split_part($1, ''.'', 4)::int8 * 2^0 )::int8'
LANGUAGE 'sql'
STRICT
IMMUTABLE;
--
CREATE OR REPLACE FUNCTION $WFWL_SCHEMA.webfwlog_aton (inet) RETURNS int8
AS 'SELECT
	   (split_part(host($1), ''.'', 1)::int8 * 2^24)::int8
	 + (split_part(host($1), ''.'', 2)::int8 * 2^16)::int8
	 + (split_part(host($1), ''.'', 3)::int8 * 2^8 )::int8
	 + (split_part(host($1), ''.'', 4)::int8 * 2^0 )::int8'
LANGUAGE 'sql'
STRICT
IMMUTABLE;
