The getservbyport function retrieves information from the /etc/services file.
# Format: getservbyport(PORT, PROTOCOL);
#!/bin/perl
print "What is the port number? ";
chomp($PORT=<>);
print "What is the protocol? ";
chomp($PROTOCOL=<>);
($name, $aliases, $port, $proto ) = getservbyport($PORT, $PROTOCOL);
print "The getservbyport function returns:
name=$name
aliases=$aliases
port number=$port
prototype=$protocol \n";
Related examples in the same category