1/* $Id: testiptcrdr.c,v 1.18 2012/04/24 22:41:53 nanard Exp $ */
2/* MiniUPnP project
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 */
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <netinet/in.h>
11#include <syslog.h>
12
13#include "iptcrdr.h"
14#include "../commonrdr.h"
15#include "iptcrdr.c"
16
17#ifndef PRIu64
18#define PRIu64 "llu"
19#endif
20
21int
22main(int argc, char ** argv)
23{
24	unsigned char dscp;
25	unsigned short iport, rport;
26	const char * iaddr, *rhost;
27	printf("Usage %s <dscp> <internal_ip> <internal_port> <peer_ip> <peer_port>\n", argv[0]);
28
29	if(argc<6)
30		return -1;
31	openlog("testiptcrdr_peer", LOG_PERROR|LOG_CONS, LOG_LOCAL0);
32	dscp = (unsigned short)atoi(argv[1]);
33	iaddr = argv[2];
34	iport = (unsigned short)atoi(argv[3]);
35	rhost = argv[4];
36	rport = (unsigned short)atoi(argv[5]);
37#if 1
38	if(addpeerdscprule(IPPROTO_TCP, dscp, iaddr, iport, rhost, rport) < 0)
39		return -1;
40#endif
41	/* test */
42	{
43		unsigned short p1, p2;
44		char addr[16];
45		int proto2;
46		char desc[256];
47		char rhost[256];
48		unsigned int timestamp;
49		u_int64_t packets, bytes;
50
51		desc[0] = '\0';
52		if(get_redirect_rule_by_index(0, "", &p1,
53									  addr, sizeof(addr), &p2,
54									  &proto2, desc, sizeof(desc),
55									  rhost, sizeof(rhost),
56									  &timestamp,
57									  &packets, &bytes) < 0)
58		{
59			printf("rule not found\n");
60		}
61		else
62		{
63			printf("redirected port %hu to %s:%hu proto %d   packets=%" PRIu64 " bytes=%" PRIu64 "\n",
64			       p1, addr, p2, proto2, packets, bytes);
65		}
66	}
67	printf("trying to list nat rules :\n");
68	list_redirect_rule(argv[1]);
69	printf("deleting\n");
70//	delete_redirect_and_filter_rules(eport, IPPROTO_TCP);
71	return 0;
72}
73
74