Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / portname.c
blob9ae9ae053e5711253cb07a4734d5f77cb8b12b91
1 /* $NetBSD$ */
3 /*
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
9 */
10 #include "ipf.h"
13 char *portname(pr, port)
14 int pr, port;
16 static char buf[32];
17 struct protoent *p = NULL;
18 struct servent *sv = NULL, *sv1 = NULL;
20 if ((opts & OPT_NORESOLVE) == 0) {
21 if (pr == -1) {
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)) ?
27 NULL : sv1;
29 if (sv)
30 return 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';
35 return buf;
40 (void) sprintf(buf, "%d", port);
41 return buf;