Skip to content

IPV4_GET_MASKBITS, IPV6_GET_MASKBITS

Return the number of netmask bits from a formatted IPV4 or IPV6 address string.

IPV4_GET_MASKBITS(text)
IPV6_GET_MASKBITS(text)

where text is a formatted string that represents an IP address. These functions return an integer. If there are no netmask bits in the input string, the result is 0.

For example:

premdb=# select ipv4_get_maskbits('192.168.0.0/22') from sys.const;
 ipv4_get_maskbits 
-------------------
               22
(1 row)
premdb=# select ipv6_get_maskbits('2001:0db8:85a3:0000:0000:8a2e:0370:7334') from sys.const;
 ipv6_get_maskbits 
-------------------
                0
(1 row)

Parent topic:Network Address Functions