summaryrefslogtreecommitdiffstats
path: root/iptables.c
diff options
context:
space:
mode:
authorPhil Oester <kernel@linuxace.com>2006-07-20 17:00:19 +0000
committerPatrick McHardy <kaber@trash.net>2006-07-20 17:00:19 +0000
commit58179b1d0d1722ea16028aa2ea9d74afc86dd5dc (patch)
treec7345c2720ad5cf6ffb5ebe4bf5bc985b609ec51 /iptables.c
parent7f5be628f66ec7b8b22e87ace39ee61213c6313b (diff)
reduce service_to_port duplication (Phil Oester <kernel@linuxace.com>)
The service_to_port function is used in a number of places, and could benefit from some centralization instead of being duplicated everywhere.
Diffstat (limited to 'iptables.c')
-rw-r--r--iptables.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/iptables.c b/iptables.c
index 78149862..56921db7 100644
--- a/iptables.c
+++ b/iptables.c
@@ -249,6 +249,17 @@ proto_to_name(u_int8_t proto, int nolookup)
return NULL;
}
+int
+service_to_port(const char *name, const char *proto)
+{
+ struct servent *service;
+
+ if ((service = getservbyname(name, proto)) != NULL)
+ return ntohs((unsigned short) service->s_port);
+
+ return -1;
+}
+
struct in_addr *
dotted_to_addr(const char *dotted)
{