From 877fab32b43e91b0a55b655a7b7d6ac0844918fd Mon Sep 17 00:00:00 2001 From: "/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=kaber/emailAddress=kaber@netfilter.org" Date: Thu, 20 Jul 2006 17:00:19 +0000 Subject: [PATCH] reduce service_to_port duplication (Phil Oester ) The service_to_port function is used in a number of places, and could benefit from some centralization instead of being duplicated everywhere. --- iptables.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'iptables.c') diff --git a/iptables.c b/iptables.c index 7814986..56921db 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) { -- cgit v1.2.3