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. --- iptables.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'iptables.c') diff --git a/iptables.c b/iptables.c index 56921db..28917cf 100644 --- a/iptables.c +++ b/iptables.c @@ -260,6 +260,19 @@ service_to_port(const char *name, const char *proto) return -1; } +u_int16_t +parse_port(const char *port, const char *proto) +{ + unsigned int portnum; + + if ((string_to_number(port, 0, 65535, &portnum)) != -1 || + (portnum = service_to_port(port, proto)) != -1) + return (u_int16_t)portnum; + + exit_error(PARAMETER_PROBLEM, + "invalid port/service `%s' specified", port); +} + struct in_addr * dotted_to_addr(const char *dotted) { -- cgit v1.2.3