IP - Functions for manipulating IP addresses and prefixes
i int; n_address IP.address; n_prefix IP.prefix; address varchar(64); prefix varchar(64);
i := IP.family(address|prefix); n_address := IP.normalize(address); n_prefix := IP.normalize(prefix); address := IP.host(address|prefix); prefix := IP.text(address|prefix); prefix := IP.network(address|prefix); address := IP.broadcast(address|prefix); address := IP.netmask(address|prefix); i := IP.masklen(address|prefix); i := IP.difference(address, address);
address := IP.plus(address, delta);
There are many valid formats for IP addresses and prefixes, but only two of them are used in the NetDB database. The functions in this package can be used to convert input IP addresses and prefixes to those formats or between those formats. This package also provides a function for calculating the nth IP address from a given IP address.
When used as functional input or output, address and prefix have specific meanings in this document:
address == d.d.d.d where 0 <= d <= 255 (IPv4) x:x:x:x:x:x:x:x where 0 <= x <= ffff (IPv6)
prefix == address/l where 0 <= l <= 32 (IPv4) 0 <= l <= 128 (IPv6)
Throughout this document we refer to the IP address and prefix formats shown above as familiar formats to distinguish them from the NetDB normalized formats.
A normalized IP address or prefix is one that has been recast into the NetDB internal storage format. Unlike the familiar forms of IP addresses and prefixes, the normalized versions sort properly. It is important to use normalized IP addresses and prefixes when doing comparisons in NetDB.
Always use these types for normalized IP addresses and prefixes.
Check for the input IP address in the NetDB IPaddress table:
select count(*) from IPaddress where IPaddress = IP.normalize(input)
Get the prefix (in familiar format) of the address space containing the input IP address:
select prefix_txt from IPaddressSpace where IP.normalize(input) between address and broadcast
Except for family(), IPv6 support is not implemented.