Perl getprotoent 函数



说明

此函数从此列表中返回下列有效协议的下一项:($name, $别名, $协议号)

语法

以下是此函数的简单语法——

getprotoent

返回值

此函数在标量上下文中返回错误时的未定义项,否则返回错误的协议号;在列表上下文中返回空列表错误协议记录(名称、别名、协议号)。

示例

以下示例代码演示了它的基本用法——

#!/usr/bin/perl

while(($name, $aliases, $protocol_number) = getprotoent()) {
   print "Name = $name\n";
   print "Aliases = $aliases\n";
   print "Protocol Number = $protocol_number\n";
}

当以上代码执行时,它生成以下结果——

Name = ip
Aliases = IP
Protocol Number = 0
Name = hopopt
Aliases = HOPOPT
Protocol Number = 0
Name = icmp
Aliases = ICMP
Protocol Number = 1
Name = igmp
Aliases = IGMP
Protocol Number = 2
Name = ggp
Aliases = GGP
Protocol Number = 3
Name = ipencap
Aliases = IP-ENCAP
Protocol Number = 4
.
.
.
Name = udplite
Aliases = UDPLite
Protocol Number = 136
Name = mpls-in-ip
Aliases = MPLS-in-IP
Protocol Number = 137
Name = manet
Aliases = manet
Protocol Number = 138
Name = hip
Aliases = HIP
Protocol Number = 139
Name = shim6
Aliases = Shim6
Protocol Number = 140
perl_function_references.htm
广告