summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorPhil Oester <kernel@linuxace.com>2006-07-20 17:00:19 +0000
committerPatrick McHardy <kaber@trash.net>2006-07-20 17:00:19 +0000
commit58179b1d0d1722ea16028aa2ea9d74afc86dd5dc (patch)
treec7345c2720ad5cf6ffb5ebe4bf5bc985b609ec51 /extensions
parent7f5be628f66ec7b8b22e87ace39ee61213c6313b (diff)
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.c11
-rw-r--r--extensions/libip6t_tcp.c13
-rw-r--r--extensions/libip6t_udp.c13
-rw-r--r--extensions/libipt_dccp.c13
-rw-r--r--extensions/libipt_mport.c11
-rw-r--r--extensions/libipt_multiport.c11
-rw-r--r--extensions/libipt_sctp.c13
-rw-r--r--extensions/libipt_tcp.c13
-rw-r--r--extensions/libipt_udp.c13
9 files changed, 6 insertions, 105 deletions
diff --git a/extensions/libip6t_multiport.c b/extensions/libip6t_multiport.c
index a8a8e08a..d33db9f2 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 a0491280..d89a3462 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 842581d9..656a79e2 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 af1d20e2..603be1de 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 a387b214..e6975d03 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 97e14765..f25632f0 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 2d060af9..06c48b4e 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 f8ed249a..7551a0a6 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 f45f364c..a49e8f79 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,