2 * Copyright (C) 1993-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * $Id: portname.c,v 1.7 2003/08/14 14:27:43 darrenr Exp $
11 char *portname(pr
, port
)
15 struct protoent
*p
= NULL
;
16 struct servent
*sv
= NULL
, *sv1
= NULL
;
18 if ((opts
& OPT_NORESOLVE
) == 0) {
20 if ((sv
= getservbyport(htons(port
), "tcp"))) {
21 strncpy(buf
, sv
->s_name
, sizeof(buf
)-1);
22 buf
[sizeof(buf
)-1] = '\0';
23 sv1
= getservbyport(htons(port
), "udp");
24 sv
= strncasecmp(buf
, sv
->s_name
, strlen(buf
)) ?
29 } else if ((pr
!= -2) && (p
= getprotobynumber(pr
))) {
30 if ((sv
= getservbyport(htons(port
), p
->p_name
))) {
31 strncpy(buf
, sv
->s_name
, sizeof(buf
)-1);
32 buf
[sizeof(buf
)-1] = '\0';
38 (void) sprintf(buf
, "%d", port
);