Changeset 10284


Ignore:
Timestamp:
Feb 25, 2010, 12:29:43 PM (12 years ago)
Author:
livings124
Message:

update libnatpmp to 20100202

Location:
trunk/third-party/libnatpmp
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/third-party/libnatpmp/Changelog.txt

    r8798 r10284  
    1 $Id: Changelog.txt,v 1.16 2009/07/13 08:36:02 nanard Exp $
     1$Id: Changelog.txt,v 1.21 2010/02/02 18:24:43 nanard Exp $
     2
     32010/02/02:
     4  Fixed compilation under Mac OS X
     5
     62009/12/19:
     7  improve and fix building under Windows.
     8  Project files for MS Visual Studio 2008
     9  More simple (and working) code for Win32.
     10  More checks in the /proc/net/route parsing. Add some comments.
     11
     122009/08/04:
     13  improving getgateway.c for windows
    214
    3152009/07/13:
  • trunk/third-party/libnatpmp/LICENSE

    r4095 r10284  
    1 libnatpmp
    2 Copyright (c) 2007, Thomas BERNARD <miniupnp@free.fr>
     1Copyright (c) 2007-2009, Thomas BERNARD
     2All rights reserved.
    33
    4 Permission to use, copy, modify, and/or distribute this software for any
    5 purpose with or without fee is hereby granted, provided that the above
    6 copyright notice and this permission notice appear in all copies.
     4Redistribution and use in source and binary forms, with or without
     5modification, are permitted provided that the following conditions are met:
    76
    8 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
    9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
    10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
    11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
    13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     7    * Redistributions of source code must retain the above copyright notice,
     8      this list of conditions and the following disclaimer.
     9    * Redistributions in binary form must reproduce the above copyright notice,
     10      this list of conditions and the following disclaimer in the documentation
     11      and/or other materials provided with the distribution.
     12    * The name of the author may not be used to endorse or promote products
     13          derived from this software without specific prior written permission.
     14
     15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     16AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25POSSIBILITY OF SUCH DAMAGE.
     26
  • trunk/third-party/libnatpmp/README

    r8798 r10284  
    1 libnatpmp is written by Thomas Bernard.
    2 Its homepage is http://miniupnp.tuxfamily.org/libnatpmp.html
    3 This code is from the libnatpmp-20090713 snapshot
     1libnatpmp (c) 2007-2009 Thomas Bernard
     2contact : miniupnp@free.fr
    43
     4see http://miniupnp.free.fr/libnatpmp.html
     5or http://miniupnp.tuxfamily.org/libnatpmp.html
     6for some documentation and code samples.
     7
  • trunk/third-party/libnatpmp/getgateway.c

    r8798 r10284  
    1 /* $Id: getgateway.c,v 1.15 2009/07/13 08:36:02 nanard Exp $ */
     1/* $Id: getgateway.c,v 1.19 2009/12/19 15:20:45 nanard Exp $ */
    22/* libnatpmp
    3  * Copyright (c) 2007-2008, Thomas BERNARD <miniupnp@free.fr>
     3 * Copyright (c) 2007-2009, Thomas BERNARD <miniupnp@free.fr>
    44 *
    55 * Permission to use, copy, modify, and/or distribute this software for any
     
    1919#include <netinet/in.h>
    2020#endif
     21#if !defined(_MSC_VER)
    2122#include <sys/param.h>
     23#endif
    2224/* There is no portable method to get the default route gateway.
    23  * So below are three differents functions implementing this.
     25 * So below are four (or five ?) differents functions implementing this.
    2426 * Parsing /proc/net/route is for linux.
    2527 * sysctl is the way to access such informations on BSD systems.
    2628 * Many systems should provide route information through raw PF_ROUTE
    27  * sockets. */
     29 * sockets.
     30 * In MS Windows, default gateway is found by looking into the registry
     31 * or by using GetBestRoute(). */
    2832#ifdef __linux__
    2933#define USE_PROC_NET_ROUTE
     
    5458#undef USE_SOCKET_ROUTE
    5559#undef USE_SYSCTL_NET_ROUTE
    56 #define USE_WIN32_CODE
     60//#define USE_WIN32_CODE
     61#define USE_WIN32_CODE_2
    5762#endif
    5863
     
    8994#include <net/route.h>
    9095#endif
    91 #ifdef WIN32
     96
     97#ifdef USE_WIN32_CODE
    9298#include <unknwn.h>
    9399#include <winreg.h>
     
    95101#define MAX_VALUE_LENGTH 16383
    96102#endif
     103
     104#ifdef USE_WIN32_CODE_2
     105#include <windows.h>
     106#include <iphlpapi.h>
     107#endif
     108
    97109#include "getgateway.h"
    98110
     
    103115
    104116#ifdef USE_PROC_NET_ROUTE
     117/*
     118 parse /proc/net/route which is as follow :
     119
     120Iface   Destination     Gateway         Flags   RefCnt  Use     Metric  Mask            MTU     Window  IRTT           
     121wlan0   0001A8C0        00000000        0001    0       0       0       00FFFFFF        0       0       0             
     122eth0    0000FEA9        00000000        0001    0       0       0       0000FFFF        0       0       0             
     123wlan0   00000000        0101A8C0        0003    0       0       0       00000000        0       0       0             
     124eth0    00000000        00000000        0001    0       0       1000    00000000        0       0       0             
     125
     126 One header line, and then one line by route by route table entry.
     127*/
    105128int getdefaultgateway(in_addr_t * addr)
    106129{
    107         long d, g;
     130        unsigned long d, g;
    108131        char buf[256];
    109132        int line = 0;
     
    114137                return FAILED;
    115138        while(fgets(buf, sizeof(buf), f)) {
    116                 if(line > 0) {
     139                if(line > 0) {  /* skip the first line */
    117140                        p = buf;
     141                        /* skip the interface name */
    118142                        while(*p && !isspace(*p))
    119143                                p++;
     
    121145                                p++;
    122146                        if(sscanf(p, "%lx%lx", &d, &g)==2) {
    123                                 if(d == 0) { /* default */
     147                                if(d == 0 && g != 0) { /* default */
    124148                                        *addr = g;
    125149                                        fclose(f);
     
    299323        int done = 0;
    300324       
    301         char networkCardsPath[] = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards";
    302         char interfacesPath[] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces";
    303        
     325        //const char * networkCardsPath = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards";
     326        //const char * interfacesPath = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces";
     327#ifdef UNICODE
     328        LPCTSTR networkCardsPath = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards";
     329        LPCTSTR interfacesPath = L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces";
     330#define STR_SERVICENAME  L"ServiceName"
     331#define STR_DHCPDEFAULTGATEWAY L"DhcpDefaultGateway"
     332#define STR_DEFAULTGATEWAY      L"DefaultGateway"
     333#else
     334        LPCTSTR networkCardsPath = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards";
     335        LPCTSTR interfacesPath = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces";
     336#define STR_SERVICENAME  "ServiceName"
     337#define STR_DHCPDEFAULTGATEWAY "DhcpDefaultGateway"
     338#define STR_DEFAULTGATEWAY      "DefaultGateway"
     339#endif
    304340        // The windows registry lists its primary network devices in the following location:
    305341        // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards
     
    381417                                keyValueLength = MAX_VALUE_LENGTH;
    382418                                if(ERROR_SUCCESS == RegQueryValueEx(networkCardKey,   // Open registry key
    383                                                                     "ServiceName",    // Name of key to query
     419                                                                    STR_SERVICENAME,    // Name of key to query
    384420                                                                    NULL,             // Reserved - must be NULL
    385421                                                                    &keyValueType,    // Receives value type
    386                                                                     keyValue,        // Receives value
     422                                                                    (LPBYTE)keyValue, // Receives value
    387423                                                                    &keyValueLength)) // Receives value length in bytes
    388424                                {
    389                                         //printf("keyValue: %s\n", keyValue);
    390                                        
     425//                                      printf("keyValue: %s\n", keyValue);                             
    391426                                        if(RegOpenKeyEx(interfacesKey, keyValue, 0, KEY_READ, &interfaceKey) == ERROR_SUCCESS)
    392427                                        {
    393428                                                gatewayValueLength = MAX_VALUE_LENGTH;
    394429                                                if(ERROR_SUCCESS == RegQueryValueEx(interfaceKey,         // Open registry key
    395                                                                                     "DhcpDefaultGateway", // Name of key to query
     430                                                                                    STR_DHCPDEFAULTGATEWAY, // Name of key to query
    396431                                                                                    NULL,                 // Reserved - must be NULL
    397432                                                                                    &gatewayValueType,    // Receives value type
    398                                                                                     gatewayValue,        // Receives value
     433                                                                                    (LPBYTE)gatewayValue, // Receives value
    399434                                                                                    &gatewayValueLength)) // Receives value length in bytes
    400435                                                {
    401436                                                        // Check to make sure it's a string
    402                                                         if(gatewayValueType == REG_MULTI_SZ || gatewayValueType == REG_SZ)
     437                                                        if((gatewayValueType == REG_MULTI_SZ || gatewayValueType == REG_SZ) && (gatewayValueLength > 1))
    403438                                                        {
    404439                                                                //printf("gatewayValue: %s\n", gatewayValue);
     
    407442                                                }
    408443                                                else if(ERROR_SUCCESS == RegQueryValueEx(interfaceKey,         // Open registry key
    409                                                                                     "DefaultGateway", // Name of key to query
     444                                                                                    STR_DEFAULTGATEWAY, // Name of key to query
    410445                                                                                    NULL,                 // Reserved - must be NULL
    411446                                                                                    &gatewayValueType,    // Receives value type
    412                                                                                     gatewayValue,         // Receives value
     447                                                                                    (LPBYTE)gatewayValue,// Receives value
    413448                                                                                    &gatewayValueLength)) // Receives value length in bytes
    414449                                                {
    415450                                                        // Check to make sure it's a string
    416                                                         if(gatewayValueType == REG_MULTI_SZ || gatewayValueType == REG_SZ)
     451                                                        if((gatewayValueType == REG_MULTI_SZ || gatewayValueType == REG_SZ) && (gatewayValueLength > 1))
    417452                                                        {
    418453                                                                //printf("gatewayValue: %s\n", gatewayValue);
     
    433468        if(done)
    434469        {
     470#if UNICODE
     471                char tmp[32];
     472                for(i = 0; i < 32; i++) {
     473                        tmp[i] = (char)gatewayValue[i];
     474                        if(!tmp[i])
     475                                break;
     476                }
     477                tmp[31] = '\0';
     478                *addr = inet_addr(tmp);
     479#else
    435480                *addr = inet_addr(gatewayValue);
     481#endif
    436482                return 0;
    437483        }
     
    440486}
    441487#endif /* #ifdef USE_WIN32_CODE */
     488
     489#ifdef USE_WIN32_CODE_2
     490int getdefaultgateway(in_addr_t *addr)
     491{
     492        MIB_IPFORWARDROW ip_forward;
     493        memset(&ip_forward, 0, sizeof(ip_forward));
     494        if(GetBestRoute(inet_addr("0.0.0.0"), 0, &ip_forward) != NO_ERROR)
     495                return -1;
     496        *addr = ip_forward.dwForwardNextHop;
     497        return 0;
     498}
     499#endif /* #ifdef USE_WIN32_CODE_2 */
    442500
    443501#ifdef USE_HAIKU_CODE
  • trunk/third-party/libnatpmp/getgateway.h

    r6303 r10284  
    1 /* $Id: getgateway.h,v 1.3 2008/07/02 22:33:06 nanard Exp $ */
     1/* $Id: getgateway.h,v 1.4 2009/12/19 12:00:00 nanard Exp $ */
    22/* libnatpmp
    33 * Copyright (c) 2007, Thomas BERNARD <miniupnp@free.fr>
     
    1818
    1919#ifdef WIN32
     20#if !defined(_MSC_VER)
    2021#include <stdint.h>
     22#else
     23typedef unsigned long uint32_t;
     24typedef unsigned short uint16_t;
     25#endif
    2126#define in_addr_t uint32_t
    2227#endif
  • trunk/third-party/libnatpmp/natpmp.c

    r8798 r10284  
    1 /* $Id: natpmp.c,v 1.9 2009/06/04 22:27:53 nanard Exp $ */
     1/* $Id: natpmp.c,v 1.12 2009/12/19 14:10:09 nanard Exp $ */
    22/* libnatpmp
    3  * Copyright (c) 2007-2008, Thomas BERNARD <miniupnp@free.fr>
     3 * Copyright (c) 2007-2009, Thomas BERNARD <miniupnp@free.fr>
    44 * http://miniupnp.free.fr/libnatpmp.html
    55 *
     
    1515 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    1616 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
     17#ifdef __linux__
     18#define _BSD_SOURCE 1
     19#endif
    1720#include <string.h>
    1821#include <time.h>
     22#if !defined(_MSC_VER)
    1923#include <sys/time.h>
     24#endif
    2025#ifdef WIN32
    2126#include <errno.h>
     
    2530#define EWOULDBLOCK WSAEWOULDBLOCK
    2631#define ECONNREFUSED WSAECONNREFUSED
     32#include "wingettimeofday.h"
    2733#else
    2834#include <errno.h>
     
    8187}
    8288
    83 static int sendpendingrequest(natpmp_t * p)
     89int sendpendingrequest(natpmp_t * p)
    8490{
    8591        int r;
     
    97103}
    98104
    99 static int sendnatpmprequest(natpmp_t * p)
     105int sendnatpmprequest(natpmp_t * p)
    100106{
    101107        int n;
  • trunk/third-party/libnatpmp/natpmp.h

    r8052 r10284  
    1 /* $Id: natpmp.h,v 1.11 2009/02/27 22:38:05 nanard Exp $ */
     1/* $Id: natpmp.h,v 1.12 2009/12/19 12:00:00 nanard Exp $ */
    22/* libnatpmp
    33 * Copyright (c) 2007-2008, Thomas BERNARD <miniupnp@free.fr>
     
    2222
    2323#include <time.h>
     24#if !defined(_MSC_VER)
    2425#include <sys/time.h>
     26#endif
    2527#ifdef WIN32
    2628#include <winsock2.h>
     29#if !defined(_MSC_VER)
    2730#include <stdint.h>
     31#else
     32typedef unsigned long uint32_t;
     33typedef unsigned short uint16_t;
     34#endif
    2835#define in_addr_t uint32_t
    2936#include "declspec.h"
Note: See TracChangeset for help on using the changeset viewer.