Changeset 6303
- Timestamp:
- Jul 9, 2008, 2:51:29 AM (15 years ago)
- Location:
- trunk/third-party
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/third-party/libnatpmp/README
r6268 r6303 1 1 libnatpmp is written by Thomas Bernard. 2 2 Its homepage is http://miniupnp.tuxfamily.org/libnatpmp.html 3 This code is from the libnatpmp-20080 630snapshot3 This code is from the libnatpmp-20080707 snapshot 4 4 -
trunk/third-party/libnatpmp/getgateway.c
r6271 r6303 1 /* $Id: getgateway.c,v 1. 8 2008/06/30 14:15:40nanard Exp $ */1 /* $Id: getgateway.c,v 1.11 2008/07/02 23:56:11 nanard Exp $ */ 2 2 /* libnatpmp 3 3 * Copyright (c) 2007-2008, Thomas BERNARD <miniupnp@free.fr> … … 16 16 #include <stdio.h> 17 17 #include <ctype.h> 18 #ifndef WIN32 18 19 #include <netinet/in.h> 20 #endif 19 21 #include <sys/param.h> 20 22 /* There is no portable method to get the default route gateway. … … 25 27 * sockets. */ 26 28 #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 35 57 #endif 36 58 … … 48 70 #include <net/route.h> 49 71 #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 50 78 #include "getgateway.h" 51 79 80 #ifndef WIN32 52 81 #define SUCCESS (0) 53 82 #define FAILED (-1) 83 #endif 54 84 55 85 #ifdef USE_PROC_NET_ROUTE … … 230 260 #endif /* #ifdef USE_SOCKET_ROUTE */ 231 261 262 #ifdef USE_WIN32_CODE 263 int 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:37nanard Exp $ */1 /* $Id: getgateway.h,v 1.3 2008/07/02 22:33:06 nanard Exp $ */ 2 2 /* libnatpmp 3 3 * Copyright (c) 2007, Thomas BERNARD <miniupnp@free.fr> … … 17 17 #define __GETGATEWAY_H__ 18 18 19 #ifdef WIN32 20 #include <stdint.h> 21 #define in_addr_t uint32_t 22 #endif 23 #include "declspec.h" 24 19 25 /* getdefaultgateway() : 20 26 * return value : 21 27 * 0 : success 22 28 * -1 : failure */ 23 int getdefaultgateway(in_addr_t * addr);29 LIBSPEC int getdefaultgateway(in_addr_t * addr); 24 30 25 31 #endif -
trunk/third-party/libnatpmp/natpmp.c
r5970 r6303 1 /* $Id: natpmp.c,v 1. 7 2008/05/29 08:06:01nanard Exp $ */1 /* $Id: natpmp.c,v 1.8 2008/07/02 22:33:06 nanard Exp $ */ 2 2 /* libnatpmp 3 3 * Copyright (c) 2007-2008, Thomas BERNARD <miniupnp@free.fr> … … 22 22 #include <Ws2tcpip.h> 23 23 #include <io.h> 24 #define EWOULDBLOCK WSAEWOULDBLOCK 25 #define ECONNREFUSED WSAECONNREFUSED 24 26 #else 25 27 #include <errno.h> … … 28 30 #include <sys/types.h> 29 31 #include <sys/socket.h> 32 #define closesocket close 30 33 #endif 31 34 #include "natpmp.h" … … 34 37 int initnatpmp(natpmp_t * p) 35 38 { 39 #ifdef WIN32 40 u_long ioctlArg = 1; 41 #else 36 42 int flags; 43 #endif 37 44 struct sockaddr_in addr; 38 45 if(!p) … … 42 49 if(p->s < 0) 43 50 return NATPMP_ERR_SOCKETERROR; 51 #ifdef WIN32 52 if(ioctlsocket(p->s, FIONBIO, &ioctlArg) == SOCKET_ERROR) 53 return NATPMP_ERR_FCNTLERROR; 54 #else 44 55 if((flags = fcntl(p->s, F_GETFL, 0)) < 0) 45 56 return NATPMP_ERR_FCNTLERROR; 46 57 if(fcntl(p->s, F_SETFL, flags | O_NONBLOCK) < 0) 47 58 return NATPMP_ERR_FCNTLERROR; 59 #endif 48 60 49 61 if(getdefaultgateway(&(p->gateway)) < 0) … … 63 75 if(!p) 64 76 return NATPMP_ERR_INVALIDARGS; 65 if(close (p->s) < 0)77 if(closesocket(p->s) < 0) 66 78 return NATPMP_ERR_CLOSEERR; 67 79 return 0; … … 161 173 if(n<0) 162 174 switch(errno) { 163 case EAGAIN: 175 /*case EAGAIN:*/ 176 case EWOULDBLOCK: 164 177 n = NATPMP_TRYAGAIN; 165 178 break; … … 270 283 break; 271 284 case NATPMP_ERR_CLOSEERR: 285 #ifdef WIN32 286 s = "closesocket() failed"; 287 #else 272 288 s = "close() failed"; 289 #endif 273 290 break; 274 291 case NATPMP_ERR_RECVFROM: -
trunk/third-party/libnatpmp/natpmp.h
r5970 r6303 1 /* $Id: natpmp.h,v 1. 9 2008/05/29 08:06:01nanard Exp $ */1 /* $Id: natpmp.h,v 1.10 2008/07/02 22:33:06 nanard Exp $ */ 2 2 /* libnatpmp 3 3 * Copyright (c) 2007-2008, Thomas BERNARD <miniupnp@free.fr> … … 25 25 #ifdef WIN32 26 26 #include <winsock2.h> 27 #include <stdint.h> 28 #define in_addr_t uint32_t 27 29 #else 28 30 #include <netinet/in.h> 29 31 #endif 32 #include "declspec.h" 30 33 31 34 typedef struct { … … 114 117 * NATPMP_ERR_CANNOTGETGATEWAY 115 118 * NATPMP_ERR_CONNECTERR */ 116 int initnatpmp(natpmp_t * p);119 LIBSPEC int initnatpmp(natpmp_t * p); 117 120 118 121 /* closenatpmp() … … 122 125 * NATPMP_ERR_INVALIDARGS 123 126 * NATPMP_ERR_CLOSEERR */ 124 int closenatpmp(natpmp_t * p);127 LIBSPEC int closenatpmp(natpmp_t * p); 125 128 126 129 /* sendpublicaddressrequest() … … 130 133 * NATPMP_ERR_INVALIDARGS 131 134 * NATPMP_ERR_SENDERR */ 132 int sendpublicaddressrequest(natpmp_t * p);135 LIBSPEC int sendpublicaddressrequest(natpmp_t * p); 133 136 134 137 /* sendnewportmappingrequest() … … 144 147 * NATPMP_ERR_INVALIDARGS 145 148 * NATPMP_ERR_SENDERR */ 146 int sendnewportmappingrequest(natpmp_t * p, int protocol,149 LIBSPEC int sendnewportmappingrequest(natpmp_t * p, int protocol, 147 150 uint16_t privateport, uint16_t publicport, 148 151 uint32_t lifetime); … … 156 159 * NATPMP_ERR_GETTIMEOFDAYERR 157 160 * NATPMP_ERR_NOPENDINGREQ */ 158 int getnatpmprequesttimeout(natpmp_t * p, struct timeval * timeout);161 LIBSPEC int getnatpmprequesttimeout(natpmp_t * p, struct timeval * timeout); 159 162 160 163 /* readnatpmpresponseorretry() … … 175 178 * NATPMP_ERR_UNSUPPORTEDOPCODE 176 179 * NATPMP_ERR_UNDEFINEDERROR */ 177 int readnatpmpresponseorretry(natpmp_t * p, natpmpresp_t * response);180 LIBSPEC int readnatpmpresponseorretry(natpmp_t * p, natpmpresp_t * response); 178 181 179 182 #ifdef ENABLE_STRNATPMPERR 180 const char * strnatpmperr(int t);183 LIBSPEC const char * strnatpmperr(int t); 181 184 #endif 182 185 -
trunk/third-party/miniupnp/LICENCE
r3731 r6303 1 Copyright (c) 2005-200 7, Thomas BERNARD1 Copyright (c) 2005-2008, Thomas BERNARD 2 2 All rights reserved. 3 3 -
trunk/third-party/miniupnp/README
r5743 r6303 1 1 MiniUPnP is written by Thomas Bernard. 2 2 Its homepage is http://miniupnp.free.fr/ 3 This is from the miniupnp-20080 428snapshot3 This is from the miniupnp-20080703 snapshot
Note: See TracChangeset
for help on using the changeset viewer.