File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / miniupnpd / pf / testobsdrdr.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 12:55:57 2012 UTC (12 years, 2 months ago) by misho
Branches: miniupnpd, elwix, MAIN
CVS tags: v1_6elwix, HEAD
miniupnpd 1.6+patches

    1: /* $Id: testobsdrdr.c,v 1.1.1.2 2012/05/29 12:55:57 misho Exp $ */
    2: /* MiniUPnP project
    3:  * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
    4:  * (c) 2006-2011 Thomas Bernard 
    5:  * This software is subject to the conditions detailed
    6:  * in the LICENCE file provided within the distribution */
    7: 
    8: #include <stdio.h>
    9: #include <stdlib.h>
   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
   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
   40: test_index(void)
   41: {
   42: 	char ifname[16/*IFNAMSIZ*/];
   43: 	char iaddr[32];
   44: 	char desc[64];
   45: 	char rhost[32];
   46: 	unsigned short iport = 0;
   47: 	unsigned short eport = 0;
   48: 	int proto = 0;
   49: 	unsigned int timestamp;
   50: 	ifname[0] = '\0';
   51: 	iaddr[0] = '\0';
   52: 	rhost[0] = '\0';
   53: 	if(get_redirect_rule_by_index(0, ifname, &eport, iaddr, sizeof(iaddr),
   54: 	                              &iport, &proto, desc, sizeof(desc),
   55: 	                              rhost, sizeof(rhost),
   56:                                   &timestamp, 0, 0) < 0)
   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];
   73: 	/*char rhost[32];*/
   74: 	unsigned short iport;
   75: 	unsigned int timestamp;
   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);
   87: 	add_redirect_rule2("ep0", "8.8.8.8", 12123, "192.168.1.125", 1234,
   88: 	                   IPPROTO_UDP, "test description", 0);
   89: 	//add_redirect_rule2("em0", 12123, "127.1.2.3", 1234,
   90: 	//                   IPPROTO_TCP, "test description tcp");
   91: 
   92: 	list_rules();
   93: 	list_eports_tcp();
   94: 	
   95: 
   96: 	if(get_redirect_rule("xl1", 4662, IPPROTO_TCP,
   97: 	                     buf, sizeof(buf), &iport, desc, sizeof(desc),
   98: 	                     &timestamp,
   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>