setprotoent
优质
小牛编辑
131浏览
2023-12-01
描述 (Description)
应在第一次调用getprotoent之前调用此函数。 STAYOPEN参数是可选的,在大多数系统中都未使用。 当getprotoent()查看协议数据库中下一行的信息时,setprotoent会将枚举设置(或重置)到主机条目集的开头。
语法 (Syntax)
以下是此函数的简单语法 -
setprotoent STAYOPEN
返回值 (Return Value)
此函数不返回任何值。
例子 (Example)
以下是显示其基本用法的示例代码 -
#!/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 = rsvp-e2e-ignore
Aliases = RSVP-E2E-IGNORE
Protocol Number = 134
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