(trunk third-party) #2273: update to latest libnatpmp and miniupnpc libraries

This commit is contained in:
Charles Kerr
2009-07-13 16:00:21 +00:00
parent b3bd122108
commit 031579b5f3
12 changed files with 193 additions and 58 deletions
+49
View File
@@ -0,0 +1,49 @@
$Id: Changelog.txt,v 1.16 2009/07/13 08:36:02 nanard Exp $
2009/07/13:
Adding Haiku code in getgateway.c
2009/06/04:
Adding Python module thanks to David Wu
2009/03/10:
Trying to have windows get gateway working if not using DHCP
2009/02/27:
dont include declspec.h if not under WIN32.
2009/01/23:
Prefixed the libraries name with lib
2008/10/06:
Fixed a memory leak in getdefaultgateway() (USE_SYSCTL_NET_ROUTE)
2008/07/03:
Adding WIN32 code from Robbie Hanson
2008/06/30:
added a Solaris implementation for getgateway().
added a LICENCE file to the distribution
2008/05/29:
Anonymous unions are forbidden in ANSI C. That was causing problems with
non-GCC compilers.
2008/04/28:
introduced strnatpmperr()
improved natpmpc.c sample
make install now install the binary
2007/12/13:
Fixed getgateway.c for working under OS X ;)
Fixed values for NATPMP_PROTOCOL_TCP and NATPMP_PROTOCOL_UDP
2007/12/11:
Fixed getgateway.c for compilation under Mac OS X
2007/12/01:
added some comments in .h
2007/11/30:
implemented almost everything
+1 -1
View File
@@ -1,4 +1,4 @@
libnatpmp is written by Thomas Bernard.
Its homepage is http://miniupnp.tuxfamily.org/libnatpmp.html
This code is from the libnatpmp-20090605 snapshot
This code is from the libnatpmp-20090713 snapshot
+63 -1
View File
@@ -1,4 +1,4 @@
/* $Id: getgateway.c,v 1.14 2009/06/04 22:27:53 nanard Exp $ */
/* $Id: getgateway.c,v 1.15 2009/07/13 08:36:02 nanard Exp $ */
/* libnatpmp
* Copyright (c) 2007-2008, Thomas BERNARD <miniupnp@free.fr>
*
@@ -67,6 +67,14 @@
#include <w32api/winreg.h>
#endif
#ifdef __HAIKU__
#include <stdlib.h>
#include <unistd.h>
#include <net/if.h>
#include <sys/sockio.h>
#define USE_HAIKU_CODE
#endif
#ifdef USE_SYSCTL_NET_ROUTE
#include <stdlib.h>
#include <sys/sysctl.h>
@@ -432,3 +440,57 @@ LIBSPEC int getdefaultgateway(in_addr_t * addr)
}
#endif /* #ifdef USE_WIN32_CODE */
#ifdef USE_HAIKU_CODE
int getdefaultgateway(in_addr_t *addr)
{
int fd, ret = -1;
struct ifconf config;
void *buffer = NULL;
struct ifreq *interface;
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
return -1;
}
if (ioctl(fd, SIOCGRTSIZE, &config, sizeof(config)) != 0) {
goto fail;
}
if (config.ifc_value < 1) {
goto fail; /* No routes */
}
if ((buffer = malloc(config.ifc_value)) == NULL) {
goto fail;
}
config.ifc_len = config.ifc_value;
config.ifc_buf = buffer;
if (ioctl(fd, SIOCGRTTABLE, &config, sizeof(config)) != 0) {
goto fail;
}
for (interface = buffer;
(uint8_t *)interface < (uint8_t *)buffer + config.ifc_len; ) {
struct route_entry route = interface->ifr_route;
int intfSize;
if (route.flags & (RTF_GATEWAY | RTF_DEFAULT)) {
*addr = ((struct sockaddr_in *)route.gateway)->sin_addr.s_addr;
ret = 0;
break;
}
intfSize = sizeof(route) + IF_NAMESIZE;
if (route.destination != NULL) {
intfSize += route.destination->sa_len;
}
if (route.mask != NULL) {
intfSize += route.mask->sa_len;
}
if (route.gateway != NULL) {
intfSize += route.gateway->sa_len;
}
interface = (struct ifreq *)((uint8_t *)interface + intfSize);
}
fail:
free(buffer);
close(fd);
return ret;
}
#endif /* #ifdef USE_HAIKU_CODE */
+2 -2
View File
@@ -80,7 +80,7 @@ LIBSPEC int closenatpmp(natpmp_t * p)
return 0;
}
int sendpendingrequest(natpmp_t * p)
static int sendpendingrequest(natpmp_t * p)
{
int r;
/* struct sockaddr_in addr;*/
@@ -96,7 +96,7 @@ int sendpendingrequest(natpmp_t * p)
return (r<0) ? NATPMP_ERR_SENDERR : r;
}
int sendnatpmprequest(natpmp_t * p)
static int sendnatpmprequest(natpmp_t * p)
{
int n;
if(!p)
+15 -1
View File
@@ -1,6 +1,20 @@
$Id: Changelog.txt,v 1.77 2008/12/18 17:47:32 nanard Exp $
$Id: Changelog.txt,v 1.82 2009/07/09 16:14:06 nanard Exp $
miniUPnP client Changelog.
2009/07/09:
Compile under Haiku
generate miniupnpcstrings.h.in from miniupnpcstrings.h
2009/06/04:
patching to compile under CygWin and cross compile for minGW
2009/04/17:
updating python module
Use strtoull() when using C99
2009/02/28:
Fixed miniwget.c for compiling under sun
2008/12/18:
cleanup in Makefile (thanks to Paul de Weerd)
minissdpc.c : win32 compatibility
+1 -1
View File
@@ -1,3 +1,3 @@
MiniUPnP is written by Thomas Bernard.
Its homepage is http://miniupnp.free.fr/
This is from miniupnpc-20090605.tar.gz
This is from miniupnpc-20090713.tar.gz
+9 -9
View File
@@ -1,4 +1,4 @@
/* $Id: miniupnpc.c,v 1.57 2008/12/18 17:46:36 nanard Exp $ */
/* $Id: miniupnpc.c,v 1.58 2009/07/09 15:59:46 nanard Exp $ */
/* Project : miniupnp
* Author : Thomas BERNARD
* copyright (c) 2005-2007 Thomas Bernard
@@ -10,7 +10,7 @@
#ifdef WIN32
/* Win32 Specific includes and defines */
#include <winsock2.h>
#include <Ws2tcpip.h>
#include <ws2tcpip.h>
#include <io.h>
#define snprintf _snprintf
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
@@ -49,7 +49,7 @@
#define SERVICEPREFIX2 'u'
/* root description parsing */
void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data)
LIBSPEC void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data)
{
struct xmlparser parser;
/* xmlparser object */
@@ -340,7 +340,7 @@ parseMSEARCHReply(const char * reply, int size,
* no devices was found.
* It is up to the caller to free the chained list
* delay is in millisecond (poll) */
struct UPNPDev * upnpDiscover(int delay, const char * multicastif,
LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif,
const char * minissdpdsock, int sameport)
{
struct UPNPDev * tmp;
@@ -489,7 +489,7 @@ struct UPNPDev * upnpDiscover(int delay, const char * multicastif,
/* freeUPNPDevlist() should be used to
* free the chained list returned by upnpDiscover() */
void freeUPNPDevlist(struct UPNPDev * devlist)
LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist)
{
struct UPNPDev * next;
while(devlist)
@@ -525,7 +525,7 @@ url_cpy_or_cat(char * dst, const char * src, int n)
/* Prepare the Urls for usage...
*/
void GetUPNPUrls(struct UPNPUrls * urls, struct IGDdatas * data,
LIBSPEC void GetUPNPUrls(struct UPNPUrls * urls, struct IGDdatas * data,
const char * descURL)
{
char * p;
@@ -568,7 +568,7 @@ void GetUPNPUrls(struct UPNPUrls * urls, struct IGDdatas * data,
#endif
}
void
LIBSPEC void
FreeUPNPUrls(struct UPNPUrls * urls)
{
if(!urls)
@@ -626,7 +626,7 @@ int ReceiveData(int socket, char * data, int length, int timeout)
return n;
}
int
static int
UPNPIGD_IsConnected(struct UPNPUrls * urls, struct IGDdatas * data)
{
char status[64];
@@ -655,7 +655,7 @@ UPNPIGD_IsConnected(struct UPNPUrls * urls, struct IGDdatas * data)
* passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to
* free allocated memory.
*/
int
LIBSPEC int
UPNP_GetValidIGD(struct UPNPDev * devlist,
struct UPNPUrls * urls,
struct IGDdatas * data,
+2 -2
View File
@@ -1,4 +1,4 @@
/* $Id: miniupnpcstrings.h,v 1.3 2009/06/04 09:05:56 nanard Exp $ */
/* $Id: miniupnpcstrings.h.in,v 1.1 2009/07/09 16:13:31 nanard Exp $ */
/* Project: miniupnp
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* Author: Thomas Bernard
@@ -8,7 +8,7 @@
#ifndef __MINIUPNPCSTRINGS_H__
#define __MINIUPNPCSTRINGS_H__
#define OS_STRING "OpenBSD/4.3"
#define OS_STRING "RedHatEnterpriseClient/5.3"
#define MINIUPNPC_VERSION_STRING "1.3"
#endif
+1
View File
@@ -31,6 +31,7 @@
#endif
#include "miniupnpcstrings.h"
#include "miniwget.h"
/* miniwget2() :
* */
+2 -2
View File
@@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
/* parseatt : used to parse the argument list
* return 0 (false) in case of success and -1 (true) if the end
* of the xmlbuffer is reached. */
int parseatt(struct xmlparser * p)
static int parseatt(struct xmlparser * p)
{
const char * attname;
int attnamelen;
@@ -106,7 +106,7 @@ int parseatt(struct xmlparser * p)
/* parseelt parse the xml stream and
* call the callback functions when needed... */
void parseelt(struct xmlparser * p)
static void parseelt(struct xmlparser * p)
{
int i;
const char * elementname;
+45 -36
View File
@@ -1,4 +1,4 @@
/* $Id: upnpcommands.c,v 1.24 2009/04/17 21:21:19 nanard Exp $ */
/* $Id: upnpcommands.c,v 1.25 2009/07/09 16:00:42 nanard Exp $ */
/* Project : miniupnp
* Author : Thomas Bernard
* Copyright (c) 2005-2009 Thomas Bernard
@@ -19,7 +19,7 @@ my_atoui(const char * s)
/*
* */
UNSIGNED_INTEGER
LIBSPEC UNSIGNED_INTEGER
UPNP_GetTotalBytesSent(const char * controlURL,
const char * servicetype)
{
@@ -39,7 +39,7 @@ UPNP_GetTotalBytesSent(const char * controlURL,
/*
* */
UNSIGNED_INTEGER
LIBSPEC UNSIGNED_INTEGER
UPNP_GetTotalBytesReceived(const char * controlURL,
const char * servicetype)
{
@@ -59,7 +59,7 @@ UPNP_GetTotalBytesReceived(const char * controlURL,
/*
* */
UNSIGNED_INTEGER
LIBSPEC UNSIGNED_INTEGER
UPNP_GetTotalPacketsSent(const char * controlURL,
const char * servicetype)
{
@@ -79,7 +79,7 @@ UPNP_GetTotalPacketsSent(const char * controlURL,
/*
* */
UNSIGNED_INTEGER
LIBSPEC UNSIGNED_INTEGER
UPNP_GetTotalPacketsReceived(const char * controlURL,
const char * servicetype)
{
@@ -99,11 +99,12 @@ UPNP_GetTotalPacketsReceived(const char * controlURL,
/* UPNP_GetStatusInfo() call the corresponding UPNP method
* returns the current status and uptime */
int UPNP_GetStatusInfo(const char * controlURL,
const char * servicetype,
char * status,
unsigned int * uptime,
char * lastconnerror)
LIBSPEC int
UPNP_GetStatusInfo(const char * controlURL,
const char * servicetype,
char * status,
unsigned int * uptime,
char * lastconnerror)
{
struct NameValueParserData pdata;
char buffer[4096];
@@ -159,9 +160,10 @@ int UPNP_GetStatusInfo(const char * controlURL,
/* UPNP_GetConnectionTypeInfo() call the corresponding UPNP method
* returns the connection type */
int UPNP_GetConnectionTypeInfo(const char * controlURL,
const char * servicetype,
char * connectionType)
LIBSPEC int
UPNP_GetConnectionTypeInfo(const char * controlURL,
const char * servicetype,
char * connectionType)
{
struct NameValueParserData pdata;
char buffer[4096];
@@ -198,7 +200,11 @@ int UPNP_GetConnectionTypeInfo(const char * controlURL,
* One of the values can be null
* Note : GetLinkLayerMaxBitRates belongs to WANPPPConnection:1 only
* We can use the GetCommonLinkProperties from WANCommonInterfaceConfig:1 */
int UPNP_GetLinkLayerMaxBitRates(const char * controlURL, const char * servicetype, unsigned int * bitrateDown, unsigned int* bitrateUp)
LIBSPEC int
UPNP_GetLinkLayerMaxBitRates(const char * controlURL,
const char * servicetype,
unsigned int * bitrateDown,
unsigned int* bitrateUp)
{
struct NameValueParserData pdata;
char buffer[4096];
@@ -226,16 +232,14 @@ int UPNP_GetLinkLayerMaxBitRates(const char * controlURL, const char * servicety
if(down && up)
ret = UPNPCOMMAND_SUCCESS;
if(bitrateDown)
{
if(bitrateDown) {
if(down)
sscanf(down,"%u",bitrateDown);
else
*bitrateDown = 0;
}
if(bitrateUp)
{
if(bitrateUp) {
if(up)
sscanf(up,"%u",bitrateUp);
else
@@ -262,9 +266,10 @@ int UPNP_GetLinkLayerMaxBitRates(const char * controlURL, const char * servicety
* 402 Invalid Args - See UPnP Device Architecture section on Control.
* 501 Action Failed - See UPnP Device Architecture section on Control.
*/
int UPNP_GetExternalIPAddress(const char * controlURL,
const char * servicetype,
char * extIpAdd)
LIBSPEC int
UPNP_GetExternalIPAddress(const char * controlURL,
const char * servicetype,
char * extIpAdd)
{
struct NameValueParserData pdata;
char buffer[4096];
@@ -297,7 +302,7 @@ int UPNP_GetExternalIPAddress(const char * controlURL,
return ret;
}
int
LIBSPEC int
UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
const char * extPort,
const char * inPort,
@@ -351,7 +356,7 @@ UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
return ret;
}
int
LIBSPEC int
UPNP_DeletePortMapping(const char * controlURL, const char * servicetype,
const char * extPort, const char * proto,
const char * remoteHost)
@@ -391,17 +396,18 @@ UPNP_DeletePortMapping(const char * controlURL, const char * servicetype,
return ret;
}
int UPNP_GetGenericPortMappingEntry(const char * controlURL,
const char * servicetype,
const char * index,
char * extPort,
char * intClient,
char * intPort,
char * protocol,
char * desc,
char * enabled,
char * rHost,
char * duration)
LIBSPEC int
UPNP_GetGenericPortMappingEntry(const char * controlURL,
const char * servicetype,
const char * index,
char * extPort,
char * intClient,
char * intPort,
char * protocol,
char * desc,
char * enabled,
char * rHost,
char * duration)
{
struct NameValueParserData pdata;
struct UPNParg * GetPortMappingArgs;
@@ -480,7 +486,10 @@ int UPNP_GetGenericPortMappingEntry(const char * controlURL,
return r;
}
int UPNP_GetPortMappingNumberOfEntries(const char * controlURL, const char * servicetype, unsigned int * numEntries)
LIBSPEC int
UPNP_GetPortMappingNumberOfEntries(const char * controlURL,
const char * servicetype,
unsigned int * numEntries)
{
struct NameValueParserData pdata;
char buffer[4096];
@@ -513,7 +522,7 @@ int UPNP_GetPortMappingNumberOfEntries(const char * controlURL, const char * ser
/* UPNP_GetSpecificPortMappingEntry retrieves an existing port mapping
* the result is returned in the intClient and intPort strings
* please provide 16 and 6 bytes of data */
int
LIBSPEC int
UPNP_GetSpecificPortMappingEntry(const char * controlURL,
const char * servicetype,
const char * extPort,
+3 -3
View File
@@ -1,14 +1,14 @@
/* $Id: upnpreplyparse.h,v 1.8 2008/02/21 13:05:27 nanard Exp $ */
/* $Id: upnpreplyparse.h,v 1.10 2009/07/09 16:01:50 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006 Thomas Bernard
* (c) 2006-2009 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
#ifndef __UPNPREPLYPARSE_H__
#define __UPNPREPLYPARSE_H__
#if defined(NO_SYS_QUEUE_H) || defined(WIN32)
#if defined(NO_SYS_QUEUE_H) || defined(WIN32) || defined(__HAIKU__)
#include "bsdqueue.h"
#else
#include <sys/queue.h>