update miniupnpc to 20100609
This commit is contained in:
parent
c19f73f77e
commit
b13cfe2ea6
|
@ -1,6 +1,16 @@
|
|||
$Id: Changelog.txt,v 1.113 2010/04/12 20:39:40 nanard Exp $
|
||||
$Id: Changelog.txt,v 1.117 2010/06/09 10:59:08 nanard Exp $
|
||||
miniUPnP client Changelog.
|
||||
|
||||
2010/06/09:
|
||||
update to python module to match modification made on 2010/04/05
|
||||
update to Java test code to match modification made on 2010/04/05
|
||||
all UPNP_* function now return an error if the SOAP request failed
|
||||
at HTTP level.
|
||||
|
||||
2010/04/17:
|
||||
Using GetBestRoute() under win32 in order to find the
|
||||
right interface to use.
|
||||
|
||||
2010/04/12:
|
||||
Retrying with HTTP/1.1 if HTTP/1.0 failed. see
|
||||
http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=1703
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: miniupnpc.c,v 1.80 2010/04/12 20:39:41 nanard Exp $ */
|
||||
/* $Id: miniupnpc.c,v 1.81 2010/04/17 22:07:59 nanard Exp $ */
|
||||
/* Project : miniupnp
|
||||
* Author : Thomas BERNARD
|
||||
* copyright (c) 2005-2010 Thomas Bernard
|
||||
|
@ -24,7 +24,7 @@
|
|||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <io.h>
|
||||
/*#include <IPHlpApi.h>*/
|
||||
#include <IPHlpApi.h>
|
||||
#define snprintf _snprintf
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
#define strncasecmp _memicmp
|
||||
|
@ -420,7 +420,7 @@ LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif,
|
|||
int rv;
|
||||
struct addrinfo hints, *servinfo, *p;
|
||||
#ifdef WIN32
|
||||
/*MIB_IPFORWARDROW ip_forward;*/
|
||||
MIB_IPFORWARDROW ip_forward;
|
||||
#endif
|
||||
|
||||
#if !defined(WIN32) && !defined(__amigaos__) && !defined(__amigaos4__)
|
||||
|
@ -473,41 +473,60 @@ LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif,
|
|||
#ifdef WIN32
|
||||
/* This code could help us to use the right Network interface for
|
||||
* SSDP multicast traffic */
|
||||
/* TODO : Get IP associated with the index given in the ip_forward struct
|
||||
/* Get IP associated with the index given in the ip_forward struct
|
||||
* in order to give this ip to setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF) */
|
||||
/*
|
||||
if(GetBestRoute(inet_addr("223.255.255.255"), 0, &ip_forward) == NO_ERROR) {
|
||||
DWORD dwRetVal = 0;
|
||||
PMIB_IPADDRTABLE pIPAddrTable;
|
||||
DWORD dwSize = 0;
|
||||
IN_ADDR IPAddr;
|
||||
int i;
|
||||
printf("ifIndex=%lu nextHop=%lx \n", ip_forward.dwForwardIfIndex, ip_forward.dwForwardNextHop);
|
||||
pIPAddrTable = (MIB_IPADDRTABLE *) malloc(sizeof (MIB_IPADDRTABLE));
|
||||
if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
|
||||
free(pIPAddrTable);
|
||||
pIPAddrTable = (MIB_IPADDRTABLE *) malloc(dwSize);
|
||||
}
|
||||
if(pIPAddrTable) {
|
||||
dwRetVal = GetIpAddrTable( pIPAddrTable, &dwSize, 0 );
|
||||
printf("\tNum Entries: %ld\n", pIPAddrTable->dwNumEntries);
|
||||
for (i=0; i < (int) pIPAddrTable->dwNumEntries; i++) {
|
||||
printf("\n\tInterface Index[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwIndex);
|
||||
IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwAddr;
|
||||
printf("\tIP Address[%d]: \t%s\n", i, inet_ntoa(IPAddr) );
|
||||
IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwMask;
|
||||
printf("\tSubnet Mask[%d]: \t%s\n", i, inet_ntoa(IPAddr) );
|
||||
IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwBCastAddr;
|
||||
printf("\tBroadCast[%d]: \t%s (%ld)\n", i, inet_ntoa(IPAddr), pIPAddrTable->table[i].dwBCastAddr);
|
||||
printf("\tReassembly size[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwReasmSize);
|
||||
printf("\tType and State[%d]:", i);
|
||||
printf("\n");
|
||||
}
|
||||
DWORD dwSize = 0;
|
||||
#ifdef DEBUG
|
||||
IN_ADDR IPAddr;
|
||||
#endif
|
||||
int i;
|
||||
#ifdef DEBUG
|
||||
printf("ifIndex=%lu nextHop=%lx \n", ip_forward.dwForwardIfIndex, ip_forward.dwForwardNextHop);
|
||||
#endif
|
||||
pIPAddrTable = (MIB_IPADDRTABLE *) malloc(sizeof (MIB_IPADDRTABLE));
|
||||
if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
|
||||
free(pIPAddrTable);
|
||||
pIPAddrTable = NULL;
|
||||
}
|
||||
pIPAddrTable = (MIB_IPADDRTABLE *) malloc(dwSize);
|
||||
}
|
||||
if(pIPAddrTable) {
|
||||
dwRetVal = GetIpAddrTable( pIPAddrTable, &dwSize, 0 );
|
||||
#ifdef DEBUG
|
||||
printf("\tNum Entries: %ld\n", pIPAddrTable->dwNumEntries);
|
||||
#endif
|
||||
for (i=0; i < (int) pIPAddrTable->dwNumEntries; i++) {
|
||||
#ifdef DEBUG
|
||||
printf("\n\tInterface Index[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwIndex);
|
||||
IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwAddr;
|
||||
printf("\tIP Address[%d]: \t%s\n", i, inet_ntoa(IPAddr) );
|
||||
IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwMask;
|
||||
printf("\tSubnet Mask[%d]: \t%s\n", i, inet_ntoa(IPAddr) );
|
||||
IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwBCastAddr;
|
||||
printf("\tBroadCast[%d]: \t%s (%ld)\n", i, inet_ntoa(IPAddr), pIPAddrTable->table[i].dwBCastAddr);
|
||||
printf("\tReassembly size[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwReasmSize);
|
||||
printf("\tType and State[%d]:", i);
|
||||
printf("\n");
|
||||
#endif
|
||||
if (pIPAddrTable->table[i].dwIndex == ip_forward.dwForwardIfIndex) {
|
||||
/* Set the address of this interface to be used */
|
||||
struct in_addr mc_if;
|
||||
memset(&mc_if, 0, sizeof(mc_if));
|
||||
mc_if.s_addr = pIPAddrTable->table[i].dwAddr;
|
||||
if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF, (const char *)&mc_if, sizeof(mc_if)) < 0) {
|
||||
PRINT_SOCKET_ERROR("setsockopt");
|
||||
}
|
||||
((struct sockaddr_in *)&sockudp_r)->sin_addr.s_addr = pIPAddrTable->table[i].dwAddr;
|
||||
#ifndef DEBUG
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
free(pIPAddrTable);
|
||||
pIPAddrTable = NULL;
|
||||
}
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $Id: upnpcommands.c,v 1.25 2009/07/09 16:00:42 nanard Exp $ */
|
||||
/* $Id: upnpcommands.c,v 1.26 2010/06/09 10:59:09 nanard Exp $ */
|
||||
/* Project : miniupnp
|
||||
* Author : Thomas Bernard
|
||||
* Copyright (c) 2005-2009 Thomas Bernard
|
||||
* Copyright (c) 2005-2010 Thomas Bernard
|
||||
* This software is subject to the conditions detailed in the
|
||||
* LICENCE file provided in this distribution.
|
||||
* */
|
||||
|
@ -28,7 +28,9 @@ UPNP_GetTotalBytesSent(const char * controlURL,
|
|||
int bufsize = 4096;
|
||||
unsigned int r = 0;
|
||||
char * p;
|
||||
simpleUPnPcommand(-1, controlURL, servicetype, "GetTotalBytesSent", 0, buffer, &bufsize);
|
||||
if(simpleUPnPcommand(-1, controlURL, servicetype, "GetTotalBytesSent", 0, buffer, &bufsize) < 0) {
|
||||
return UPNPCOMMAND_HTTP_ERROR;
|
||||
}
|
||||
ParseNameValue(buffer, bufsize, &pdata);
|
||||
/*DisplayNameValueList(buffer, bufsize);*/
|
||||
p = GetValueFromNameValueList(&pdata, "NewTotalBytesSent");
|
||||
|
@ -48,7 +50,9 @@ UPNP_GetTotalBytesReceived(const char * controlURL,
|
|||
int bufsize = 4096;
|
||||
unsigned int r = 0;
|
||||
char * p;
|
||||
simpleUPnPcommand(-1, controlURL, servicetype, "GetTotalBytesReceived", 0, buffer, &bufsize);
|
||||
if(simpleUPnPcommand(-1, controlURL, servicetype, "GetTotalBytesReceived", 0, buffer, &bufsize) < 0) {
|
||||
return UPNPCOMMAND_HTTP_ERROR;
|
||||
}
|
||||
ParseNameValue(buffer, bufsize, &pdata);
|
||||
/*DisplayNameValueList(buffer, bufsize);*/
|
||||
p = GetValueFromNameValueList(&pdata, "NewTotalBytesReceived");
|
||||
|
@ -68,7 +72,9 @@ UPNP_GetTotalPacketsSent(const char * controlURL,
|
|||
int bufsize = 4096;
|
||||
unsigned int r = 0;
|
||||
char * p;
|
||||
simpleUPnPcommand(-1, controlURL, servicetype, "GetTotalPacketsSent", 0, buffer, &bufsize);
|
||||
if(simpleUPnPcommand(-1, controlURL, servicetype, "GetTotalPacketsSent", 0, buffer, &bufsize) < 0) {
|
||||
return UPNPCOMMAND_HTTP_ERROR;
|
||||
}
|
||||
ParseNameValue(buffer, bufsize, &pdata);
|
||||
/*DisplayNameValueList(buffer, bufsize);*/
|
||||
p = GetValueFromNameValueList(&pdata, "NewTotalPacketsSent");
|
||||
|
@ -88,7 +94,9 @@ UPNP_GetTotalPacketsReceived(const char * controlURL,
|
|||
int bufsize = 4096;
|
||||
unsigned int r = 0;
|
||||
char * p;
|
||||
simpleUPnPcommand(-1, controlURL, servicetype, "GetTotalPacketsReceived", 0, buffer, &bufsize);
|
||||
if(simpleUPnPcommand(-1, controlURL, servicetype, "GetTotalPacketsReceived", 0, buffer, &bufsize) < 0) {
|
||||
return UPNPCOMMAND_HTTP_ERROR;
|
||||
}
|
||||
ParseNameValue(buffer, bufsize, &pdata);
|
||||
/*DisplayNameValueList(buffer, bufsize);*/
|
||||
p = GetValueFromNameValueList(&pdata, "NewTotalPacketsReceived");
|
||||
|
@ -117,7 +125,9 @@ UPNP_GetStatusInfo(const char * controlURL,
|
|||
if(!status && !uptime)
|
||||
return UPNPCOMMAND_INVALID_ARGS;
|
||||
|
||||
simpleUPnPcommand(-1, controlURL, servicetype, "GetStatusInfo", 0, buffer, &bufsize);
|
||||
if(simpleUPnPcommand(-1, controlURL, servicetype, "GetStatusInfo", 0, buffer, &bufsize) < 0) {
|
||||
return UPNPCOMMAND_HTTP_ERROR;
|
||||
}
|
||||
ParseNameValue(buffer, bufsize, &pdata);
|
||||
/*DisplayNameValueList(buffer, bufsize);*/
|
||||
up = GetValueFromNameValueList(&pdata, "NewUptime");
|
||||
|
@ -174,8 +184,10 @@ UPNP_GetConnectionTypeInfo(const char * controlURL,
|
|||
if(!connectionType)
|
||||
return UPNPCOMMAND_INVALID_ARGS;
|
||||
|
||||
simpleUPnPcommand(-1, controlURL, servicetype,
|
||||
"GetConnectionTypeInfo", 0, buffer, &bufsize);
|
||||
if(simpleUPnPcommand(-1, controlURL, servicetype,
|
||||
"GetConnectionTypeInfo", 0, buffer, &bufsize) < 0) {
|
||||
return UPNPCOMMAND_HTTP_ERROR;
|
||||
}
|
||||
ParseNameValue(buffer, bufsize, &pdata);
|
||||
p = GetValueFromNameValueList(&pdata, "NewConnectionType");
|
||||
/*p = GetValueFromNameValueList(&pdata, "NewPossibleConnectionTypes");*/
|
||||
|
@ -218,9 +230,11 @@ UPNP_GetLinkLayerMaxBitRates(const char * controlURL,
|
|||
return UPNPCOMMAND_INVALID_ARGS;
|
||||
|
||||
/* shouldn't we use GetCommonLinkProperties ? */
|
||||
simpleUPnPcommand(-1, controlURL, servicetype,
|
||||
"GetCommonLinkProperties", 0, buffer, &bufsize);
|
||||
if(simpleUPnPcommand(-1, controlURL, servicetype,
|
||||
"GetCommonLinkProperties", 0, buffer, &bufsize) < 0) {
|
||||
/*"GetLinkLayerMaxBitRates", 0, buffer, &bufsize);*/
|
||||
return UPNPCOMMAND_HTTP_ERROR;
|
||||
}
|
||||
/*DisplayNameValueList(buffer, bufsize);*/
|
||||
ParseNameValue(buffer, bufsize, &pdata);
|
||||
/*down = GetValueFromNameValueList(&pdata, "NewDownstreamMaxBitRate");*/
|
||||
|
@ -280,7 +294,9 @@ UPNP_GetExternalIPAddress(const char * controlURL,
|
|||
if(!extIpAdd || !controlURL || !servicetype)
|
||||
return UPNPCOMMAND_INVALID_ARGS;
|
||||
|
||||
simpleUPnPcommand(-1, controlURL, servicetype, "GetExternalIPAddress", 0, buffer, &bufsize);
|
||||
if(simpleUPnPcommand(-1, controlURL, servicetype, "GetExternalIPAddress", 0, buffer, &bufsize) < 0) {
|
||||
return UPNPCOMMAND_HTTP_ERROR;
|
||||
}
|
||||
/*DisplayNameValueList(buffer, bufsize);*/
|
||||
ParseNameValue(buffer, bufsize, &pdata);
|
||||
/*printf("external ip = %s\n", GetValueFromNameValueList(&pdata, "NewExternalIPAddress") );*/
|
||||
|
@ -338,7 +354,10 @@ UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
|
|||
AddPortMappingArgs[6].val = desc?desc:"libminiupnpc";
|
||||
AddPortMappingArgs[7].elt = "NewLeaseDuration";
|
||||
AddPortMappingArgs[7].val = "0";
|
||||
simpleUPnPcommand(-1, controlURL, servicetype, "AddPortMapping", AddPortMappingArgs, buffer, &bufsize);
|
||||
if(simpleUPnPcommand(-1, controlURL, servicetype, "AddPortMapping", AddPortMappingArgs, buffer, &bufsize) < 0) {
|
||||
free(AddPortMappingArgs);
|
||||
return UPNPCOMMAND_HTTP_ERROR;
|
||||
}
|
||||
/*DisplayNameValueList(buffer, bufsize);*/
|
||||
/*buffer[bufsize] = '\0';*/
|
||||
/*puts(buffer);*/
|
||||
|
@ -379,9 +398,12 @@ UPNP_DeletePortMapping(const char * controlURL, const char * servicetype,
|
|||
DeletePortMappingArgs[1].val = extPort;
|
||||
DeletePortMappingArgs[2].elt = "NewProtocol";
|
||||
DeletePortMappingArgs[2].val = proto;
|
||||
simpleUPnPcommand(-1, controlURL, servicetype,
|
||||
"DeletePortMapping",
|
||||
DeletePortMappingArgs, buffer, &bufsize);
|
||||
if(simpleUPnPcommand(-1, controlURL, servicetype,
|
||||
"DeletePortMapping",
|
||||
DeletePortMappingArgs, buffer, &bufsize) < 0 ) {
|
||||
free(DeletePortMappingArgs);
|
||||
return UPNPCOMMAND_HTTP_ERROR;
|
||||
}
|
||||
/*DisplayNameValueList(buffer, bufsize);*/
|
||||
ParseNameValue(buffer, bufsize, &pdata);
|
||||
resVal = GetValueFromNameValueList(&pdata, "errorCode");
|
||||
|
@ -422,9 +444,12 @@ UPNP_GetGenericPortMappingEntry(const char * controlURL,
|
|||
GetPortMappingArgs = calloc(2, sizeof(struct UPNParg));
|
||||
GetPortMappingArgs[0].elt = "NewPortMappingIndex";
|
||||
GetPortMappingArgs[0].val = index;
|
||||
simpleUPnPcommand(-1, controlURL, servicetype,
|
||||
if(simpleUPnPcommand(-1, controlURL, servicetype,
|
||||
"GetGenericPortMappingEntry",
|
||||
GetPortMappingArgs, buffer, &bufsize);
|
||||
GetPortMappingArgs, buffer, &bufsize) < 0) {
|
||||
free(GetPortMappingArgs);
|
||||
return UPNPCOMMAND_HTTP_ERROR;
|
||||
}
|
||||
ParseNameValue(buffer, bufsize, &pdata);
|
||||
p = GetValueFromNameValueList(&pdata, "NewRemoteHost");
|
||||
if(p && rHost)
|
||||
|
@ -496,7 +521,9 @@ UPNP_GetPortMappingNumberOfEntries(const char * controlURL,
|
|||
int bufsize = 4096;
|
||||
char* p;
|
||||
int ret = UPNPCOMMAND_UNKNOWN_ERROR;
|
||||
simpleUPnPcommand(-1, controlURL, servicetype, "GetPortMappingNumberOfEntries", 0, buffer, &bufsize);
|
||||
if(simpleUPnPcommand(-1, controlURL, servicetype, "GetPortMappingNumberOfEntries", 0, buffer, &bufsize) < 0) {
|
||||
return UPNPCOMMAND_HTTP_ERROR;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
DisplayNameValueList(buffer, bufsize);
|
||||
#endif
|
||||
|
@ -546,10 +573,12 @@ UPNP_GetSpecificPortMappingEntry(const char * controlURL,
|
|||
GetPortMappingArgs[1].val = extPort;
|
||||
GetPortMappingArgs[2].elt = "NewProtocol";
|
||||
GetPortMappingArgs[2].val = proto;
|
||||
simpleUPnPcommand(-1, controlURL, servicetype,
|
||||
"GetSpecificPortMappingEntry",
|
||||
GetPortMappingArgs, buffer, &bufsize);
|
||||
/*fd = simpleUPnPcommand(fd, controlURL, data.servicetype, "GetSpecificPortMappingEntry", AddPortMappingArgs, buffer, &bufsize); */
|
||||
if(simpleUPnPcommand(-1, controlURL, servicetype,
|
||||
"GetSpecificPortMappingEntry",
|
||||
GetPortMappingArgs, buffer, &bufsize) < 0) {
|
||||
free(GetPortMappingArgs);
|
||||
return UPNPCOMMAND_HTTP_ERROR;
|
||||
}
|
||||
/*DisplayNameValueList(buffer, bufsize);*/
|
||||
ParseNameValue(buffer, bufsize, &pdata);
|
||||
|
||||
|
|
Loading…
Reference in New Issue