Annotation of embedaddon/miniupnpd/ipf/testipfrdr.c, revision 1.1.1.2
1.1.1.2 ! misho 1: /* $Id: testipfrdr.c,v 1.4 2012/03/19 21:14:13 nanard Exp $ */
1.1 misho 2:
3: #include <stdio.h>
1.1.1.2 ! misho 4: #include <stdlib.h>
1.1 misho 5: #include <syslog.h>
6: #include <netinet/in.h>
1.1.1.2 ! misho 7: #include <sys/types.h>
1.1 misho 8: #include "ipfrdr.h"
9:
10: /* test program for ipfrdr.c */
11:
1.1.1.2 ! misho 12: int runtime_flags = 0;
! 13:
! 14: void
! 15: list_eports_tcp(void)
! 16: {
! 17: unsigned short * port_list;
! 18: unsigned int number = 0;
! 19: unsigned int i;
! 20: port_list = get_portmappings_in_range(0, 65535, IPPROTO_TCP, &number);
! 21: printf("%u ports redirected (TCP) :", number);
! 22: for(i = 0; i < number; i++)
! 23: {
! 24: printf(" %hu", port_list[i]);
! 25: }
! 26: printf("\n");
! 27: free(port_list);
! 28: port_list = get_portmappings_in_range(0, 65535, IPPROTO_UDP, &number);
! 29: printf("%u ports redirected (UDP) :", number);
! 30: for(i = 0; i < number; i++)
! 31: {
! 32: printf(" %hu", port_list[i]);
! 33: }
! 34: printf("\n");
! 35: free(port_list);
! 36: }
! 37:
1.1 misho 38: int
39: main(int argc, char * * argv)
40: {
1.1.1.2 ! misho 41: char c;
! 42:
1.1 misho 43: openlog("testipfrdrd", LOG_CONS|LOG_PERROR, LOG_USER);
1.1.1.2 ! misho 44: if(init_redirect() < 0)
! 45: {
! 46: fprintf(stderr, "init_redirect() failed\n");
! 47: return 1;
! 48: }
! 49:
! 50: printf("List rdr ports :\n");
! 51: list_eports_tcp();
! 52:
1.1 misho 53: printf("Add redirection !\n");
1.1.1.2 ! misho 54: add_redirect_rule2("xennet0", "*", 12345, "192.168.1.100", 54321, IPPROTO_UDP,
! 55: "redirection description", 0);
! 56: add_redirect_rule2("xennet0", "8.8.8.8", 12345, "192.168.1.100", 54321, IPPROTO_TCP,
! 57: "redirection description", 0);
! 58:
! 59: printf("Check redirect rules with \"ipnat -l\" then press any key.\n");
! 60: c = getchar();
! 61:
! 62: printf("List rdr ports :\n");
! 63: list_eports_tcp();
! 64:
! 65: printf("Delete redirection !\n");
! 66: delete_redirect_rule("xennet0", 12345, IPPROTO_UDP);
! 67: delete_redirect_rule("xennet0", 12345, IPPROTO_TCP);
! 68:
! 69: printf("List rdr ports :\n");
! 70: list_eports_tcp();
! 71:
1.1 misho 72: return 0;
73: }
74:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>