Annotation of embedaddon/miniupnpd/netfilter/testiptcrdr.c, revision 1.1.1.3

1.1.1.3 ! misho       1: /* $Id: testiptcrdr.c,v 1.18 2012/04/24 22:41:53 nanard Exp $ */
1.1       misho       2: /* MiniUPnP project
                      3:  * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
1.1.1.3 ! misho       4:  * (c) 2006-2012 Thomas Bernard
1.1       misho       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"
1.1.1.3 ! misho      14: #include "../commonrdr.h"
1.1       misho      15: 
1.1.1.2   misho      16: #ifndef PRIu64
                     17: #define PRIu64 "llu"
                     18: #endif
                     19: 
1.1       misho      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]);
1.1.1.3 ! misho      26: 
1.1       misho      27:        if(argc<4)
                     28:                return -1;
1.1.1.2   misho      29:        openlog("testiptcrdr", LOG_PERROR|LOG_CONS, LOG_LOCAL0);
1.1       misho      30:        eport = (unsigned short)atoi(argv[1]);
                     31:        iaddr = argv[2];
                     32:        iport = (unsigned short)atoi(argv[3]);
1.1.1.3 ! misho      33: #if 0
1.1       misho      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;
1.1.1.3 ! misho      39: #endif
1.1       misho      40:        /* test */
                     41:        {
                     42:                unsigned short p1, p2;
                     43:                char addr[16];
                     44:                int proto2;
                     45:                char desc[256];
1.1.1.3 ! misho      46:                char rhost[256];
        !            47:                unsigned int timestamp;
1.1       misho      48:                u_int64_t packets, bytes;
1.1.1.3 ! misho      49: 
1.1       misho      50:                desc[0] = '\0';
1.1.1.3 ! misho      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,
1.1       misho      56:                                                                          &packets, &bytes) < 0)
                     57:                {
1.1.1.2   misho      58:                        printf("rule not found\n");
1.1       misho      59:                }
                     60:                else
                     61:                {
1.1.1.2   misho      62:                        printf("redirected port %hu to %s:%hu proto %d   packets=%" PRIu64 " bytes=%" PRIu64 "\n",
                     63:                               p1, addr, p2, proto2, packets, bytes);
1.1       misho      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>