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

    1: /* $Id: testiptcrdr.c,v 1.1.1.3 2013/07/22 00:32:35 misho Exp $ */
    2: /* MiniUPnP project
    3:  * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
    4:  * (c) 2006-2012 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 <netinet/in.h>
   11: #include <syslog.h>
   12: 
   13: #include "iptcrdr.h"
   14: #include "../commonrdr.h"
   15: 
   16: #ifndef PRIu64
   17: #define PRIu64 "llu"
   18: #endif
   19: 
   20: int
   21: main(int argc, char ** argv)
   22: {
   23: 	unsigned short eport, iport;
   24: 	const char * iaddr;
   25: 	printf("Usage %s <ext_port> <internal_ip> <internal_port>\n", argv[0]);
   26: 
   27: 	if(argc<4)
   28: 		return -1;
   29: 	openlog("testiptcrdr", LOG_PERROR|LOG_CONS, LOG_LOCAL0);
   30: 	eport = (unsigned short)atoi(argv[1]);
   31: 	iaddr = argv[2];
   32: 	iport = (unsigned short)atoi(argv[3]);
   33: #if 0
   34: 	printf("trying to redirect port %hu to %s:%hu\n", eport, iaddr, iport);
   35: 	if(addnatrule(IPPROTO_TCP, eport, iaddr, iport) < 0)
   36: 		return -1;
   37: 	if(add_filter_rule(IPPROTO_TCP, iaddr, iport) < 0)
   38: 		return -1;
   39: #endif
   40: 	/* test */
   41: 	{
   42: 		unsigned short p1, p2;
   43: 		char addr[16];
   44: 		int proto2;
   45: 		char desc[256];
   46: 		char rhost[256];
   47: 		unsigned int timestamp;
   48: 		u_int64_t packets, bytes;
   49: 
   50: 		desc[0] = '\0';
   51: 		if(get_redirect_rule_by_index(0, "", &p1,
   52: 		                              addr, sizeof(addr), &p2,
   53: 		                              &proto2, desc, sizeof(desc),
   54: 		                              rhost, sizeof(rhost),
   55: 		                              &timestamp,
   56: 									  &packets, &bytes) < 0)
   57: 		{
   58: 			printf("rule not found\n");
   59: 		}
   60: 		else
   61: 		{
   62: 			printf("redirected port %hu to %s:%hu proto %d   packets=%" PRIu64 " bytes=%" PRIu64 "\n",
   63: 			       p1, addr, p2, proto2, packets, bytes);
   64: 		}
   65: 	}
   66: 	printf("trying to list nat rules :\n");
   67: 	list_redirect_rule(argv[1]);
   68: 	printf("deleting\n");
   69: 	delete_redirect_and_filter_rules(eport, IPPROTO_TCP);
   70: 	return 0;
   71: }
   72: 

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