The IP network address types, cidr
and inet
,
support the usual comparison operators shown in
Table 9.1
as well as the specialized operators and functions shown in
Table 9.39 and
Table 9.40.
Any cidr
value can be cast to inet
implicitly;
therefore, the operators and functions shown below as operating on
inet
also work on cidr
values. (Where there are
separate functions for inet
and cidr
, it is
because the behavior should be different for the two cases.)
Also, it is permitted to cast an inet
value
to cidr
. When this is done, any bits to the right of the
netmask are silently zeroed to create a valid cidr
value.
Table 9.39. IP Address Operators
Table 9.40. IP Address Functions
Function Description Example(s) |
---|
Creates an abbreviated display format as text.
(The result is the same as the
|
Creates an abbreviated display format as text. (The abbreviation consists of dropping all-zero octets to the right of the netmask; more examples are in Table 8.22.)
|
Computes the broadcast address for the address's network.
|
Returns the address's family:
|
Returns the IP address as text, ignoring the netmask.
|
Computes the host mask for the address's network.
|
Computes the smallest network that includes both of the given networks.
|
Tests whether the addresses belong to the same IP family.
|
Returns the netmask length in bits.
|
Computes the network mask for the address's network.
|
Returns the network part of the address, zeroing out
whatever is to the right of the netmask.
(This is equivalent to casting the value to
|
Sets the netmask length for an
|
Sets the netmask length for a
|
Returns the unabbreviated IP address and netmask length as text.
(This has the same result as an explicit cast to
|
The abbrev
, host
,
and text
functions are primarily intended to offer
alternative display formats for IP addresses.
The MAC address types, macaddr
and macaddr8
,
support the usual comparison operators shown in
Table 9.1
as well as the specialized functions shown in
Table 9.41.
In addition, they support the bitwise logical operators
~
, &
and |
(NOT, AND and OR), just as shown above for IP addresses.
Table 9.41. MAC Address Functions