masklen()

返回网络掩码长度的函数

masklen() 是一个系统函数,用于返回提供IP地址的子网掩码长度(以比特为单位)。

masklen() 函数在 PostgreSQL 6.4 中被添加。

用法

masklen ( inet ) → integer

如果提供了无效值,则会引发 ERROR 错误。

变更历史

示例

masklen() 的基本用法示例

postgres=# SELECT masklen('192.168.1.2/24');
 masklen 
---------
      24
(1 row)

如果提供的地址不包含网络掩码,则返回 32

postgres=# SELECT masklen('192.168.1.2');
 masklen 
---------
      32
(1 row)

如果提供了无效地址,则会引发 ERROR 错误

postgres=# SELECT masklen('192.168.1.2/99');
ERROR:  invalid input syntax for type inet: "192.168.1.2/99"
LINE 1: SELECT masklen('192.168.1.2/99');

分类

网络, 系统函数

另请参阅

netmask(), host(), broadcast(), abbrev()

反馈

提交关于“masklen()”的任何评论、建议或更正,请 在此处 进行。