summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Oester <kernel@linuxace.com>2006-07-22 14:10:53 +0000
committerPatrick McHardy <kaber@trash.net>2006-07-22 14:10:53 +0000
commita6c1d926f6c3c00e0c1875d80b9579c95bde2cfa (patch)
treef0e3e44030eb3278ec8098e53e2acd2b02154bf0
parent04a1e4cabd185d7a93bea1ece276343044d9ecd4 (diff)
proto_to_name duplication (Phil Oester <kernel@linuxace.com>)
Update multiport match to use the iptables version of proto_to_name instead of reinventing the wheel.
-rw-r--r--extensions/libipt_multiport.c21
-rw-r--r--include/iptables.h1
-rw-r--r--iptables.c3
3 files changed, 5 insertions, 20 deletions
diff --git a/extensions/libipt_multiport.c b/extensions/libipt_multiport.c
index 2a10abd4..28fd8503 100644
--- a/extensions/libipt_multiport.c
+++ b/extensions/libipt_multiport.c
@@ -51,23 +51,6 @@ static struct option opts[] = {
{0}
};
-static char *
-proto_to_name(u_int8_t proto)
-{
- switch (proto) {
- case IPPROTO_TCP:
- return "tcp";
- case IPPROTO_UDP:
- return "udp";
- case IPPROTO_SCTP:
- return "sctp";
- case IPPROTO_DCCP:
- return "dccp";
- default:
- return NULL;
- }
-}
-
static unsigned int
parse_multi_ports(const char *portstring, u_int16_t *ports, const char *proto)
{
@@ -143,7 +126,7 @@ check_proto(const struct ipt_entry *entry)
exit_error(PARAMETER_PROBLEM,
"multiport only works with TCP or UDP");
- if ((proto = proto_to_name(entry->ip.proto)) != NULL)
+ if ((proto = proto_to_name(entry->ip.proto, 1)) != NULL)
return proto;
else if (!entry->ip.proto)
exit_error(PARAMETER_PROBLEM,
@@ -264,7 +247,7 @@ port_to_service(int port, u_int8_t proto)
{
struct servent *service;
- if ((service = getservbyport(htons(port), proto_to_name(proto))))
+ if ((service = getservbyport(htons(port), proto_to_name(proto, 1))))
return service->s_name;
return NULL;
diff --git a/include/iptables.h b/include/iptables.h
index ba27cac6..d616c8c4 100644
--- a/include/iptables.h
+++ b/include/iptables.h
@@ -151,6 +151,7 @@ extern int line;
extern void register_match(struct iptables_match *me);
extern void register_target(struct iptables_target *me);
+extern char *proto_to_name(u_int8_t proto, int nolookup);
extern int service_to_port(const char *name, const char *proto);
extern u_int16_t parse_port(const char *port, const char *proto);
extern struct in_addr *dotted_to_addr(const char *dotted);
diff --git a/iptables.c b/iptables.c
index 28917cf1..74925af0 100644
--- a/iptables.c
+++ b/iptables.c
@@ -229,9 +229,10 @@ static const struct pprot chain_protos[] = {
{ "esp", IPPROTO_ESP },
{ "ah", IPPROTO_AH },
{ "sctp", IPPROTO_SCTP },
+ { "dccp", IPPROTO_DCCP },
};
-static char *
+char *
proto_to_name(u_int8_t proto, int nolookup)
{
unsigned int i;