This section provides a tutorial example on how to use network utility functions to get default port numbers of standard network services, or get the host name on the network by a given IP address.
getprotobyname($protoName) - Returns the protocol number of the specified protocol name
in scalar context, and ($protoName,$aliases,$protoNumber) in list context.
getservbyname($serviceName,$protoName) - Returns the port number of the specified
network service name and protocol name in scalar context, and
($serviceName,$aliases,$portNumber,$protoName) in list context.
getservbyport($portNumber,$protoName) - Returns the network service name of the specified
port number and protocol name in scalar context, and
($serviceName,$aliases,$portNumber,$protoName) in list context.
gethostbyname($hostName) - Returns the packed IP address of the specified
host name in scalar context, and ($name,$aliases,$addrtype,$length,@addrs) in list
context. The host name can also be specified in IP address format.
gethostbyaddr($packedHostAddress) - Returns the host name of the specified
packed IP address in scalar context, and ($name,$aliases,$addrtype,$length,@addrs)
in list context.
Here is sample program to show you how these functions work: