[netfilter-cvslog] r6646 - in trunk/iptables: . extensions include

kaber at netfilter.org kaber at netfilter.org
Thu Jul 20 19:00:21 CEST 2006


Author: kaber at netfilter.org
Date: 2006-07-20 19:00:19 +0200 (Thu, 20 Jul 2006)
New Revision: 6646

Modified:
   trunk/iptables/extensions/libip6t_multiport.c
   trunk/iptables/extensions/libip6t_tcp.c
   trunk/iptables/extensions/libip6t_udp.c
   trunk/iptables/extensions/libipt_dccp.c
   trunk/iptables/extensions/libipt_mport.c
   trunk/iptables/extensions/libipt_multiport.c
   trunk/iptables/extensions/libipt_sctp.c
   trunk/iptables/extensions/libipt_tcp.c
   trunk/iptables/extensions/libipt_udp.c
   trunk/iptables/include/ip6tables.h
   trunk/iptables/include/iptables.h
   trunk/iptables/ip6tables.c
   trunk/iptables/iptables.c
Log:
[PATCH] reduce service_to_port duplication (Phil Oester <kernel at 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.


Modified: trunk/iptables/extensions/libip6t_multiport.c
===================================================================
--- trunk/iptables/extensions/libip6t_multiport.c	2006-07-20 16:59:04 UTC (rev 6645)
+++ trunk/iptables/extensions/libip6t_multiport.c	2006-07-20 17:00:19 UTC (rev 6646)
@@ -50,17 +50,6 @@
 	}
 }
 
-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)
 {

Modified: trunk/iptables/extensions/libip6t_tcp.c
===================================================================
--- trunk/iptables/extensions/libip6t_tcp.c	2006-07-20 16:59:04 UTC (rev 6645)
+++ trunk/iptables/extensions/libip6t_tcp.c	2006-07-20 17:00:19 UTC (rev 6646)
@@ -38,24 +38,13 @@
 	{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,

Modified: trunk/iptables/extensions/libip6t_udp.c
===================================================================
--- trunk/iptables/extensions/libip6t_udp.c	2006-07-20 16:59:04 UTC (rev 6645)
+++ trunk/iptables/extensions/libip6t_udp.c	2006-07-20 17:00:19 UTC (rev 6646)
@@ -30,24 +30,13 @@
 	{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,

Modified: trunk/iptables/extensions/libipt_dccp.c
===================================================================
--- trunk/iptables/extensions/libipt_dccp.c	2006-07-20 16:59:04 UTC (rev 6645)
+++ trunk/iptables/extensions/libipt_dccp.c	2006-07-20 17:00:19 UTC (rev 6646)
@@ -56,17 +56,6 @@
 	{ .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 @@
 
 	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,

Modified: trunk/iptables/extensions/libipt_mport.c
===================================================================
--- trunk/iptables/extensions/libipt_mport.c	2006-07-20 16:59:04 UTC (rev 6645)
+++ trunk/iptables/extensions/libipt_mport.c	2006-07-20 17:00:19 UTC (rev 6646)
@@ -33,17 +33,6 @@
 	{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)
 {

Modified: trunk/iptables/extensions/libipt_multiport.c
===================================================================
--- trunk/iptables/extensions/libipt_multiport.c	2006-07-20 16:59:04 UTC (rev 6645)
+++ trunk/iptables/extensions/libipt_multiport.c	2006-07-20 17:00:19 UTC (rev 6646)
@@ -68,17 +68,6 @@
 	}
 }
 
-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)
 {

Modified: trunk/iptables/extensions/libipt_sctp.c
===================================================================
--- trunk/iptables/extensions/libipt_sctp.c	2006-07-20 16:59:04 UTC (rev 6645)
+++ trunk/iptables/extensions/libipt_sctp.c	2006-07-20 17:00:19 UTC (rev 6646)
@@ -79,17 +79,6 @@
 	{ .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 @@
 
 	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,

Modified: trunk/iptables/extensions/libipt_tcp.c
===================================================================
--- trunk/iptables/extensions/libipt_tcp.c	2006-07-20 16:59:04 UTC (rev 6645)
+++ trunk/iptables/extensions/libipt_tcp.c	2006-07-20 17:00:19 UTC (rev 6646)
@@ -38,24 +38,13 @@
 	{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,

Modified: trunk/iptables/extensions/libipt_udp.c
===================================================================
--- trunk/iptables/extensions/libipt_udp.c	2006-07-20 16:59:04 UTC (rev 6645)
+++ trunk/iptables/extensions/libipt_udp.c	2006-07-20 17:00:19 UTC (rev 6646)
@@ -30,24 +30,13 @@
 	{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,

Modified: trunk/iptables/include/ip6tables.h
===================================================================
--- trunk/iptables/include/ip6tables.h	2006-07-20 16:59:04 UTC (rev 6645)
+++ trunk/iptables/include/ip6tables.h	2006-07-20 17:00:19 UTC (rev 6646)
@@ -133,6 +133,7 @@
 extern void register_match6(struct ip6tables_match *me);
 extern void register_target6(struct ip6tables_target *me);
 
+extern int service_to_port(const char *name, const char *proto);
 extern int do_command6(int argc, char *argv[], char **table,
 		       ip6tc_handle_t *handle);
 /* Keeping track of external matches and targets: linked lists. */

Modified: trunk/iptables/include/iptables.h
===================================================================
--- trunk/iptables/include/iptables.h	2006-07-20 16:59:04 UTC (rev 6645)
+++ trunk/iptables/include/iptables.h	2006-07-20 17:00:19 UTC (rev 6646)
@@ -151,6 +151,7 @@
 extern void register_match(struct iptables_match *me);
 extern void register_target(struct iptables_target *me);
 
+extern int service_to_port(const char *name, const char *proto);
 extern struct in_addr *dotted_to_addr(const char *dotted);
 extern char *addr_to_dotted(const struct in_addr *addrp);
 extern char *addr_to_anyname(const struct in_addr *addr);

Modified: trunk/iptables/ip6tables.c
===================================================================
--- trunk/iptables/ip6tables.c	2006-07-20 16:59:04 UTC (rev 6645)
+++ trunk/iptables/ip6tables.c	2006-07-20 17:00:19 UTC (rev 6646)
@@ -245,6 +245,17 @@
 	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)
 {

Modified: trunk/iptables/iptables.c
===================================================================
--- trunk/iptables/iptables.c	2006-07-20 16:59:04 UTC (rev 6645)
+++ trunk/iptables/iptables.c	2006-07-20 17:00:19 UTC (rev 6646)
@@ -249,6 +249,17 @@
 	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)
 {




More information about the netfilter-cvslog mailing list