#!/bin/env perl

use strict;
use warnings;
use Getopt::Long;

GetOptions(
    'n' => \my $bynumber,
) or die "Wrong options given\n";

my ($serv, $proto) = @ARGV;
$proto or die "Usage: $0 [-n] SERVICE PROTOCOL\n";

my @service = ($bynumber
    ? getservbyport($serv, $proto)
    : getservbyname($serv, $proto))
    or die "Service $proto/$serv no found\n";

print(($bynumber ? $service[0] : $service[2]), "\n");
