1 /* $Id: testipfwrdr.c,v 1.6 2011/06/04 15:47:18 nanard Exp $ */
4 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
5 * (c) 2009-2011 Jardel Weyrich, Thomas Bernard
6 * This software is subject to the conditions detailed
7 * in the LICENCE file provided within the distribution
13 #include <netinet/in.h>
16 // test program for ipfwrdr.c
17 static const char * ifname
= "lo0";
20 list_port_mappings(void)
29 unsigned int timestamp
;
30 u_int64_t packets
, bytes
;
32 printf("== Port Mapping List ==\n");
40 if(get_redirect_rule_by_index(i
, 0/*ifname*/, &eport
, iaddr
, sizeof(iaddr
),
41 &iport
, &proto
, desc
, sizeof(desc
),
43 ×tamp
, &packets
, &bytes
) < 0)
45 printf("%2d - %5hu=>%15s:%5hu %d '%s' %u %" PRIu64
" %" PRIu64
"\n",
46 i
, eport
, iaddr
, iport
, proto
, desc
, timestamp
,
49 printf("== %d Port Mapping%s ==\n", i
, (i
> 1)?"s":"");
52 int main(int argc
, char * * argv
) {
53 unsigned int timestamp
;
56 unsigned short iport
= 0;
57 const char * rhost
= "8.8.8.8";
61 openlog("testipfwrdrd", LOG_CONS
| LOG_PERROR
, LOG_USER
);
62 if(init_redirect() < 0) {
63 fprintf(stderr
, "init_redirect() failed.\n");
67 delete_redirect_rule(ifname
, 2222, IPPROTO_TCP
);
68 add_redirect_rule2(ifname
, rhost
, 2222,
69 "10.1.1.16", 4444, IPPROTO_TCP
,
70 "test miniupnpd", time(NULL
) + 60);
71 get_redirect_rule(ifname
, 2222, IPPROTO_TCP
, addr
, sizeof(addr
), &iport
,
72 desc
, sizeof(desc
), ×tamp
, NULL
, NULL
);
73 printf("%s:%hu '%s' %u\n", addr
, iport
, desc
, timestamp
);
75 delete_redirect_rule(ifname
, 2222, IPPROTO_TCP
);