Annotation of embedaddon/miniupnpd/netfilter/testiptcrdr.c, revision 1.1.1.1
1.1 misho 1: /* $Id: testiptcrdr.c,v 1.14 2007/06/11 13:25:25 nanard Exp $ */
2: /* MiniUPnP project
3: * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4: * (c) 2006 Thomas Bernard
5: * This software is subject to the conditions detailed
6: * in the LICENCE file provided within the distribution */
7:
8: #include <stdio.h>
9: #include <stdlib.h>
10: #include <netinet/in.h>
11: #include <syslog.h>
12:
13: #include "iptcrdr.h"
14:
15: int
16: main(int argc, char ** argv)
17: {
18: unsigned short eport, iport;
19: const char * iaddr;
20: printf("Usage %s <ext_port> <internal_ip> <internal_port>\n", argv[0]);
21:
22: if(argc<4)
23: return -1;
24: openlog("testuptcrdr", LOG_PERROR|LOG_CONS, LOG_LOCAL0);
25: eport = (unsigned short)atoi(argv[1]);
26: iaddr = argv[2];
27: iport = (unsigned short)atoi(argv[3]);
28: printf("trying to redirect port %hu to %s:%hu\n", eport, iaddr, iport);
29: if(addnatrule(IPPROTO_TCP, eport, iaddr, iport) < 0)
30: return -1;
31: if(add_filter_rule(IPPROTO_TCP, iaddr, iport) < 0)
32: return -1;
33: /* test */
34: {
35: unsigned short p1, p2;
36: char addr[16];
37: int proto2;
38: char desc[256];
39: u_int64_t packets, bytes;
40: desc[0] = '\0';
41: if(get_redirect_rule_by_index(0, "", &p1, addr, sizeof(addr),
42: &p2, &proto2, desc, sizeof(desc),
43: &packets, &bytes) < 0)
44: {
45: printf("redirected port %hu to %s:%hu proto %d packets=%llu bytes=%llu\n",
46: p1, addr, p2, proto2, packets, bytes);
47: }
48: else
49: {
50: printf("rule not found\n");
51: }
52: }
53: printf("trying to list nat rules :\n");
54: list_redirect_rule(argv[1]);
55: printf("deleting\n");
56: delete_redirect_and_filter_rules(eport, IPPROTO_TCP);
57: return 0;
58: }
59:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>