jen has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I'm trying to use getprotobyname to, well, get the port number for something that's listed in /etc/services on the machine where my script is running.
Here's an example:
$server_port = getprotobyname('talk');
I've tried it with and without parens, with and without quotes, and $server_port is never populated. What's going on here?

Replies are listed 'Best First'.
Re: Trouble with getprotobyname
by nardo (Friar) on Jul 14, 2000 at 20:31 UTC
    getprotobyname() is not made for services, it's made for protocols like tcp and udp. You want:
    $server_port = getservbyname('talk', 'udp');
Re: Trouble with getprotobyname
by Shendal (Hermit) on Jul 14, 2000 at 20:32 UTC
    I think what you're looking for is getservbyname instead of getprotobyname. For example, you may have something like this:
    my($server_port) = getservbyname('talk','tcp');
    Hope that helps!
    --shendal