示例
以下是显示其基本用法的示例代码-
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 = egp
Aliases = EGP
Protocol Number = 8
Name = igp
Aliases = IGP
Protocol Number = 9
Name = pup
Aliases = PUP
Protocol Number = 12
Name = udp
Aliases = UDP
Protocol Number = 17
Name = hmp
Aliases = HMP
Protocol Number = 20
Name = xns-idp
Aliases = XNS-IDP
Protocol Number = 22
Name = rdp
Aliases = RDP
Protocol Number = 27
Name = iso-tp4
Aliases = ISO-TP4
Protocol Number = 29
Name = dccp
Aliases = DCCP
Protocol Number = 33
Name = xtp
Aliases = XTP
Protocol Number = 36
Name = ddp
Aliases = DDP
Protocol Number = 37
Name = idpr-cmtp
Aliases = IDPR-CMTP
Protocol Number = 38
Name = ipv6
Aliases = IPv6
Protocol Number = 41
Name = ipv6-route
Aliases = IPv6-Route
Protocol Number = 43
Name = ipv6-frag
Aliases = IPv6-Frag