version 1.1.1.1, 2012/02/21 23:16:02
|
version 1.1.1.2, 2013/07/22 00:32:35
|
Line 1
|
Line 1
|
/* $Id$ */ |
/* $Id$ */ |
|
|
#include <stdio.h> |
#include <stdio.h> |
|
#include <stdlib.h> |
#include <syslog.h> |
#include <syslog.h> |
#include <netinet/in.h> |
#include <netinet/in.h> |
|
#include <sys/types.h> |
#include "ipfrdr.h" |
#include "ipfrdr.h" |
|
|
extern void |
|
test_list_nat_rules(); |
|
/* test program for ipfrdr.c */ |
/* test program for ipfrdr.c */ |
|
|
|
int runtime_flags = 0; |
|
|
|
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); |
|
port_list = get_portmappings_in_range(0, 65535, IPPROTO_UDP, &number); |
|
printf("%u ports redirected (UDP) :", number); |
|
for(i = 0; i < number; i++) |
|
{ |
|
printf(" %hu", port_list[i]); |
|
} |
|
printf("\n"); |
|
free(port_list); |
|
} |
|
|
int |
int |
main(int argc, char * * argv) |
main(int argc, char * * argv) |
{ |
{ |
|
char c; |
|
|
openlog("testipfrdrd", LOG_CONS|LOG_PERROR, LOG_USER); |
openlog("testipfrdrd", LOG_CONS|LOG_PERROR, LOG_USER); |
printf("List nat rules :\n"); | if(init_redirect() < 0) |
test_list_nat_rules(); | { |
| fprintf(stderr, "init_redirect() failed\n"); |
| return 1; |
| } |
| |
| printf("List rdr ports :\n"); |
| list_eports_tcp(); |
| |
printf("Add redirection !\n"); |
printf("Add redirection !\n"); |
add_redirect_rule2("ep0", 12345, "1.2.3.4", 54321, IPPROTO_UDP, | add_redirect_rule2("xennet0", "*", 12345, "192.168.1.100", 54321, IPPROTO_UDP, |
"redirection description"); | "redirection description", 0); |
printf("List nat rules :\n"); | add_redirect_rule2("xennet0", "8.8.8.8", 12345, "192.168.1.100", 54321, IPPROTO_TCP, |
test_list_nat_rules(); | "redirection description", 0); |
| |
| printf("Check redirect rules with \"ipnat -l\" then press any key.\n"); |
| c = getchar(); |
| |
| printf("List rdr ports :\n"); |
| list_eports_tcp(); |
| |
| printf("Delete redirection !\n"); |
| delete_redirect_rule("xennet0", 12345, IPPROTO_UDP); |
| delete_redirect_rule("xennet0", 12345, IPPROTO_TCP); |
| |
| printf("List rdr ports :\n"); |
| list_eports_tcp(); |
| |
return 0; |
return 0; |
} |
} |
|
|