4 * Copyright (C) 2000-2003 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: portname.c,v 1.7.2.1 2006/06/16 17:21:09 darrenr Exp
13 char *portname(pr
, port
)
17 struct protoent
*p
= NULL
;
18 struct servent
*sv
= NULL
, *sv1
= NULL
;
20 if ((opts
& OPT_NORESOLVE
) == 0) {
22 if ((sv
= getservbyport(htons(port
), "tcp"))) {
23 strncpy(buf
, sv
->s_name
, sizeof(buf
)-1);
24 buf
[sizeof(buf
)-1] = '\0';
25 sv1
= getservbyport(htons(port
), "udp");
26 sv
= strncasecmp(buf
, sv
->s_name
, strlen(buf
)) ?
31 } else if ((pr
!= -2) && (p
= getprotobynumber(pr
))) {
32 if ((sv
= getservbyport(htons(port
), p
->p_name
))) {
33 strncpy(buf
, sv
->s_name
, sizeof(buf
)-1);
34 buf
[sizeof(buf
)-1] = '\0';
40 (void) sprintf(buf
, "%d", port
);