Ignore:
Timestamp:
Jun 9, 2010, 11:22:00 PM (12 years ago)
Author:
livings124
Message:

update miniupnpc to 20100609

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/third-party/miniupnp/miniupnpc.c

    r10472 r10739  
    1 /* $Id: miniupnpc.c,v 1.80 2010/04/12 20:39:41 nanard Exp $ */
     1/* $Id: miniupnpc.c,v 1.81 2010/04/17 22:07:59 nanard Exp $ */
    22/* Project : miniupnp
    33 * Author : Thomas BERNARD
     
    2525#include <ws2tcpip.h>
    2626#include <io.h>
    27 /*#include <IPHlpApi.h>*/
     27#include <IPHlpApi.h>
    2828#define snprintf _snprintf
    2929#if defined(_MSC_VER) && (_MSC_VER >= 1400)
     
    421421        struct addrinfo hints, *servinfo, *p;
    422422#ifdef WIN32
    423         /*MIB_IPFORWARDROW ip_forward;*/
     423        MIB_IPFORWARDROW ip_forward;
    424424#endif
    425425
     
    474474/* This code could help us to use the right Network interface for
    475475 * SSDP multicast traffic */
    476 /* TODO : Get IP associated with the index given in the ip_forward struct
     476/* Get IP associated with the index given in the ip_forward struct
    477477 * in order to give this ip to setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF) */
    478  /*
    479478        if(GetBestRoute(inet_addr("223.255.255.255"), 0, &ip_forward) == NO_ERROR) {
    480479                DWORD dwRetVal = 0;
    481480                PMIB_IPADDRTABLE pIPAddrTable;
    482     DWORD dwSize = 0;
    483     IN_ADDR IPAddr;
    484     int i;
    485     printf("ifIndex=%lu nextHop=%lx \n", ip_forward.dwForwardIfIndex, ip_forward.dwForwardNextHop);
    486     pIPAddrTable = (MIB_IPADDRTABLE *) malloc(sizeof (MIB_IPADDRTABLE));
    487     if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
    488             free(pIPAddrTable);
    489       pIPAddrTable = (MIB_IPADDRTABLE *) malloc(dwSize);
    490     }
    491     if(pIPAddrTable) {
    492         dwRetVal = GetIpAddrTable( pIPAddrTable, &dwSize, 0 );
    493         printf("\tNum Entries: %ld\n", pIPAddrTable->dwNumEntries);
    494         for (i=0; i < (int) pIPAddrTable->dwNumEntries; i++) {
    495         printf("\n\tInterface Index[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwIndex);
    496         IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwAddr;
    497         printf("\tIP Address[%d]:     \t%s\n", i, inet_ntoa(IPAddr) );
    498         IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwMask;
    499         printf("\tSubnet Mask[%d]:    \t%s\n", i, inet_ntoa(IPAddr) );
    500         IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwBCastAddr;
    501         printf("\tBroadCast[%d]:      \t%s (%ld)\n", i, inet_ntoa(IPAddr), pIPAddrTable->table[i].dwBCastAddr);
    502         printf("\tReassembly size[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwReasmSize);
    503         printf("\tType and State[%d]:", i);
    504         printf("\n");
    505         }
     481                DWORD dwSize = 0;
     482#ifdef DEBUG
     483                IN_ADDR IPAddr;
     484#endif
     485                int i;
     486#ifdef DEBUG
     487                printf("ifIndex=%lu nextHop=%lx \n", ip_forward.dwForwardIfIndex, ip_forward.dwForwardNextHop);
     488#endif
     489                pIPAddrTable = (MIB_IPADDRTABLE *) malloc(sizeof (MIB_IPADDRTABLE));
     490                if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
    506491                        free(pIPAddrTable);
    507         pIPAddrTable = NULL;
    508     }
    509         }
    510 */
     492                        pIPAddrTable = (MIB_IPADDRTABLE *) malloc(dwSize);
     493                }
     494                if(pIPAddrTable) {
     495                        dwRetVal = GetIpAddrTable( pIPAddrTable, &dwSize, 0 );
     496#ifdef DEBUG
     497                        printf("\tNum Entries: %ld\n", pIPAddrTable->dwNumEntries);
     498#endif
     499                        for (i=0; i < (int) pIPAddrTable->dwNumEntries; i++) {
     500#ifdef DEBUG
     501                                printf("\n\tInterface Index[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwIndex);
     502                                IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwAddr;
     503                                printf("\tIP Address[%d]:     \t%s\n", i, inet_ntoa(IPAddr) );
     504                                IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwMask;
     505                                printf("\tSubnet Mask[%d]:    \t%s\n", i, inet_ntoa(IPAddr) );
     506                                IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwBCastAddr;
     507                                printf("\tBroadCast[%d]:      \t%s (%ld)\n", i, inet_ntoa(IPAddr), pIPAddrTable->table[i].dwBCastAddr);
     508                                printf("\tReassembly size[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwReasmSize);
     509                                printf("\tType and State[%d]:", i);
     510                                printf("\n");
     511#endif
     512                                if (pIPAddrTable->table[i].dwIndex == ip_forward.dwForwardIfIndex) {
     513                                        /* Set the address of this interface to be used */
     514                                        struct in_addr mc_if;
     515                                        memset(&mc_if, 0, sizeof(mc_if));
     516                                        mc_if.s_addr = pIPAddrTable->table[i].dwAddr;
     517                                        if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF, (const char *)&mc_if, sizeof(mc_if)) < 0) {
     518                                                PRINT_SOCKET_ERROR("setsockopt");
     519                                        }
     520                                        ((struct sockaddr_in *)&sockudp_r)->sin_addr.s_addr = pIPAddrTable->table[i].dwAddr;
     521#ifndef DEBUG
     522                                        break;
     523#endif
     524                                }
     525                        }
     526                        free(pIPAddrTable);
     527                        pIPAddrTable = NULL;
     528                }
     529        }
    511530#endif
    512531
Note: See TracChangeset for help on using the changeset viewer.