IPV4_NETMASK, IPV6_NETMASK

Construct the netmask for an IPV4 or IPV6 network, given a number that specifies how many leading bits should be set to 1 in the result.

IPV4_NETMASK(integer)
IPV6_NETMASK(integer)

where integer is in the range of 0 to 32 for IPV4 netmasks and 0 to 128 for IPV6 netmasks.

Each octet in an IPV4 value occupies 8 bits. If the first 24 bits (from 32) are set to 1, the function returns 255.255.255.0. Similarly, if the first 24 bits (from 128) in an IPV6 value are set to 1, the function returns ffff:ff00:0000:0000:0000:0000:0000:0000.

Examples

For example:
premdb=# select ipv4_netmask(24) from sys.const;
 ipv4_netmask  
---------------
 255.255.255.0
(1 row)

premdb=# select ipv4_netmask(18) from sys.const;
 ipv4_netmask  
---------------
 255.255.192.0
(1 row)

premdb=# select ipv6_netmask(18) from sys.const;
              ipv6_netmask               
-----------------------------------------
 ffff:c000:0000:0000:0000:0000:0000:0000
(1 row)

premdb=# select ipv6_netmask(128) from sys.const;
              ipv6_netmask               
-----------------------------------------
 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
(1 row)