summaryrefslogtreecommitdiffstats
path: root/contrib/ipfilter/lib/portname.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ipfilter/lib/portname.c')
-rw-r--r--contrib/ipfilter/lib/portname.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/contrib/ipfilter/lib/portname.c b/contrib/ipfilter/lib/portname.c
new file mode 100644
index 0000000..7c0fc87
--- /dev/null
+++ b/contrib/ipfilter/lib/portname.c
@@ -0,0 +1,42 @@
+/* $NetBSD$ */
+
+/*
+ * Copyright (C) 1993-2001 by Darren Reed.
+ *
+ * See the IPFILTER.LICENCE file for details on licencing.
+ *
+ * Id: portname.c,v 1.7 2003/08/14 14:27:43 darrenr Exp
+ */
+#include "ipf.h"
+
+
+char *portname(pr, port)
+int pr, port;
+{
+ static char buf[32];
+ struct protoent *p = NULL;
+ struct servent *sv = NULL, *sv1 = NULL;
+
+ if ((opts & OPT_NORESOLVE) == 0) {
+ if (pr == -1) {
+ if ((sv = getservbyport(htons(port), "tcp"))) {
+ strncpy(buf, sv->s_name, sizeof(buf)-1);
+ buf[sizeof(buf)-1] = '\0';
+ sv1 = getservbyport(htons(port), "udp");
+ sv = strncasecmp(buf, sv->s_name, strlen(buf)) ?
+ NULL : sv1;
+ }
+ if (sv)
+ return buf;
+ } else if ((pr != -2) && (p = getprotobynumber(pr))) {
+ if ((sv = getservbyport(htons(port), p->p_name))) {
+ strncpy(buf, sv->s_name, sizeof(buf)-1);
+ buf[sizeof(buf)-1] = '\0';
+ return buf;
+ }
+ }
+ }
+
+ (void) sprintf(buf, "%d", port);
+ return buf;
+}
OpenPOWER on IntegriCloud