1 /* $Id: testobsdrdr.c,v 1.17 2007/06/11 12:46:35 nanard Exp $ */
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 */
10 #include <netinet/in.h>
22 char ifname
[16/*IFNAMSIZ*/];
25 unsigned short iport
= 0;
26 unsigned short eport
= 0;
30 if(get_redirect_rule_by_index(0, ifname
, &eport
, iaddr
, sizeof(iaddr
),
31 &iport
, &proto
, desc
, sizeof(desc
),
34 printf("get.._by_index : no rule\n");
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
);
45 main(int arc
, char * * argv
)
50 u_int64_t packets
= 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");
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");
65 printf("\n%s:%d '%s' packets=%llu bytes=%llu\n", buf
, (int)iport
, desc
,
69 if(delete_redirect_rule("ep0", 12123, IPPROTO_UDP
) < 0)
70 printf("delete_redirect_rule() failed\n");
72 printf("delete_redirect_rule() succeded\n");
74 if(delete_redirect_rule("ep0", 12123, IPPROTO_UDP
) < 0)
75 printf("delete_redirect_rule() failed\n");
77 printf("delete_redirect_rule() succeded\n");
81 //clear_redirect_rules();