From 18c7ec36ac949aaaf28aa25d11c0289a88d35592 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:01:54 +0000 Subject: [PATCH] reduce parse_*_port duplication (Phil Oester ) The below patch (dependent upon my 'reduce service_to_port duplication' patch) centralizes the parse_*_port functions into parse_port. --- extensions/libipt_tcp.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'extensions/libipt_tcp.c') diff --git a/extensions/libipt_tcp.c b/extensions/libipt_tcp.c index 7551a0a..c712b92 100644 --- a/extensions/libipt_tcp.c +++ b/extensions/libipt_tcp.c @@ -38,19 +38,6 @@ static struct option opts[] = { {0} }; -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, "tcp")) != -1) - return (u_int16_t)portnum; - - exit_error(PARAMETER_PROBLEM, - "invalid TCP port/service `%s' specified", port); -} - static void parse_tcp_ports(const char *portstring, u_int16_t *ports) { @@ -59,13 +46,13 @@ parse_tcp_ports(const char *portstring, u_int16_t *ports) buffer = strdup(portstring); if ((cp = strchr(buffer, ':')) == NULL) - ports[0] = ports[1] = parse_tcp_port(buffer); + ports[0] = ports[1] = parse_port(buffer, "tcp"); else { *cp = '\0'; cp++; - ports[0] = buffer[0] ? parse_tcp_port(buffer) : 0; - ports[1] = cp[0] ? parse_tcp_port(cp) : 0xFFFF; + ports[0] = buffer[0] ? parse_port(buffer, "tcp") : 0; + ports[1] = cp[0] ? parse_port(cp, "tcp") : 0xFFFF; if (ports[0] > ports[1]) exit_error(PARAMETER_PROBLEM, -- cgit v1.2.3