9.12. 網路位址函式及運算子
Table 9.36shows the operators available for thecidr
andinet
types. The operators<<
,<<=
,>>
,>>=
, and&&
test for subnet inclusion. They consider only the network parts of the two addresses (ignoring any host part) and determine whether one network is identical to or a subnet of the other.
**Table 9.36. **cidr
andinet
Operators
Operator | Description | Example | ||
---|---|---|---|---|
| is less than |
| ||
| is less than or equal |
| ||
| equals |
| ||
| is greater or equal |
| ||
| is greater than |
| ||
| is not equal |
| ||
| is contained by |
| ||
| is contained by or equals |
| ||
| contains |
| ||
| contains or equals |
| ||
| contains or is contained by |
| ||
| bitwise NOT |
| ||
| bitwise AND |
| ||
` | ` | bitwise OR | `inet '192.168.1.6' | inet '0.0.0.255'` |
| addition |
| ||
| subtraction |
| ||
| subtraction |
|
Table 9.37shows the functions available for use with thecidr
andinet
types. Theabbrev
,host
, andtext
functions are primarily intended to offer alternative display formats.
**Table 9.37. **cidr
andinet
Functions
Function | Return Type | Description | Example | Result |
---|---|---|---|---|
|
| abbreviated display format as text |
|
|
|
| abbreviated display format as text |
|
|
|
| broadcast address for network |
|
|
|
| extract family of address; |
|
|
|
| extract IP address as text |
|
|
|
| construct host mask for network |
|
|
|
| extract netmask length |
|
|
|
| construct netmask for network |
|
|
|
| extract network part of address |
|
|
|
| set netmask length for |
|
|
|
| set netmask length for |
|
|
|
| extract IP address and netmask length as text |
|
|
|
| are the addresses from the same family? |
|
|
|
| the smallest network which includes both of the given networks |
|
|
Anycidr
value can be cast toinet
implicitly or explicitly; therefore, the functions shown above as operating oninet
also work oncidr
values. (Where there are separate functions forinet
andcidr
, it is because the behavior should be different for the two cases.) Also, it is permitted to cast aninet
value tocidr
. When this is done, any bits to the right of the netmask are silently zeroed to create a validcidr
value. In addition, you can cast a text value toinet
orcidr
using normal casting syntax: for example,inet(expression
)orcolname
::cidr.
Table 9.38shows the functions available for use with themacaddr
type. The functiontrunc(macaddr
)returns a MAC address with the last 3 bytes set to zero. This can be used to associate the remaining prefix with a manufacturer.
**Table 9.38. **macaddr
Functions
Function | Return Type | Description | Example | Result |
---|---|---|---|---|
|
| set last 3 bytes to zero |
|
|
Themacaddr
type also supports the standard relational operators (>
,<=
, etc.) for lexicographical ordering, and the bitwise arithmetic operators (~
,&
and|
) for NOT, AND and OR.
Table 9.39shows the functions available for use with themacaddr8
type. The functiontrunc(macaddr8
)returns a MAC address with the last 5 bytes set to zero. This can be used to associate the remaining prefix with a manufacturer.
**Table 9.39. **macaddr8
Functions
Function | Return Type | Description | Example | Result |
---|---|---|---|---|
|
| set last 5 bytes to zero |
|
|
|
| set 7th bit to one, also known as modified EUI-64, for inclusion in an IPv6 address |
|
|
Themacaddr8
type also supports the standard relational operators (>
,<=
, etc.) for ordering, and the bitwise arithmetic operators (~
,&
and|
) for NOT, AND and OR.
Last updated