10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * Copyright (C) 1993-2001 by Darren Reed.
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * See the IPFILTER.LICENCE file for details on licencing.
50Sstevel@tonic-gate *
6*2393Syz155240 * $Id: portname.c,v 1.7 2003/08/14 14:27:43 darrenr Exp $
70Sstevel@tonic-gate */
80Sstevel@tonic-gate #include "ipf.h"
90Sstevel@tonic-gate
100Sstevel@tonic-gate
portname(pr,port)110Sstevel@tonic-gate char *portname(pr, port)
120Sstevel@tonic-gate int pr, port;
130Sstevel@tonic-gate {
140Sstevel@tonic-gate static char buf[32];
150Sstevel@tonic-gate struct protoent *p = NULL;
160Sstevel@tonic-gate struct servent *sv = NULL, *sv1 = NULL;
170Sstevel@tonic-gate
18*2393Syz155240 if ((opts & OPT_NORESOLVE) == 0) {
19*2393Syz155240 if (pr == -1) {
20*2393Syz155240 if ((sv = getservbyport(htons(port), "tcp"))) {
21*2393Syz155240 strncpy(buf, sv->s_name, sizeof(buf)-1);
22*2393Syz155240 buf[sizeof(buf)-1] = '\0';
23*2393Syz155240 sv1 = getservbyport(htons(port), "udp");
24*2393Syz155240 sv = strncasecmp(buf, sv->s_name, strlen(buf)) ?
25*2393Syz155240 NULL : sv1;
26*2393Syz155240 }
27*2393Syz155240 if (sv)
28*2393Syz155240 return buf;
29*2393Syz155240 } else if ((pr != -2) && (p = getprotobynumber(pr))) {
30*2393Syz155240 if ((sv = getservbyport(htons(port), p->p_name))) {
31*2393Syz155240 strncpy(buf, sv->s_name, sizeof(buf)-1);
32*2393Syz155240 buf[sizeof(buf)-1] = '\0';
33*2393Syz155240 return buf;
34*2393Syz155240 }
350Sstevel@tonic-gate }
360Sstevel@tonic-gate }
370Sstevel@tonic-gate
380Sstevel@tonic-gate (void) sprintf(buf, "%d", port);
390Sstevel@tonic-gate return buf;
400Sstevel@tonic-gate }
41