Diff for /embedaddon/miniupnpd/ipfw/testipfwrdr.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2012/02/21 23:16:02 version 1.1.1.2, 2012/05/29 12:55:57
Line 1 Line 1
   /* $Id$ */
 /*  /*
  * MiniUPnP project   * MiniUPnP project
  * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/   * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
 * (c) 2009 Jardel Weyrich * (c) 2009-2011 Jardel Weyrich, Thomas Bernard
  * This software is subject to the conditions detailed   * This software is subject to the conditions detailed
  * in the LICENCE file provided within the distribution   * in the LICENCE file provided within the distribution
  */   */
   
 #include <stdio.h>  #include <stdio.h>
 #include <syslog.h>  #include <syslog.h>
   #include <time.h>
 #include <netinet/in.h>  #include <netinet/in.h>
 #include "ipfwrdr.h"  #include "ipfwrdr.h"
   
 // test program for ipfwrdr.c  // test program for ipfwrdr.c
   static const char * ifname = "lo0";
   
   static void
   list_port_mappings(void)
   {
           int i;
           unsigned short eport;
           char iaddr[16];
           unsigned short iport;
           int proto;
           char desc[64];
           char rhost[32];
           unsigned int timestamp;
           u_int64_t packets, bytes;
   
           printf("== Port Mapping List ==\n");
           for(i = 0;; i++) {
                   iaddr[0] = '\0';
                   desc[0] = '\0';
                   eport = iport = 0;
                   timestamp = 0;
                   packets = bytes = 0;
                   proto = -1;
                   if(get_redirect_rule_by_index(i, 0/*ifname*/, &eport, iaddr, sizeof(iaddr),
                                                 &iport, &proto, desc, sizeof(desc),
                                                 rhost, sizeof(rhost),
                                                 &timestamp, &packets, &bytes) < 0)
                           break;
                   printf("%2d - %5hu=>%15s:%5hu %d '%s' '%s' %u %" PRIu64 " %" PRIu64 "\n",
                          i, eport, iaddr, iport, proto, desc, rhost, timestamp,
                          packets, bytes);
           }
           printf("== %d Port Mapping%s ==\n", i, (i > 1)?"s":"");
   }
   
 int main(int argc, char * * argv) {  int main(int argc, char * * argv) {
           unsigned int timestamp;
           char desc[64];
           char addr[16];
           char rhost[40];
           unsigned short iport = 0;
           const char * in_rhost = "8.8.8.8";
   
           desc[0] = '\0';
           addr[0] = '\0';
         openlog("testipfwrdrd", LOG_CONS | LOG_PERROR, LOG_USER);          openlog("testipfwrdrd", LOG_CONS | LOG_PERROR, LOG_USER);
        init_redirect();        if(init_redirect() < 0) {
        delete_redirect_rule("lo", 2222, IPPROTO_TCP);                fprintf(stderr, "init_redirect() failed.\n");
        add_redirect_rule2("lo", 2222, "10.1.1.16", 4444, IPPROTO_TCP, "miniupnpd");                return 1;
        get_redirect_rule("lo", 2222, IPPROTO_TCP, NULL, 0, NULL, NULL, 0, NULL, NULL);        }
         list_port_mappings();
         delete_redirect_rule(ifname, 2222, IPPROTO_TCP);
         delete_redirect_rule(ifname, 2223, IPPROTO_TCP);
         add_redirect_rule2(ifname, "", 2223,
                            "10.1.1.17", 4445, IPPROTO_TCP,
                            "test miniupnpd", time(NULL) + 60);
         add_redirect_rule2(ifname, in_rhost, 2222,
                            "10.1.1.16", 4444, IPPROTO_TCP,
                            "test miniupnpd", time(NULL) + 60);
         get_redirect_rule(ifname, 2222, IPPROTO_TCP, addr, sizeof(addr), &iport,
                           desc, sizeof(desc), rhost, sizeof(rhost),
                           &timestamp, NULL, NULL);
         printf("'%s' %s:%hu '%s' %u\n", rhost, addr, iport, desc, timestamp);
         list_port_mappings();
         delete_redirect_rule(ifname, 2222, IPPROTO_TCP);
         delete_redirect_rule(ifname, 2223, IPPROTO_TCP);
         list_port_mappings();
         shutdown_redirect();          shutdown_redirect();
         return 0;          return 0;
 }  }

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


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