diff options
author | /C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=kaber/emailAddress=kaber@netfilter.org </C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=kaber/emailAddress=kaber@netfilter.org> | 2006-07-20 17:00:19 +0000 |
---|---|---|
committer | /C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=kaber/emailAddress=kaber@netfilter.org </C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=kaber/emailAddress=kaber@netfilter.org> | 2006-07-20 17:00:19 +0000 |
commit | 877fab32b43e91b0a55b655a7b7d6ac0844918fd (patch) | |
tree | c7345c2720ad5cf6ffb5ebe4bf5bc985b609ec51 /extensions | |
parent | 138ab553e6e7e928ff163bdae0ddd0d403c62d56 (diff) |
[PATCH] 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 'extensions')
-rw-r--r-- | extensions/libip6t_multiport.c | 11 | ||||
-rw-r--r-- | extensions/libip6t_tcp.c | 13 | ||||
-rw-r--r-- | extensions/libip6t_udp.c | 13 | ||||
-rw-r--r-- | extensions/libipt_dccp.c | 13 | ||||
-rw-r--r-- | extensions/libipt_mport.c | 11 | ||||
-rw-r--r-- | extensions/libipt_multiport.c | 11 | ||||
-rw-r--r-- | extensions/libipt_sctp.c | 13 | ||||
-rw-r--r-- | extensions/libipt_tcp.c | 13 | ||||
-rw-r--r-- | extensions/libipt_udp.c | 13 |
9 files changed, 6 insertions, 105 deletions
diff --git a/extensions/libip6t_multiport.c b/extensions/libip6t_multiport.c index a8a8e08..d33db9f 100644 --- a/extensions/libip6t_multiport.c +++ b/extensions/libip6t_multiport.c @@ -50,17 +50,6 @@ proto_to_name(u_int8_t proto) } } -static 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 u_int16_t parse_port(const char *port, const char *proto) { diff --git a/extensions/libip6t_tcp.c b/extensions/libip6t_tcp.c index a049128..d89a346 100644 --- a/extensions/libip6t_tcp.c +++ b/extensions/libip6t_tcp.c @@ -38,24 +38,13 @@ static struct option opts[] = { {0} }; -static int -service_to_port(const char *name) -{ - struct servent *service; - - if ((service = getservbyname(name, "tcp")) != NULL) - return ntohs((unsigned short) service->s_port); - - return -1; -} - static u_int16_t parse_tcp_port(const char *port) { unsigned int portnum; if (string_to_number(port, 0, 65535, &portnum) != -1 || - (portnum = service_to_port(port)) != -1) + (portnum = service_to_port(port, "tcp")) != -1) return (u_int16_t)portnum; exit_error(PARAMETER_PROBLEM, diff --git a/extensions/libip6t_udp.c b/extensions/libip6t_udp.c index 842581d..656a79e 100644 --- a/extensions/libip6t_udp.c +++ b/extensions/libip6t_udp.c @@ -30,24 +30,13 @@ static struct option opts[] = { {0} }; -static int -service_to_port(const char *name) -{ - struct servent *service; - - if ((service = getservbyname(name, "udp")) != NULL) - return ntohs((unsigned short) service->s_port); - - return -1; -} - static u_int16_t parse_udp_port(const char *port) { unsigned int portnum; if (string_to_number(port, 0, 65535, &portnum) != -1 || - (portnum = service_to_port(port)) != -1) + (portnum = service_to_port(port, "udp")) != -1) return (u_int16_t)portnum; exit_error(PARAMETER_PROBLEM, diff --git a/extensions/libipt_dccp.c b/extensions/libipt_dccp.c index af1d20e..603be1d 100644 --- a/extensions/libipt_dccp.c +++ b/extensions/libipt_dccp.c @@ -56,17 +56,6 @@ static struct option opts[] = { { .name = 0 } }; -static int -service_to_port(const char *name) -{ - struct servent *service; - - if ((service = getservbyname(name, "dccp")) != NULL) - return ntohs((unsigned short) service->s_port); - - return -1; -} - static u_int16_t parse_dccp_port(const char *port) { @@ -74,7 +63,7 @@ parse_dccp_port(const char *port) DEBUGP("%s\n", port); if (string_to_number(port, 0, 65535, &portnum) != -1 || - (portnum = service_to_port(port)) != -1) + (portnum = service_to_port(port, "dccp")) != -1) return (u_int16_t)portnum; exit_error(PARAMETER_PROBLEM, diff --git a/extensions/libipt_mport.c b/extensions/libipt_mport.c index a387b21..e6975d0 100644 --- a/extensions/libipt_mport.c +++ b/extensions/libipt_mport.c @@ -33,17 +33,6 @@ static struct option opts[] = { {0} }; -static 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 u_int16_t parse_port(const char *port, const char *proto) { diff --git a/extensions/libipt_multiport.c b/extensions/libipt_multiport.c index 97e1476..f25632f 100644 --- a/extensions/libipt_multiport.c +++ b/extensions/libipt_multiport.c @@ -68,17 +68,6 @@ proto_to_name(u_int8_t proto) } } -static 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 u_int16_t parse_port(const char *port, const char *proto) { diff --git a/extensions/libipt_sctp.c b/extensions/libipt_sctp.c index 2d060af..06c48b4 100644 --- a/extensions/libipt_sctp.c +++ b/extensions/libipt_sctp.c @@ -79,17 +79,6 @@ static struct option opts[] = { { .name = 0 } }; -static int -service_to_port(const char *name) -{ - struct servent *service; - - if ((service = getservbyname(name, "sctp")) != NULL) - return ntohs((unsigned short) service->s_port); - - return -1; -} - static u_int16_t parse_sctp_port(const char *port) { @@ -97,7 +86,7 @@ parse_sctp_port(const char *port) DEBUGP("%s\n", port); if (string_to_number(port, 0, 65535, &portnum) != -1 || - (portnum = service_to_port(port)) != -1) + (portnum = service_to_port(port, "sctp")) != -1) return (u_int16_t)portnum; exit_error(PARAMETER_PROBLEM, diff --git a/extensions/libipt_tcp.c b/extensions/libipt_tcp.c index f8ed249..7551a0a 100644 --- a/extensions/libipt_tcp.c +++ b/extensions/libipt_tcp.c @@ -38,24 +38,13 @@ static struct option opts[] = { {0} }; -static int -service_to_port(const char *name) -{ - struct servent *service; - - if ((service = getservbyname(name, "tcp")) != NULL) - return ntohs((unsigned short) service->s_port); - - return -1; -} - static u_int16_t parse_tcp_port(const char *port) { unsigned int portnum; if (string_to_number(port, 0, 65535, &portnum) != -1 || - (portnum = service_to_port(port)) != -1) + (portnum = service_to_port(port, "tcp")) != -1) return (u_int16_t)portnum; exit_error(PARAMETER_PROBLEM, diff --git a/extensions/libipt_udp.c b/extensions/libipt_udp.c index f45f364..a49e8f7 100644 --- a/extensions/libipt_udp.c +++ b/extensions/libipt_udp.c @@ -30,24 +30,13 @@ static struct option opts[] = { {0} }; -static int -service_to_port(const char *name) -{ - struct servent *service; - - if ((service = getservbyname(name, "udp")) != NULL) - return ntohs((unsigned short) service->s_port); - - return -1; -} - static u_int16_t parse_udp_port(const char *port) { unsigned int portnum; if (string_to_number(port, 0, 65535, &portnum) != -1 || - (portnum = service_to_port(port)) != -1) + (portnum = service_to_port(port, "udp")) != -1) return (u_int16_t)portnum; exit_error(PARAMETER_PROBLEM, |