Changeset 6303


Ignore:
Timestamp:
Jul 9, 2008, 2:51:29 AM (15 years ago)
Author:
charles
Message:

Update to the 20080707 version of libnatpmp and the 20080703 version of miniupnpc

Location:
trunk/third-party
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/third-party/libnatpmp/README

    r6268 r6303  
    11libnatpmp is written by Thomas Bernard.
    22Its homepage is http://miniupnp.tuxfamily.org/libnatpmp.html
    3 This code is from the libnatpmp-20080630 snapshot
     3This code is from the libnatpmp-20080707 snapshot
    44
  • trunk/third-party/libnatpmp/getgateway.c

    r6271 r6303  
    1 /* $Id: getgateway.c,v 1.8 2008/06/30 14:15:40 nanard Exp $ */
     1/* $Id: getgateway.c,v 1.11 2008/07/02 23:56:11 nanard Exp $ */
    22/* libnatpmp
    33 * Copyright (c) 2007-2008, Thomas BERNARD <miniupnp@free.fr>
     
    1616#include <stdio.h>
    1717#include <ctype.h>
     18#ifndef WIN32
    1819#include <netinet/in.h>
     20#endif
    1921#include <sys/param.h>
    2022/* There is no portable method to get the default route gateway.
     
    2527 * sockets. */
    2628#ifdef __linux__
    27   #define USE_PROC_NET_ROUTE
    28 #elif defined(__APPLE__)
    29   #define USE_SYSCTL_NET_ROUTE
    30 #elif defined(BSD)
    31   /*#define USE_SYSCTL_NET_ROUTE*/
    32   #define USE_SOCKET_ROUTE
    33 #elif (defined(sun) && defined(__SVR4))
    34   #define USE_SOCKET_ROUTE
     29#define USE_PROC_NET_ROUTE
     30#undef USE_SOCKET_ROUTE
     31#undef USE_SYSCTL_NET_ROUTE
     32#endif
     33
     34#ifdef BSD
     35#undef USE_PROC_NET_ROUTE
     36#define USE_SOCKET_ROUTE
     37#undef USE_SYSCTL_NET_ROUTE
     38#endif
     39
     40#ifdef __APPLE__
     41#undef USE_PROC_NET_ROUTE
     42#undef USE_SOCKET_ROUTE
     43#define USE_SYSCTL_NET_ROUTE
     44#endif
     45
     46#if (defined(sun) && defined(__SVR4))
     47#undef USE_PROC_NET_ROUTE
     48#define USE_SOCKET_ROUTE
     49#undef USE_SYSCTL_NET_ROUTE
     50#endif
     51
     52#ifdef WIN32
     53#undef USE_PROC_NET_ROUTE
     54#undef USE_SOCKET_ROUTE
     55#undef USE_SYSCTL_NET_ROUTE
     56#define USE_WIN32_CODE
    3557#endif
    3658
     
    4870#include <net/route.h>
    4971#endif
     72#ifdef WIN32
     73#include <unknwn.h>
     74#include <winreg.h>
     75#define MAX_KEY_LENGTH 255
     76#define MAX_VALUE_LENGTH 16383
     77#endif
    5078#include "getgateway.h"
    5179
     80#ifndef WIN32
    5281#define SUCCESS (0)
    5382#define FAILED  (-1)
     83#endif
    5484
    5585#ifdef USE_PROC_NET_ROUTE
     
    230260#endif /* #ifdef USE_SOCKET_ROUTE */
    231261
     262#ifdef USE_WIN32_CODE
     263int getdefaultgateway(in_addr_t * addr)
     264{
     265        HKEY networkCardsKey;
     266        HKEY networkCardKey;
     267        HKEY interfacesKey;
     268        HKEY interfaceKey;
     269        DWORD i = 0;
     270        DWORD numSubKeys = 0;
     271        TCHAR keyName[MAX_KEY_LENGTH];
     272        DWORD keyNameLength = MAX_KEY_LENGTH;
     273        TCHAR keyValue[MAX_VALUE_LENGTH];
     274        DWORD keyValueLength = MAX_VALUE_LENGTH;
     275        DWORD keyValueType = REG_SZ;
     276        TCHAR gatewayValue[MAX_VALUE_LENGTH];
     277        DWORD gatewayValueLength = MAX_VALUE_LENGTH;
     278        DWORD gatewayValueType = REG_MULTI_SZ;
     279        int done = 0;
     280       
     281        char networkCardsPath[] = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards";
     282        char interfacesPath[] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces";
     283       
     284        // The windows registry lists its primary network devices in the following location:
     285        // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards
     286        //
     287        // Each network device has its own subfolder, named with an index, with various properties:
     288        // -NetworkCards
     289        //   -5
     290        //     -Description = Broadcom 802.11n Network Adapter
     291        //     -ServiceName = {E35A72F8-5065-4097-8DFE-C7790774EE4D}
     292        //   -8
     293        //     -Description = Marvell Yukon 88E8058 PCI-E Gigabit Ethernet Controller
     294        //     -ServiceName = {86226414-5545-4335-A9D1-5BD7120119AD}
     295        //
     296        // The above service name is the name of a subfolder within:
     297        // HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces
     298        //
     299        // There may be more subfolders in this interfaces path than listed in the network cards path above:
     300        // -Interfaces
     301        //   -{3a539854-6a70-11db-887c-806e6f6e6963}
     302        //     -DhcpIPAddress = 0.0.0.0
     303        //     -[more]
     304        //   -{E35A72F8-5065-4097-8DFE-C7790774EE4D}
     305        //     -DhcpIPAddress = 10.0.1.4
     306        //     -DhcpDefaultGateway = 10.0.1.1
     307        //     -[more]
     308        //   -{86226414-5545-4335-A9D1-5BD7120119AD}
     309        //     -DhcpIpAddress = 10.0.1.5
     310        //     -DhcpDefaultGateay = 10.0.1.1
     311        //     -[more]
     312        //
     313        // In order to extract this information, we enumerate each network card, and extract the ServiceName value.
     314        // This is then used to open the interface subfolder, and attempt to extract a DhcpDefaultGateway value.
     315        // Once one is found, we're done.
     316        //
     317        // It may be possible to simply enumerate the interface folders until we find one with a DhcpDefaultGateway value.
     318        // However, the technique used is the technique most cited on the web, and we assume it to be more correct.
     319       
     320        if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, // Open registry key or predifined key
     321                                         networkCardsPath,   // Name of registry subkey to open
     322                                         0,                  // Reserved - must be zero
     323                                         KEY_READ,           // Mask - desired access rights
     324                                         &networkCardsKey))  // Pointer to output key
     325        {
     326                // Unable to open network cards keys
     327                return -1;
     328        }
     329       
     330        if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, // Open registry key or predefined key
     331                                         interfacesPath,     // Name of registry subkey to open
     332                                         0,                  // Reserved - must be zero
     333                                         KEY_READ,           // Mask - desired access rights
     334                                         &interfacesKey))    // Pointer to output key
     335        {
     336                // Unable to open interfaces key
     337                RegCloseKey(networkCardsKey);
     338                return -1;
     339        }
     340       
     341        // Figure out how many subfolders are within the NetworkCards folder
     342        RegQueryInfoKey(networkCardsKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
     343       
     344        //printf( "Number of subkeys: %u\n", (unsigned int)numSubKeys);
     345       
     346        // Enumrate through each subfolder within the NetworkCards folder
     347        for(i = 0; i < numSubKeys && !done; i++)
     348        {
     349                keyNameLength = MAX_KEY_LENGTH;
     350                if(ERROR_SUCCESS == RegEnumKeyEx(networkCardsKey, // Open registry key
     351                                                 i,               // Index of subkey to retrieve
     352                                                 keyName,         // Buffer that receives the name of the subkey
     353                                                 &keyNameLength,  // Variable that receives the size of the above buffer
     354                                                 NULL,            // Reserved - must be NULL
     355                                                 NULL,            // Buffer that receives the class string
     356                                                 NULL,            // Variable that receives the size of the above buffer
     357                                                 NULL))           // Variable that receives the last write time of subkey
     358                {
     359                        if(RegOpenKeyEx(networkCardsKey,  keyName, 0, KEY_READ, &networkCardKey) == ERROR_SUCCESS)
     360                        {
     361                                keyValueLength = MAX_VALUE_LENGTH;
     362                                if(ERROR_SUCCESS == RegQueryValueEx(networkCardKey,   // Open registry key
     363                                                                    "ServiceName",    // Name of key to query
     364                                                                    NULL,             // Reserved - must be NULL
     365                                                                    &keyValueType,    // Receives value type
     366                                                                    keyValue,         // Receives value
     367                                                                    &keyValueLength)) // Receives value length in bytes
     368                                {
     369                                        //printf("keyValue: %s\n", keyValue);
     370                                       
     371                                        if(RegOpenKeyEx(interfacesKey, keyValue, 0, KEY_READ, &interfaceKey) == ERROR_SUCCESS)
     372                                        {
     373                                                gatewayValueLength = MAX_VALUE_LENGTH;
     374                                                if(ERROR_SUCCESS == RegQueryValueEx(interfaceKey,         // Open registry key
     375                                                                                    "DhcpDefaultGateway", // Name of key to query
     376                                                                                    NULL,                 // Reserved - must be NULL
     377                                                                                    &gatewayValueType,    // Receives value type
     378                                                                                    gatewayValue,         // Receives value
     379                                                                                    &gatewayValueLength)) // Receives value length in bytes
     380                                                {
     381                                                        // Check to make sure it's a string
     382                                                        if(gatewayValueType == REG_MULTI_SZ || gatewayValueType == REG_SZ)
     383                                                        {
     384                                                                //printf("gatewayValue: %s\n", gatewayValue);
     385                                                                done = 1;
     386                                                        }
     387                                                }
     388                                                RegCloseKey(interfaceKey);
     389                                        }
     390                                }
     391                                RegCloseKey(networkCardKey);
     392                        }
     393                }
     394        }
     395       
     396        RegCloseKey(interfacesKey);
     397        RegCloseKey(networkCardsKey);
     398       
     399        if(done)
     400        {
     401                *addr = inet_addr(gatewayValue);
     402                return 0;
     403        }
     404       
     405        return -1;
     406}
     407#endif /* #ifdef USE_WIN32_CODE */
     408
  • trunk/third-party/libnatpmp/getgateway.h

    r4095 r6303  
    1 /* $Id: getgateway.h,v 1.2 2007/11/22 18:01:37 nanard Exp $ */
     1/* $Id: getgateway.h,v 1.3 2008/07/02 22:33:06 nanard Exp $ */
    22/* libnatpmp
    33 * Copyright (c) 2007, Thomas BERNARD <miniupnp@free.fr>
     
    1717#define __GETGATEWAY_H__
    1818
     19#ifdef WIN32
     20#include <stdint.h>
     21#define in_addr_t uint32_t
     22#endif
     23#include "declspec.h"
     24
    1925/* getdefaultgateway() :
    2026 * return value :
    2127 *    0 : success
    2228 *   -1 : failure    */
    23 int getdefaultgateway(in_addr_t * addr);
     29LIBSPEC int getdefaultgateway(in_addr_t * addr);
    2430
    2531#endif
  • trunk/third-party/libnatpmp/natpmp.c

    r5970 r6303  
    1 /* $Id: natpmp.c,v 1.7 2008/05/29 08:06:01 nanard Exp $ */
     1/* $Id: natpmp.c,v 1.8 2008/07/02 22:33:06 nanard Exp $ */
    22/* libnatpmp
    33 * Copyright (c) 2007-2008, Thomas BERNARD <miniupnp@free.fr>
     
    2222#include <Ws2tcpip.h>
    2323#include <io.h>
     24#define EWOULDBLOCK WSAEWOULDBLOCK
     25#define ECONNREFUSED WSAECONNREFUSED
    2426#else
    2527#include <errno.h>
     
    2830#include <sys/types.h>
    2931#include <sys/socket.h>
     32#define closesocket close
    3033#endif
    3134#include "natpmp.h"
     
    3437int initnatpmp(natpmp_t * p)
    3538{
     39#ifdef WIN32
     40        u_long ioctlArg = 1;
     41#else
    3642        int flags;
     43#endif
    3744        struct sockaddr_in addr;
    3845        if(!p)
     
    4249        if(p->s < 0)
    4350                return NATPMP_ERR_SOCKETERROR;
     51#ifdef WIN32
     52        if(ioctlsocket(p->s, FIONBIO, &ioctlArg) == SOCKET_ERROR)
     53                return NATPMP_ERR_FCNTLERROR;
     54#else
    4455        if((flags = fcntl(p->s, F_GETFL, 0)) < 0)
    4556                return NATPMP_ERR_FCNTLERROR;
    4657        if(fcntl(p->s, F_SETFL, flags | O_NONBLOCK) < 0)
    4758                return NATPMP_ERR_FCNTLERROR;
     59#endif
    4860
    4961        if(getdefaultgateway(&(p->gateway)) < 0)
     
    6375        if(!p)
    6476                return NATPMP_ERR_INVALIDARGS;
    65         if(close(p->s) < 0)
     77        if(closesocket(p->s) < 0)
    6678                return NATPMP_ERR_CLOSEERR;
    6779        return 0;
     
    161173        if(n<0)
    162174                switch(errno) {
    163                 case EAGAIN:
     175                /*case EAGAIN:*/
     176                case EWOULDBLOCK:
    164177                        n = NATPMP_TRYAGAIN;
    165178                        break;
     
    270283                break;
    271284        case NATPMP_ERR_CLOSEERR:
     285#ifdef WIN32
     286                s = "closesocket() failed";
     287#else
    272288                s = "close() failed";
     289#endif
    273290                break;
    274291        case NATPMP_ERR_RECVFROM:
  • trunk/third-party/libnatpmp/natpmp.h

    r5970 r6303  
    1 /* $Id: natpmp.h,v 1.9 2008/05/29 08:06:01 nanard Exp $ */
     1/* $Id: natpmp.h,v 1.10 2008/07/02 22:33:06 nanard Exp $ */
    22/* libnatpmp
    33 * Copyright (c) 2007-2008, Thomas BERNARD <miniupnp@free.fr>
     
    2525#ifdef WIN32
    2626#include <winsock2.h>
     27#include <stdint.h>
     28#define in_addr_t uint32_t
    2729#else
    2830#include <netinet/in.h>
    2931#endif
     32#include "declspec.h"
    3033
    3134typedef struct {
     
    114117 * NATPMP_ERR_CANNOTGETGATEWAY
    115118 * NATPMP_ERR_CONNECTERR */
    116 int initnatpmp(natpmp_t * p);
     119LIBSPEC int initnatpmp(natpmp_t * p);
    117120
    118121/* closenatpmp()
     
    122125 * NATPMP_ERR_INVALIDARGS
    123126 * NATPMP_ERR_CLOSEERR */
    124 int closenatpmp(natpmp_t * p);
     127LIBSPEC int closenatpmp(natpmp_t * p);
    125128
    126129/* sendpublicaddressrequest()
     
    130133 * NATPMP_ERR_INVALIDARGS
    131134 * NATPMP_ERR_SENDERR */
    132 int sendpublicaddressrequest(natpmp_t * p);
     135LIBSPEC int sendpublicaddressrequest(natpmp_t * p);
    133136
    134137/* sendnewportmappingrequest()
     
    144147 * NATPMP_ERR_INVALIDARGS
    145148 * NATPMP_ERR_SENDERR */
    146 int sendnewportmappingrequest(natpmp_t * p, int protocol,
     149LIBSPEC int sendnewportmappingrequest(natpmp_t * p, int protocol,
    147150                              uint16_t privateport, uint16_t publicport,
    148151                                                          uint32_t lifetime);
     
    156159 * NATPMP_ERR_GETTIMEOFDAYERR
    157160 * NATPMP_ERR_NOPENDINGREQ */
    158 int getnatpmprequesttimeout(natpmp_t * p, struct timeval * timeout);
     161LIBSPEC int getnatpmprequesttimeout(natpmp_t * p, struct timeval * timeout);
    159162
    160163/* readnatpmpresponseorretry()
     
    175178 * NATPMP_ERR_UNSUPPORTEDOPCODE
    176179 * NATPMP_ERR_UNDEFINEDERROR */
    177 int readnatpmpresponseorretry(natpmp_t * p, natpmpresp_t * response);
     180LIBSPEC int readnatpmpresponseorretry(natpmp_t * p, natpmpresp_t * response);
    178181
    179182#ifdef ENABLE_STRNATPMPERR
    180 const char * strnatpmperr(int t);
     183LIBSPEC const char * strnatpmperr(int t);
    181184#endif
    182185
  • trunk/third-party/miniupnp/LICENCE

    r3731 r6303  
    1 Copyright (c) 2005-2007, Thomas BERNARD
     1Copyright (c) 2005-2008, Thomas BERNARD
    22All rights reserved.
    33
  • trunk/third-party/miniupnp/README

    r5743 r6303  
    11MiniUPnP is written by Thomas Bernard.
    22Its homepage is http://miniupnp.free.fr/
    3 This is from the miniupnp-20080428 snapshot
     3This is from the miniupnp-20080703 snapshot
Note: See TracChangeset for help on using the changeset viewer.