File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / miniupnpd / ipf / testipfrdr.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Mon Jul 22 00:32:35 2013 UTC (10 years, 11 months ago) by misho
Branches: miniupnpd, elwix, MAIN
CVS tags: v1_8p0, v1_8, HEAD
1.8

    1: /* $Id: testipfrdr.c,v 1.1.1.2 2013/07/22 00:32:35 misho Exp $ */
    2: 
    3: #include <stdio.h>
    4: #include <stdlib.h>
    5: #include <syslog.h>
    6: #include <netinet/in.h>
    7: #include <sys/types.h>
    8: #include "ipfrdr.h"
    9: 
   10: /* test program for ipfrdr.c */
   11: 
   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: 
   38: int
   39: main(int argc, char * * argv)
   40: {
   41: 	char c;
   42: 	
   43: 	openlog("testipfrdrd", LOG_CONS|LOG_PERROR, LOG_USER);
   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: 	
   53: 	printf("Add redirection !\n");
   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: 	
   72: 	return 0;
   73: }
   74: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>