Tomato 1.24
[tomato.git] / release / src / router / miniupnpd / pf / testobsdrdr.c
blob2ff2761ac384a709f769b755a906f8bc7719b5ce
1 /* $Id: testobsdrdr.c,v 1.17 2007/06/11 12:46:35 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 */
8 #include <stdio.h>
9 #include <sys/types.h>
10 #include <netinet/in.h>
12 #include "obsdrdr.h"
14 int logpackets = 1;
16 void
17 list_rules(void);
19 void
20 test_index(void)
22 char ifname[16/*IFNAMSIZ*/];
23 char iaddr[32];
24 char desc[64];
25 unsigned short iport = 0;
26 unsigned short eport = 0;
27 int proto = 0;
28 ifname[0] = '\0';
29 iaddr[0] = '\0';
30 if(get_redirect_rule_by_index(0, ifname, &eport, iaddr, sizeof(iaddr),
31 &iport, &proto, desc, sizeof(desc),
32 0, 0) < 0)
34 printf("get.._by_index : no rule\n");
36 else
38 printf("%s %u -> %s:%u proto %d\n", ifname, (unsigned int)eport,
39 iaddr, (unsigned int)iport, proto);
40 printf("description: \"%s\"\n", desc);
44 int
45 main(int arc, char * * argv)
47 char buf[32];
48 char desc[64];
49 unsigned short iport;
50 u_int64_t packets = 0;
51 u_int64_t bytes = 0;
52 //add_redirect_rule("ep0", 12123, "192.168.1.23", 1234);
53 //add_redirect_rule2("ep0", 12155, "192.168.1.155", 1255, IPPROTO_TCP);
54 //add_redirect_rule2("ep0", 12123, "192.168.1.125", 1234,
55 // IPPROTO_UDP, "test description");
57 list_rules();
59 if(get_redirect_rule("xl1", 4662, IPPROTO_TCP,
60 buf, 32, &iport, desc, sizeof(desc),
61 &packets, &bytes) < 0)
62 printf("get_redirect_rule() failed\n");
63 else
65 printf("\n%s:%d '%s' packets=%llu bytes=%llu\n", buf, (int)iport, desc,
66 packets, bytes);
68 #if 0
69 if(delete_redirect_rule("ep0", 12123, IPPROTO_UDP) < 0)
70 printf("delete_redirect_rule() failed\n");
71 else
72 printf("delete_redirect_rule() succeded\n");
74 if(delete_redirect_rule("ep0", 12123, IPPROTO_UDP) < 0)
75 printf("delete_redirect_rule() failed\n");
76 else
77 printf("delete_redirect_rule() succeded\n");
78 #endif
79 //test_index();
81 //clear_redirect_rules();
82 //list_rules();
84 return 0;