TOR: fix compilation
[tomato.git] / release / src / router / miniupnpd / pf / testobsdrdr.c
blob13d9ee56ee333b95d8d0e28d1d4101b7890b338f
1 /* $Id: testobsdrdr.c,v 1.28 2014/03/06 13:02:47 nanard Exp $ */
2 /* MiniUPnP project
3 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4 * (c) 2006-2014 Thomas Bernard
5 * This software is subject to the conditions detailed
6 * in the LICENCE file provided within the distribution */
8 #include <string.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <sys/types.h>
12 #include <netinet/in.h>
13 #include <syslog.h>
15 #include "obsdrdr.h"
17 /*int logpackets = 1;*/
18 int runtime_flags = 0;
19 const char * tag = 0;
20 const char * anchor_name = "miniupnpd";
21 const char * queue = NULL;
23 void
24 list_rules(void);
26 void
27 list_eports_tcp(void)
29 unsigned short * port_list;
30 unsigned int number = 0;
31 unsigned int i;
32 port_list = get_portmappings_in_range(0, 65535, IPPROTO_TCP, &number);
33 printf("%u ports redirected (TCP) :", number);
34 for(i = 0; i < number; i++)
36 printf(" %hu", port_list[i]);
38 printf("\n");
39 free(port_list);
42 void
43 test_index(void)
45 char ifname[16/*IFNAMSIZ*/];
46 char iaddr[32];
47 char desc[64];
48 char rhost[32];
49 unsigned short iport = 0;
50 unsigned short eport = 0;
51 int proto = 0;
52 unsigned int timestamp;
53 ifname[0] = '\0';
54 iaddr[0] = '\0';
55 rhost[0] = '\0';
56 if(get_redirect_rule_by_index(0, ifname, &eport, iaddr, sizeof(iaddr),
57 &iport, &proto, desc, sizeof(desc),
58 rhost, sizeof(rhost),
59 &timestamp, 0, 0) < 0)
61 printf("get.._by_index : no rule\n");
63 else
65 printf("%s %u -> %s:%u proto %d\n", ifname, (unsigned int)eport,
66 iaddr, (unsigned int)iport, proto);
67 printf("description: \"%s\"\n", desc);
71 int
72 main(int argc, char * * argv)
74 char buf[32];
75 char desc[64];
76 char rhost[64];
77 /*char rhost[32];*/
78 unsigned short iport;
79 unsigned int timestamp;
80 u_int64_t packets = 0;
81 u_int64_t bytes = 0;
82 int clear = 0;
84 if(argc > 1) {
85 if(0 == strcmp(argv[1], "--clear") || 0 == strcmp(argv[1], "-c"))
86 clear = 1;
89 openlog("testobsdrdr", LOG_PERROR, LOG_USER);
90 if(init_redirect() < 0)
92 fprintf(stderr, "init_redirect() failed\n");
93 return 1;
95 #if 0
96 add_redirect_rule("ep0", 12123, "192.168.1.23", 1234);
97 add_redirect_rule2("ep0", 12155, "192.168.1.155", 1255, IPPROTO_TCP);
98 #endif
99 if(add_redirect_rule2("ep0", "8.8.8.8", 12123, "192.168.1.125", 1234,
100 IPPROTO_UDP, "test description", 0) < 0)
101 printf("add_redirect_rule2() #3 failed\n");
102 if(add_redirect_rule2("em0", NULL, 12123, "127.1.2.3", 1234,
103 IPPROTO_TCP, "test description tcp", 0) < 0)
104 printf("add_redirect_rule2() #4 failed\n");
105 if(add_filter_rule2("em0", NULL, "127.1.2.3", 12123, 1234, IPPROTO_TCP,
106 "test description tcp") < 0)
107 printf("add_filter_rule2() #1 failed\n");
109 list_rules();
110 list_eports_tcp();
113 if(get_redirect_rule("xl1", 4662, IPPROTO_TCP,
114 buf, sizeof(buf), &iport, desc, sizeof(desc),
115 rhost, sizeof(rhost),
116 &timestamp,
117 &packets, &bytes) < 0)
118 printf("get_redirect_rule() failed\n");
119 else
121 printf("\n%s:%d '%s' packets=%llu bytes=%llu\n", buf, (int)iport, desc,
122 packets, bytes);
125 if(delete_redirect_rule("ep0", 12123, IPPROTO_UDP) < 0)
126 printf("delete_redirect_rule() failed\n");
128 if(delete_redirect_rule("ep0", 12123, IPPROTO_UDP) < 0)
129 printf("delete_redirect_rule() failed\n");
131 if(delete_redirect_and_filter_rules("em0", 12123, IPPROTO_TCP) < 0)
132 printf("delete_redirect_and_filter_rules() failed\n");
134 test_index();
136 if(clear) {
137 clear_redirect_rules();
138 clear_filter_rules();
140 /*list_rules();*/
142 return 0;