|
|
| version 1.1.1.1, 2012/02/21 23:16:02 | version 1.1.1.2, 2012/05/29 12:55:57 |
|---|---|
| Line 1 | Line 1 |
| /* $Id$ */ | /* $Id$ */ |
| /* MiniUPnP project | /* MiniUPnP project |
| * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ | * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ |
| * (c) 2006-2010 Thomas Bernard | * (c) 2006-2011 Thomas Bernard |
| * This software is subject to the conditions detailed | * This software is subject to the conditions detailed |
| * in the LICENCE file provided within the distribution */ | * in the LICENCE file provided within the distribution */ |
| #include <stdio.h> | #include <stdio.h> |
| #include <stdlib.h> | |
| #include <sys/types.h> | #include <sys/types.h> |
| #include <netinet/in.h> | #include <netinet/in.h> |
| #include <syslog.h> | #include <syslog.h> |
| Line 20 void | Line 21 void |
| list_rules(void); | list_rules(void); |
| void | void |
| list_eports_tcp(void) | |
| { | |
| unsigned short * port_list; | |
| unsigned int number = 0; | |
| unsigned int i; | |
| port_list = get_portmappings_in_range(0, 65535, IPPROTO_TCP, &number); | |
| printf("%u ports redirected (TCP) :", number); | |
| for(i = 0; i < number; i++) | |
| { | |
| printf(" %hu", port_list[i]); | |
| } | |
| printf("\n"); | |
| free(port_list); | |
| } | |
| void | |
| test_index(void) | test_index(void) |
| { | { |
| char ifname[16/*IFNAMSIZ*/]; | char ifname[16/*IFNAMSIZ*/]; |
| char iaddr[32]; | char iaddr[32]; |
| char desc[64]; | char desc[64]; |
| char rhost[32]; | |
| unsigned short iport = 0; | unsigned short iport = 0; |
| unsigned short eport = 0; | unsigned short eport = 0; |
| int proto = 0; | int proto = 0; |
| unsigned int timestamp; | |
| ifname[0] = '\0'; | ifname[0] = '\0'; |
| iaddr[0] = '\0'; | iaddr[0] = '\0'; |
| rhost[0] = '\0'; | |
| if(get_redirect_rule_by_index(0, ifname, &eport, iaddr, sizeof(iaddr), | if(get_redirect_rule_by_index(0, ifname, &eport, iaddr, sizeof(iaddr), |
| &iport, &proto, desc, sizeof(desc), | &iport, &proto, desc, sizeof(desc), |
| 0, 0) < 0) | rhost, sizeof(rhost), |
| ×tamp, 0, 0) < 0) | |
| { | { |
| printf("get.._by_index : no rule\n"); | printf("get.._by_index : no rule\n"); |
| } | } |
| Line 49 main(int arc, char * * argv) | Line 70 main(int arc, char * * argv) |
| { | { |
| char buf[32]; | char buf[32]; |
| char desc[64]; | char desc[64]; |
| /*char rhost[32];*/ | |
| unsigned short iport; | unsigned short iport; |
| unsigned int timestamp; | |
| u_int64_t packets = 0; | u_int64_t packets = 0; |
| u_int64_t bytes = 0; | u_int64_t bytes = 0; |
| Line 61 main(int arc, char * * argv) | Line 84 main(int arc, char * * argv) |
| } | } |
| //add_redirect_rule("ep0", 12123, "192.168.1.23", 1234); | //add_redirect_rule("ep0", 12123, "192.168.1.23", 1234); |
| //add_redirect_rule2("ep0", 12155, "192.168.1.155", 1255, IPPROTO_TCP); | //add_redirect_rule2("ep0", 12155, "192.168.1.155", 1255, IPPROTO_TCP); |
| //add_redirect_rule2("ep0", 12123, "192.168.1.125", 1234, | add_redirect_rule2("ep0", "8.8.8.8", 12123, "192.168.1.125", 1234, |
| // IPPROTO_UDP, "test description"); | IPPROTO_UDP, "test description", 0); |
| //add_redirect_rule2("em0", 12123, "127.1.2.3", 1234, | //add_redirect_rule2("em0", 12123, "127.1.2.3", 1234, |
| // IPPROTO_TCP, "test description tcp"); | // IPPROTO_TCP, "test description tcp"); |
| list_rules(); | list_rules(); |
| list_eports_tcp(); | |
| if(get_redirect_rule("xl1", 4662, IPPROTO_TCP, | if(get_redirect_rule("xl1", 4662, IPPROTO_TCP, |
| buf, 32, &iport, desc, sizeof(desc), | buf, sizeof(buf), &iport, desc, sizeof(desc), |
| ×tamp, | |
| &packets, &bytes) < 0) | &packets, &bytes) < 0) |
| printf("get_redirect_rule() failed\n"); | printf("get_redirect_rule() failed\n"); |
| else | else |