From c86e48dc7d688d97a6ee4697ce01e594fa70d7db Mon Sep 17 00:00:00 2001 From: "/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org" Date: Sat, 16 Apr 2005 13:30:56 +0000 Subject: add pablo's conntrack tool --- extensions/libct_proto_udp.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 extensions/libct_proto_udp.c (limited to 'extensions/libct_proto_udp.c') diff --git a/extensions/libct_proto_udp.c b/extensions/libct_proto_udp.c new file mode 100644 index 0000000..8022913 --- /dev/null +++ b/extensions/libct_proto_udp.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include /* For htons */ +#include +#include +#include "../include/libct_proto.h" + +static struct option opts[] = { + {"orig-port-src", 1, 0, '1'}, + {"orig-port-dst", 1, 0, '2'}, + {"reply-port-src", 1, 0, '3'}, + {"reply-port-dst", 1, 0, '4'}, + {0, 0, 0, 0} +}; + +int parse(char c, char *argv[], + struct ip_conntrack_tuple *orig, + struct ip_conntrack_tuple *reply) +{ + switch(c) { + case '1': + if (optarg) + orig->src.u.udp.port = htons(atoi(optarg)); + break; + case '2': + if (optarg) + orig->dst.u.udp.port = htons(atoi(optarg)); + break; + case '3': + if (optarg) + reply->src.u.udp.port = htons(atoi(optarg)); + break; + case '4': + if (optarg) + reply->dst.u.udp.port = htons(atoi(optarg)); + break; + } + return 1; +} + +void print(struct ip_conntrack_tuple *t) +{ + printf("sport=%d dport=%d ", ntohs(t->src.u.udp.port), + ntohs(t->dst.u.udp.port)); +} + +static struct ctproto_handler udp = { + .name = "udp", + .protonum = 17, + .parse = parse, + .print = print, + .opts = opts +}; + +void __attribute__ ((constructor)) init(void); +void __attribute__ ((destructor)) fini(void); + +void init(void) +{ + register_proto(&udp); +} + +void fini(void) +{ + unregister_proto(&udp); +} -- cgit v1.2.3