当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Perl endprotoent用法及代码示例



描述

此函数告诉系统您不再期望使用 getprotoent 从协议列表中读取条目。

用法

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

endprotoent

返回值

此函数不返回任何值。

示例

以下是显示其基本用法的示例代码 -

#!/usr/bin/perl

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

setprotoent(1); # Rewind the database.

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

执行上述代码时,会产生以下结果 -

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 = st
Aliases = ST
Protocol Number = 5
Name = tcp
Aliases = TCP
Protocol Number = 6
.
.
.
Name = manet
Aliases = manet
Protocol Number = 138
Name = hip
Aliases = HIP
Protocol Number = 139
Name = shim6
Aliases = Shim6
Protocol Number = 140

相关用法


注:本文由纯净天空筛选整理自 Perl endprotoent Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。