Annotation of embedaddon/miniupnpd/netfilter/testiptcrdr.c, revision 1.1.1.2
1.1.1.2 ! misho 1: /* $Id: testiptcrdr.c,v 1.16 2011/03/02 16:04:23 nanard Exp $ */
1.1 misho 2: /* MiniUPnP project
3: * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
1.1.1.2 ! misho 4: * (c) 2006-2011 Thomas Bernard
1.1 misho 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:
1.1.1.2 ! misho 15: #ifndef PRIu64
! 16: #define PRIu64 "llu"
! 17: #endif
! 18:
1.1 misho 19: int
20: main(int argc, char ** argv)
21: {
22: unsigned short eport, iport;
23: const char * iaddr;
24: printf("Usage %s <ext_port> <internal_ip> <internal_port>\n", argv[0]);
25:
26: if(argc<4)
27: return -1;
1.1.1.2 ! misho 28: openlog("testiptcrdr", LOG_PERROR|LOG_CONS, LOG_LOCAL0);
1.1 misho 29: eport = (unsigned short)atoi(argv[1]);
30: iaddr = argv[2];
31: iport = (unsigned short)atoi(argv[3]);
32: printf("trying to redirect port %hu to %s:%hu\n", eport, iaddr, iport);
33: if(addnatrule(IPPROTO_TCP, eport, iaddr, iport) < 0)
34: return -1;
35: if(add_filter_rule(IPPROTO_TCP, iaddr, iport) < 0)
36: return -1;
37: /* test */
38: {
39: unsigned short p1, p2;
40: char addr[16];
41: int proto2;
42: char desc[256];
43: u_int64_t packets, bytes;
44: desc[0] = '\0';
45: if(get_redirect_rule_by_index(0, "", &p1, addr, sizeof(addr),
46: &p2, &proto2, desc, sizeof(desc),
47: &packets, &bytes) < 0)
48: {
1.1.1.2 ! misho 49: printf("rule not found\n");
1.1 misho 50: }
51: else
52: {
1.1.1.2 ! misho 53: printf("redirected port %hu to %s:%hu proto %d packets=%" PRIu64 " bytes=%" PRIu64 "\n",
! 54: p1, addr, p2, proto2, packets, bytes);
1.1 misho 55: }
56: }
57: printf("trying to list nat rules :\n");
58: list_redirect_rule(argv[1]);
59: printf("deleting\n");
60: delete_redirect_and_filter_rules(eport, IPPROTO_TCP);
61: return 0;
62: }
63:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>