Syntax
getservbyport PORT, PROTO
|
Definition and Usage
Translates the service number PORT for the protocol PROTO, returning the service
name in a scalar context and the name and associated information in a list context:
($name, $aliases, $port_number, $protocol_name)
This call returns these values based on /etc/services file.
Return Value
In scalar context undef on error otherwise service number
In list context empty list on error otherwise Service record (name, aliases, port
number, protocol name).
Example
Try out following example:
#!/usr/bin/perl
($name, $aliases, $port_number,
$protocol_name) = getservbyport(21, "tcp");
print "Name = $name\n";
print "Aliases = $aliases\n";
print "Port Number = $port_number\n";
print "Protocol Name = $protocol_name\n";
It will produce following result
Name = ftp
Aliases =
Port Number = 21
Protocol Name = tcp
|
|