9.12. Функции и операторы для работы с сетевыми адресами
В Таблица 9.37 показаны операторы, работающие с типами cidr и inet. Операторы <<, <<=, >>, >>= и && проверяют включения подсетей, рассматривая только биты сети в обоих адресах (игнорируя биты узлов) и определяя, идентична ли одна сеть другой или её подсети.
Таблица 9.37. Операторы для типов cidr и inet
| Оператор | Описание | Пример |
|---|---|---|
< | меньше | inet '192.168.1.5' < inet '192.168.1.6' |
<= | меньше или равно | inet '192.168.1.5' <= inet '192.168.1.5' |
= | равно | inet '192.168.1.5' = inet '192.168.1.5' |
>= | больше или равно | inet '192.168.1.5' >= inet '192.168.1.5' |
> | больше | inet '192.168.1.5' > inet '192.168.1.4' |
<> | не равно | inet '192.168.1.5' <> inet '192.168.1.4' |
<< | содержится в | inet '192.168.1.5' << inet '192.168.1/24' |
<<= | равно или содержится в | inet '192.168.1/24' <<= inet '192.168.1/24' |
>> | содержит | inet '192.168.1/24' >> inet '192.168.1.5' |
>>= | равно или содержит | inet '192.168.1/24' >>= inet '192.168.1/24' |
&& | содержит или содержится в | inet '192.168.1/24' && inet '192.168.1.80/28' |
~ | битовый NOT | ~ inet '192.168.1.6' |
& | битовый AND | inet '192.168.1.6' & inet '0.0.0.255' |
| | битовый OR | inet '192.168.1.6' | inet '0.0.0.255' |
+ | сложение | inet '192.168.1.6' + 25 |
- | вычитание | inet '192.168.1.43' - 36 |
- | вычитание | inet '192.168.1.43' - inet '192.168.1.19' |
В Таблице 9.38 перечислены функции, работающие с типами cidr и inet. Функции abbrev, host и text предназначены в основном для вывода данных в альтернативных форматах.
Таблица 9.38. Функции для типов cidr и inet
Любое значение cidr можно привести к типу inet, явно или нет; поэтому все функции, показанные выше с типом inet, также будут работать со значениями cidr. (Некоторые из функций указаны отдельно для типов inet и cidr, потому что их поведение с разными типами различается.) Кроме того, значение inet тоже можно привести к типу cidr. При этом все биты справа от сетевой маски просто обнуляются, чтобы значение стало допустимым для типа cidr. К типам inet и cidr можно привести и обычные текстовые значения, используя обычный синтаксис, например: inet( или выражение).столбец::cidr
В Таблице 9.39 приведена функция, предназначенная для работы с типом macaddr. Функция возвращает MAC-адрес, последние 3 байта в котором равны 0. Это может быть полезно для вычисления префикса, определяющего производителя.trunc(macaddr)
Таблица 9.39. Функции macaddr
Тип macaddr также поддерживает стандартные реляционные операторы лексической сортировки (>, <= и т. д.) и операторы битовой арифметики (~, & и |), соответствующие операциям NOT, AND и OR.
В Таблице 9.40 приведены функции, предназначенные для работы с типом macaddr8. Функция возвращает MAC-адрес, последние 5 байт в котором равны нулю. Это может быть полезно для вычисления префикса, определяющего производителя.trunc(macaddr8)
Таблица 9.40. Функции macaddr8
Тип macaddr8 также поддерживает стандартные реляционные операторы лексической сортировки (>, <= и т. д.) и операторы битовой арифметики (~, & и |), соответствующие операциям NOT, AND и OR.
9.12. Network Address Functions and Operators
Table 9.37 shows the operators available for the cidr and inet 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.37. cidr and inet Operators
| Operator | Description | Example |
|---|---|---|
< | is less than | inet '192.168.1.5' < inet '192.168.1.6' |
<= | is less than or equal | inet '192.168.1.5' <= inet '192.168.1.5' |
= | equals | inet '192.168.1.5' = inet '192.168.1.5' |
>= | is greater or equal | inet '192.168.1.5' >= inet '192.168.1.5' |
> | is greater than | inet '192.168.1.5' > inet '192.168.1.4' |
<> | is not equal | inet '192.168.1.5' <> inet '192.168.1.4' |
<< | is contained by | inet '192.168.1.5' << inet '192.168.1/24' |
<<= | is contained by or equals | inet '192.168.1/24' <<= inet '192.168.1/24' |
>> | contains | inet '192.168.1/24' >> inet '192.168.1.5' |
>>= | contains or equals | inet '192.168.1/24' >>= inet '192.168.1/24' |
&& | contains or is contained by | inet '192.168.1/24' && inet '192.168.1.80/28' |
~ | bitwise NOT | ~ inet '192.168.1.6' |
& | bitwise AND | inet '192.168.1.6' & inet '0.0.0.255' |
| | bitwise OR | inet '192.168.1.6' | inet '0.0.0.255' |
+ | addition | inet '192.168.1.6' + 25 |
- | subtraction | inet '192.168.1.43' - 36 |
- | subtraction | inet '192.168.1.43' - inet '192.168.1.19' |
Table 9.38 shows the functions available for use with the cidr and inet types. The abbrev, host, and text functions are primarily intended to offer alternative display formats.
Table 9.38. cidr and inet Functions
Any cidr value can be cast to inet implicitly or explicitly; therefore, the functions shown above 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. In addition, you can cast a text value to inet or cidr using normal casting syntax: for example, inet( or expression). colname::cidr
Table 9.39 shows the functions available for use with the macaddr type. The function returns a MAC address with the last 3 bytes set to zero. This can be used to associate the remaining prefix with a manufacturer. trunc(macaddr)
Table 9.39. macaddr Functions
The macaddr type also supports the standard relational operators (>, <=, etc.) for lexicographical ordering, and the bitwise arithmetic operators (~, & and |) for NOT, AND and OR.
Table 9.40 shows the functions available for use with the macaddr8 type. The function returns a MAC address with the last 5 bytes set to zero. This can be used to associate the remaining prefix with a manufacturer. trunc(macaddr8)
Table 9.40. macaddr8 Functions
The macaddr8 type also supports the standard relational operators (>, <=, etc.) for ordering, and the bitwise arithmetic operators (~, & and |) for NOT, AND and OR.