Annotation of embedaddon/miniupnpd/pf/testobsdrdr.c, revision 1.1

1.1     ! misho       1: /* $Id: testobsdrdr.c,v 1.19 2010/03/07 09:25:20 nanard Exp $ */
        !             2: /* MiniUPnP project
        !             3:  * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
        !             4:  * (c) 2006-2010 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 <sys/types.h>
        !            10: #include <netinet/in.h>
        !            11: #include <syslog.h>
        !            12: 
        !            13: #include "obsdrdr.h"
        !            14: 
        !            15: /*int logpackets = 1;*/
        !            16: int runtime_flags = 0;
        !            17: const char * tag = 0;
        !            18: 
        !            19: void
        !            20: list_rules(void);
        !            21: 
        !            22: void
        !            23: test_index(void)
        !            24: {
        !            25:        char ifname[16/*IFNAMSIZ*/];
        !            26:        char iaddr[32];
        !            27:        char desc[64];
        !            28:        unsigned short iport = 0;
        !            29:        unsigned short eport = 0;
        !            30:        int proto = 0;
        !            31:        ifname[0] = '\0';
        !            32:        iaddr[0] = '\0';
        !            33:        if(get_redirect_rule_by_index(0, ifname, &eport, iaddr, sizeof(iaddr),
        !            34:                                      &iport, &proto, desc, sizeof(desc),
        !            35:                                   0, 0) < 0)
        !            36:        {
        !            37:                printf("get.._by_index : no rule\n");
        !            38:        }
        !            39:        else
        !            40:        {
        !            41:                printf("%s %u -> %s:%u proto %d\n", ifname, (unsigned int)eport,
        !            42:                       iaddr, (unsigned int)iport, proto);
        !            43:                printf("description: \"%s\"\n", desc);
        !            44:        }
        !            45: }
        !            46: 
        !            47: int
        !            48: main(int arc, char * * argv)
        !            49: {
        !            50:        char buf[32];
        !            51:        char desc[64];
        !            52:        unsigned short iport;
        !            53:        u_int64_t packets = 0;
        !            54:        u_int64_t bytes = 0;
        !            55: 
        !            56:        openlog("testobsdrdr", LOG_PERROR, LOG_USER);
        !            57:        if(init_redirect() < 0)
        !            58:        {
        !            59:                fprintf(stderr, "init_redirect() failed\n");
        !            60:                return 1;
        !            61:        }
        !            62:        //add_redirect_rule("ep0", 12123, "192.168.1.23", 1234);
        !            63:        //add_redirect_rule2("ep0", 12155, "192.168.1.155", 1255, IPPROTO_TCP);
        !            64:        //add_redirect_rule2("ep0", 12123, "192.168.1.125", 1234,
        !            65:        //                   IPPROTO_UDP, "test description");
        !            66:        //add_redirect_rule2("em0", 12123, "127.1.2.3", 1234,
        !            67:        //                   IPPROTO_TCP, "test description tcp");
        !            68: 
        !            69:        list_rules();
        !            70: 
        !            71:        if(get_redirect_rule("xl1", 4662, IPPROTO_TCP,
        !            72:                             buf, 32, &iport, desc, sizeof(desc),
        !            73:                             &packets, &bytes) < 0)
        !            74:                printf("get_redirect_rule() failed\n");
        !            75:        else
        !            76:        {
        !            77:                printf("\n%s:%d '%s' packets=%llu bytes=%llu\n", buf, (int)iport, desc,
        !            78:                       packets, bytes);
        !            79:        }
        !            80: #if 0
        !            81:        if(delete_redirect_rule("ep0", 12123, IPPROTO_UDP) < 0)
        !            82:                printf("delete_redirect_rule() failed\n");
        !            83:        else
        !            84:                printf("delete_redirect_rule() succeded\n");
        !            85: 
        !            86:        if(delete_redirect_rule("ep0", 12123, IPPROTO_UDP) < 0)
        !            87:                printf("delete_redirect_rule() failed\n");
        !            88:        else
        !            89:                printf("delete_redirect_rule() succeded\n");
        !            90: #endif
        !            91:        //test_index();
        !            92: 
        !            93:        //clear_redirect_rules();
        !            94:        //list_rules();
        !            95: 
        !            96:        return 0;
        !            97: }
        !            98: 
        !            99: 

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