From 58179b1d0d1722ea16028aa2ea9d74afc86dd5dc Mon Sep 17 00:00:00 2001 From: Phil Oester Date: Thu, 20 Jul 2006 17:00:19 +0000 Subject: 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. --- ip6tables.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'ip6tables.c') diff --git a/ip6tables.c b/ip6tables.c index 82e95950..6dc7aa2d 100644 --- a/ip6tables.c +++ b/ip6tables.c @@ -245,6 +245,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; +} + static void in6addrcpy(struct in6_addr *dst, struct in6_addr *src) { -- cgit v1.2.3