1 /* $Id: testiptcrdr_peer.c,v 1.1 2013/12/13 13:10:48 nanard Exp $ */
3 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4 * (c) 2006-2012 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>
14 #include "../commonrdr.h"
22 main(int argc
, char ** argv
)
24 unsigned short eport
, iport
, rport
;
25 const char * eaddr
, *iaddr
, *rhost
;
26 printf("Usage %s <ext_ip> <ext_port> <internal_ip> <internal_port> <peer_ip> <peer_port>\n", argv
[0]);
30 openlog("testiptcrdr_peer", LOG_PERROR
|LOG_CONS
, LOG_LOCAL0
);
32 eport
= (unsigned short)atoi(argv
[2]);
34 iport
= (unsigned short)atoi(argv
[4]);
36 rport
= (unsigned short)atoi(argv
[6]);
38 printf("trying to redirect port %hu to %s:%hu\n", eport
, iaddr
, iport
);
39 if(addpeernatrule(IPPROTO_TCP
, eaddr
, eport
, iaddr
, iport
, rhost
, rport
) < 0)
44 unsigned short p1
, p2
;
49 unsigned int timestamp
;
50 u_int64_t packets
, bytes
;
53 if(get_redirect_rule_by_index(0, "", &p1
,
54 addr
, sizeof(addr
), &p2
,
55 &proto2
, desc
, sizeof(desc
),
58 &packets
, &bytes
) < 0)
60 printf("rule not found\n");
64 printf("redirected port %hu to %s:%hu proto %d packets=%" PRIu64
" bytes=%" PRIu64
"\n",
65 p1
, addr
, p2
, proto2
, packets
, bytes
);
68 printf("trying to list nat rules :\n");
69 list_redirect_rule(argv
[1]);
71 delete_redirect_and_filter_rules(eport
, IPPROTO_TCP
);