]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
reduce service_to_port duplication (Phil Oester <kernel@linuxace.com>)
authorPhil Oester <kernel@linuxace.com>
Thu, 20 Jul 2006 17:00:19 +0000 (17:00 +0000)
committerPatrick McHardy <kaber@trash.net>
Thu, 20 Jul 2006 17:00:19 +0000 (17:00 +0000)
The service_to_port function is used in a number of places, and could
benefit from some centralization instead of being duplicated everywhere.

13 files changed:
extensions/libip6t_multiport.c
extensions/libip6t_tcp.c
extensions/libip6t_udp.c
extensions/libipt_dccp.c
extensions/libipt_mport.c
extensions/libipt_multiport.c
extensions/libipt_sctp.c
extensions/libipt_tcp.c
extensions/libipt_udp.c
include/ip6tables.h
include/iptables.h
ip6tables.c
iptables.c

index a8a8e08ab0917be460ce5c7861fe0234de3cabb2..d33db9f2f4924f991e7f53718298998d829e0efa 100644 (file)
@@ -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)
 {
index a0491280260729c2729d51cf117234ced01603e4..d89a346227c78f203506e020efaf1d45a5fe3bd9 100644 (file)
@@ -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,
index 842581d95e9f1e4b3d77a91f2b02fb3fce9d9bdc..656a79e272a4a759a154e3f917bf98f76c9fb898 100644 (file)
@@ -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,
index af1d20e23696faf1bc1c7fc5f78e35cc9396baba..603be1de1dda4695668988af827800a262e25eec 100644 (file)
@@ -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,
index a387b2141439a3dcc019ed7b2e534b57402aed09..e6975d03864d476c0de4787d0c850a3f357a1cbf 100644 (file)
@@ -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)
 {
index 97e1476576f44ca8eea13c843a50f6f9a7656d62..f25632f0ed12d1b54dea43b71dcc7e612be1283c 100644 (file)
@@ -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)
 {
index 2d060af9586e17bb863bf7facff2188bdad6dd1d..06c48b4eda57e25806453e841297903456c74c88 100644 (file)
@@ -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,
index f8ed249aa029271b987427a2301c86a661a68cb2..7551a0a65a9af3838dc894bee2392b50102adfa6 100644 (file)
@@ -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,
index f45f364ca06608ccbaf777193f81aa0b7937f1c6..a49e8f79ddb2aedac4e76254e51304e9284b112c 100644 (file)
@@ -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,
index 96f9798b7bef06155bf691d4ace1d8a968ddd4b0..e711982ceaac60b510043e1110361edbef29a005 100644 (file)
@@ -133,6 +133,7 @@ extern int line;
 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. */
index 1cd9dc4196ec5fbbd3cfafca5118a44f8adaacd7..4465e59b3fcc7c3c2254ed873da10d41f1403b5d 100644 (file)
@@ -151,6 +151,7 @@ extern int line;
 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);
index 82e9595061587635b8845a8f6e52cb8cbd36e014..6dc7aa2da3d80e56ff3157a9578f826299046e9f 100644 (file)
@@ -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)
 {
index 781498628484c93e61140b83c016f4c4f696d6ab..56921db7af552e80c850322ff5b73f420e1b77e9 100644 (file)
@@ -249,6 +249,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;
+}
+
 struct in_addr *
 dotted_to_addr(const char *dotted)
 {