Perl getprotoent Function

Advertisements


Description

This function returns the next entry from the list of valid protocols: ($name, $aliases, $protocol_number)

Syntax

Following is the simple syntax for this function:

getprotoent

Return Value

This function returns undef on error otherwise protocol number in scalar context and empty list on error protocol record (name, aliases, protocol number) in list context.

Example

Following is the example code showing its basic usage:

#!/usr/bin/perl

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

When above code is executed, it produced following result

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


Advertisements
Advertisements