Annotation of embedaddon/miniupnpd/pf/testobsdrdr.c, revision 1.1.1.2
1.1.1.2 ! misho 1: /* $Id: testobsdrdr.c,v 1.22 2011/06/04 16:45:22 nanard Exp $ */
1.1 misho 2: /* MiniUPnP project
3: * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
1.1.1.2 ! misho 4: * (c) 2006-2011 Thomas Bernard
1.1 misho 5: * This software is subject to the conditions detailed
6: * in the LICENCE file provided within the distribution */
7:
8: #include <stdio.h>
1.1.1.2 ! misho 9: #include <stdlib.h>
1.1 misho 10: #include <sys/types.h>
11: #include <netinet/in.h>
12: #include <syslog.h>
13:
14: #include "obsdrdr.h"
15:
16: /*int logpackets = 1;*/
17: int runtime_flags = 0;
18: const char * tag = 0;
19:
20: void
21: list_rules(void);
22:
23: void
1.1.1.2 ! misho 24: list_eports_tcp(void)
! 25: {
! 26: unsigned short * port_list;
! 27: unsigned int number = 0;
! 28: unsigned int i;
! 29: port_list = get_portmappings_in_range(0, 65535, IPPROTO_TCP, &number);
! 30: printf("%u ports redirected (TCP) :", number);
! 31: for(i = 0; i < number; i++)
! 32: {
! 33: printf(" %hu", port_list[i]);
! 34: }
! 35: printf("\n");
! 36: free(port_list);
! 37: }
! 38:
! 39: void
1.1 misho 40: test_index(void)
41: {
42: char ifname[16/*IFNAMSIZ*/];
43: char iaddr[32];
44: char desc[64];
1.1.1.2 ! misho 45: char rhost[32];
1.1 misho 46: unsigned short iport = 0;
47: unsigned short eport = 0;
48: int proto = 0;
1.1.1.2 ! misho 49: unsigned int timestamp;
1.1 misho 50: ifname[0] = '\0';
51: iaddr[0] = '\0';
1.1.1.2 ! misho 52: rhost[0] = '\0';
1.1 misho 53: if(get_redirect_rule_by_index(0, ifname, &eport, iaddr, sizeof(iaddr),
54: &iport, &proto, desc, sizeof(desc),
1.1.1.2 ! misho 55: rhost, sizeof(rhost),
! 56: ×tamp, 0, 0) < 0)
1.1 misho 57: {
58: printf("get.._by_index : no rule\n");
59: }
60: else
61: {
62: printf("%s %u -> %s:%u proto %d\n", ifname, (unsigned int)eport,
63: iaddr, (unsigned int)iport, proto);
64: printf("description: \"%s\"\n", desc);
65: }
66: }
67:
68: int
69: main(int arc, char * * argv)
70: {
71: char buf[32];
72: char desc[64];
1.1.1.2 ! misho 73: /*char rhost[32];*/
1.1 misho 74: unsigned short iport;
1.1.1.2 ! misho 75: unsigned int timestamp;
1.1 misho 76: u_int64_t packets = 0;
77: u_int64_t bytes = 0;
78:
79: openlog("testobsdrdr", LOG_PERROR, LOG_USER);
80: if(init_redirect() < 0)
81: {
82: fprintf(stderr, "init_redirect() failed\n");
83: return 1;
84: }
85: //add_redirect_rule("ep0", 12123, "192.168.1.23", 1234);
86: //add_redirect_rule2("ep0", 12155, "192.168.1.155", 1255, IPPROTO_TCP);
1.1.1.2 ! misho 87: add_redirect_rule2("ep0", "8.8.8.8", 12123, "192.168.1.125", 1234,
! 88: IPPROTO_UDP, "test description", 0);
1.1 misho 89: //add_redirect_rule2("em0", 12123, "127.1.2.3", 1234,
90: // IPPROTO_TCP, "test description tcp");
91:
92: list_rules();
1.1.1.2 ! misho 93: list_eports_tcp();
! 94:
1.1 misho 95:
96: if(get_redirect_rule("xl1", 4662, IPPROTO_TCP,
1.1.1.2 ! misho 97: buf, sizeof(buf), &iport, desc, sizeof(desc),
! 98: ×tamp,
1.1 misho 99: &packets, &bytes) < 0)
100: printf("get_redirect_rule() failed\n");
101: else
102: {
103: printf("\n%s:%d '%s' packets=%llu bytes=%llu\n", buf, (int)iport, desc,
104: packets, bytes);
105: }
106: #if 0
107: if(delete_redirect_rule("ep0", 12123, IPPROTO_UDP) < 0)
108: printf("delete_redirect_rule() failed\n");
109: else
110: printf("delete_redirect_rule() succeded\n");
111:
112: if(delete_redirect_rule("ep0", 12123, IPPROTO_UDP) < 0)
113: printf("delete_redirect_rule() failed\n");
114: else
115: printf("delete_redirect_rule() succeded\n");
116: #endif
117: //test_index();
118:
119: //clear_redirect_rules();
120: //list_rules();
121:
122: return 0;
123: }
124:
125:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>