1
/* $Id: miniupnpc.c,v 1.95 2011/05/15 21:42:26 nanard Exp $ */
3
* Author : Thomas BERNARD
4
* copyright (c) 2005-2011 Thomas Bernard
5
* This software is subjet to the conditions detailed in the
6
* provided LICENSE file. */
7
#define __EXTENSIONS__ 1
8
#if !defined(MACOSX) && !defined(__sun)
9
#if !defined(_XOPEN_SOURCE) && !defined(__OpenBSD__) && !defined(__NetBSD__)
11
#define _XOPEN_SOURCE 600
15
#define __BSD_VISIBLE 1
23
/* Win32 Specific includes and defines */
28
#define snprintf _snprintf
30
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
31
#define strncasecmp _memicmp
32
#else /* defined(_MSC_VER) && (_MSC_VER >= 1400) */
33
#define strncasecmp memicmp
34
#endif /* defined(_MSC_VER) && (_MSC_VER >= 1400) */
35
#endif /* #ifndef strncasecmp */
36
#define MAXHOSTNAMELEN 64
37
#else /* #ifdef WIN32 */
38
/* Standard POSIX includes */
40
#if defined(__amigaos__) && !defined(__amigaos4__)
41
/* Amiga OS 3 specific stuff */
44
#include <sys/select.h>
46
#include <sys/socket.h>
47
#include <sys/types.h>
48
#include <sys/param.h>
49
#include <netinet/in.h>
50
#include <arpa/inet.h>
53
#if !defined(__amigaos__) && !defined(__amigaos4__)
58
#define closesocket close
59
#endif /* #else WIN32 */
60
#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT
63
#if defined(__amigaos__) || defined(__amigaos4__)
64
/* Amiga OS specific stuff */
65
#define TIMEVAL struct timeval
68
#include "miniupnpc.h"
69
#include "minissdpc.h"
73
#include "upnpcommands.h"
74
#include "connecthostport.h"
75
#include "receivedata.h"
78
#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError());
80
#define PRINT_SOCKET_ERROR(x) perror(x)
83
#define SOAPPREFIX "s"
84
#define SERVICEPREFIX "u"
85
#define SERVICEPREFIX2 'u'
87
/* root description parsing */
88
LIBSPEC void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data)
90
struct xmlparser parser;
91
/* xmlparser object */
92
parser.xmlstart = buffer;
93
parser.xmlsize = bufsize;
95
parser.starteltfunc = IGDstartelt;
96
parser.endeltfunc = IGDendelt;
97
parser.datafunc = IGDdata;
105
/* simpleUPnPcommand2 :
110
char * simpleUPnPcommand2(int s, const char * url, const char * service,
111
const char * action, struct UPNParg * args,
112
int * bufsize, const char * httpversion)
114
char hostname[MAXHOSTNAMELEN+1];
115
unsigned short port = 0;
123
snprintf(soapact, sizeof(soapact), "%s#%s", service, action);
126
/*soapbodylen = */snprintf(soapbody, sizeof(soapbody),
127
"<?xml version=\"1.0\"?>\r\n"
128
"<" SOAPPREFIX ":Envelope "
129
"xmlns:" SOAPPREFIX "=\"http://schemas.xmlsoap.org/soap/envelope/\" "
130
SOAPPREFIX ":encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
131
"<" SOAPPREFIX ":Body>"
132
"<" SERVICEPREFIX ":%s xmlns:" SERVICEPREFIX "=\"%s\">"
133
"</" SERVICEPREFIX ":%s>"
134
"</" SOAPPREFIX ":Body></" SOAPPREFIX ":Envelope>"
135
"\r\n", action, service, action);
140
const char * pe, * pv;
142
soapbodylen = snprintf(soapbody, sizeof(soapbody),
143
"<?xml version=\"1.0\"?>\r\n"
144
"<" SOAPPREFIX ":Envelope "
145
"xmlns:" SOAPPREFIX "=\"http://schemas.xmlsoap.org/soap/envelope/\" "
146
SOAPPREFIX ":encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
147
"<" SOAPPREFIX ":Body>"
148
"<" SERVICEPREFIX ":%s xmlns:" SERVICEPREFIX "=\"%s\">",
150
p = soapbody + soapbodylen;
153
/* check that we are never overflowing the string... */
154
if(soapbody + sizeof(soapbody) <= p + 100)
156
/* we keep a margin of at least 100 bytes */
179
*(p++) = SERVICEPREFIX2;
184
strncpy(p, "></" SOAPPREFIX ":Body></" SOAPPREFIX ":Envelope>\r\n",
185
soapbody + sizeof(soapbody) - p);
187
if(!parseURL(url, hostname, &port, &path)) return NULL;
190
s = connecthostport(hostname, port);
197
n = soapPostSubmit(s, path, hostname, port, soapact, soapbody, httpversion);
200
printf("Error sending SOAP request\n");
206
buf = getHTTPResponse(s, bufsize);
208
if(*bufsize > 0 && buf)
210
printf("SOAP Response :\n%.*s\n", *bufsize, buf);
217
/* simpleUPnPcommand :
222
char * simpleUPnPcommand(int s, const char * url, const char * service,
223
const char * action, struct UPNParg * args,
228
buf = simpleUPnPcommand2(s, url, service, action, args, bufsize, "1.1");
230
buf = simpleUPnPcommand2(s, url, service, action, args, bufsize, "1.0");
231
if (!buf || *bufsize == 0)
234
printf("Error or no result from SOAP request; retrying with HTTP/1.1\n");
236
buf = simpleUPnPcommand2(s, url, service, action, args, bufsize, "1.1");
242
/* parseMSEARCHReply()
243
* the last 4 arguments are filled during the parsing :
244
* - location/locationsize : "location:" field of the SSDP reply packet
245
* - st/stsize : "st:" field of the SSDP reply packet.
246
* The strings are NOT null terminated */
248
parseMSEARCHReply(const char * reply, int size,
249
const char * * location, int * locationsize,
250
const char * * st, int * stsize)
254
a = i; /* start of the line */
255
b = 0; /* end of the "header" (position of the colon) */
263
b = i; /* end of the "header" */
275
/*for(j=b+1; j<i; j++)
280
/* skip the colon and white spaces */
281
do { b++; } while(reply[b]==' ');
282
if(0==strncasecmp(reply+a, "location", 8))
287
else if(0==strncasecmp(reply+a, "st", 2))
303
/* port upnp discover : SSDP protocol */
305
#define XSTR(s) STR(s)
307
#define UPNP_MCAST_ADDR "239.255.255.250"
309
#define UPNP_MCAST_LL_ADDR "FF02::C" /* link-local */
310
#define UPNP_MCAST_SL_ADDR "FF05::C" /* site-local */
313
* return a chained list of all devices found or NULL if
314
* no devices was found.
315
* It is up to the caller to free the chained list
316
* delay is in millisecond (poll) */
317
LIBSPEC struct UPNPDev *
318
upnpDiscover(int delay, const char * multicastif,
319
const char * minissdpdsock, int sameport,
323
struct UPNPDev * tmp;
324
struct UPNPDev * devlist = 0;
326
static const char MSearchMsgFmt[] =
327
"M-SEARCH * HTTP/1.1\r\n"
328
"HOST: %s:" XSTR(PORT) "\r\n"
330
"MAN: \"ssdp:discover\"\r\n"
333
static const char * const deviceList[] = {
335
"urn:schemas-upnp-org:device:InternetGatewayDevice:2",
336
"urn:schemas-upnp-org:service:WANIPConnection:2",
338
"urn:schemas-upnp-org:device:InternetGatewayDevice:1",
339
"urn:schemas-upnp-org:service:WANIPConnection:1",
340
"urn:schemas-upnp-org:service:WANPPPConnection:1",
345
char bufr[1536]; /* reception and emission buffer */
348
struct sockaddr_storage sockudp_r;
350
#ifdef NO_GETADDRINFO
351
struct sockaddr_storage sockudp_w;
354
struct addrinfo hints, *servinfo, *p;
357
MIB_IPFORWARDROW ip_forward;
362
*error = UPNPDISCOVER_UNKNOWN_ERROR;
363
#if !defined(WIN32) && !defined(__amigaos__) && !defined(__amigaos4__)
364
/* first try to get infos from minissdpd ! */
366
minissdpdsock = "/var/run/minissdpd.sock";
367
while(!devlist && deviceList[deviceIndex]) {
368
devlist = getDevicesFromMiniSSDPD(deviceList[deviceIndex],
370
/* We return what we have found if it was not only a rootdevice */
371
if(devlist && !strstr(deviceList[deviceIndex], "rootdevice")) {
373
*error = UPNPDISCOVER_SUCCESS;
380
/* fallback to direct discovery */
382
sudp = socket(ipv6 ? PF_INET6 : PF_INET, SOCK_DGRAM, IPPROTO_UDP);
384
sudp = socket(ipv6 ? PF_INET6 : PF_INET, SOCK_DGRAM, 0);
389
*error = UPNPDISCOVER_SOCKET_ERROR;
390
PRINT_SOCKET_ERROR("socket");
394
memset(&sockudp_r, 0, sizeof(struct sockaddr_storage));
396
struct sockaddr_in6 * p = (struct sockaddr_in6 *)&sockudp_r;
397
p->sin6_family = AF_INET6;
399
p->sin6_port = htons(PORT);
400
p->sin6_addr = in6addr_any; /* in6addr_any is not available with MinGW32 3.4.2 */
402
struct sockaddr_in * p = (struct sockaddr_in *)&sockudp_r;
403
p->sin_family = AF_INET;
405
p->sin_port = htons(PORT);
406
p->sin_addr.s_addr = INADDR_ANY;
409
/* This code could help us to use the right Network interface for
410
* SSDP multicast traffic */
411
/* Get IP associated with the index given in the ip_forward struct
412
* in order to give this ip to setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF) */
414
&& (GetBestRoute(inet_addr("223.255.255.255"), 0, &ip_forward) == NO_ERROR)) {
416
PMIB_IPADDRTABLE pIPAddrTable;
423
printf("ifIndex=%lu nextHop=%lx \n", ip_forward.dwForwardIfIndex, ip_forward.dwForwardNextHop);
425
pIPAddrTable = (MIB_IPADDRTABLE *) malloc(sizeof (MIB_IPADDRTABLE));
426
if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
428
pIPAddrTable = (MIB_IPADDRTABLE *) malloc(dwSize);
431
dwRetVal = GetIpAddrTable( pIPAddrTable, &dwSize, 0 );
433
printf("\tNum Entries: %ld\n", pIPAddrTable->dwNumEntries);
435
for (i=0; i < (int) pIPAddrTable->dwNumEntries; i++) {
437
printf("\n\tInterface Index[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwIndex);
438
IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwAddr;
439
printf("\tIP Address[%d]: \t%s\n", i, inet_ntoa(IPAddr) );
440
IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwMask;
441
printf("\tSubnet Mask[%d]: \t%s\n", i, inet_ntoa(IPAddr) );
442
IPAddr.S_un.S_addr = (u_long) pIPAddrTable->table[i].dwBCastAddr;
443
printf("\tBroadCast[%d]: \t%s (%ld)\n", i, inet_ntoa(IPAddr), pIPAddrTable->table[i].dwBCastAddr);
444
printf("\tReassembly size[%d]:\t%ld\n", i, pIPAddrTable->table[i].dwReasmSize);
445
printf("\tType and State[%d]:", i);
448
if (pIPAddrTable->table[i].dwIndex == ip_forward.dwForwardIfIndex) {
449
/* Set the address of this interface to be used */
450
struct in_addr mc_if;
451
memset(&mc_if, 0, sizeof(mc_if));
452
mc_if.s_addr = pIPAddrTable->table[i].dwAddr;
453
if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF, (const char *)&mc_if, sizeof(mc_if)) < 0) {
454
PRINT_SOCKET_ERROR("setsockopt");
456
((struct sockaddr_in *)&sockudp_r)->sin_addr.s_addr = pIPAddrTable->table[i].dwAddr;
469
if (setsockopt(sudp, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof (opt)) < 0)
471
if (setsockopt(sudp, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt)) < 0)
475
*error = UPNPDISCOVER_SOCKET_ERROR;
476
PRINT_SOCKET_ERROR("setsockopt");
484
/* according to MSDN, if_nametoindex() is supported since
485
* MS Windows Vista and MS Windows Server 2008.
486
* http://msdn.microsoft.com/en-us/library/bb408409%28v=vs.85%29.aspx */
487
unsigned int ifindex = if_nametoindex(multicastif); /* eth0, etc. */
488
if(setsockopt(sudp, IPPROTO_IPV6, IPV6_MULTICAST_IF, &ifindex, sizeof(&ifindex)) < 0)
490
PRINT_SOCKET_ERROR("setsockopt");
494
printf("Setting of multicast interface not supported in IPv6 under Windows.\n");
498
struct in_addr mc_if;
499
mc_if.s_addr = inet_addr(multicastif); /* ex: 192.168.x.x */
500
((struct sockaddr_in *)&sockudp_r)->sin_addr.s_addr = mc_if.s_addr;
501
if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF, (const char *)&mc_if, sizeof(mc_if)) < 0)
503
PRINT_SOCKET_ERROR("setsockopt");
508
/* Avant d'envoyer le paquet on bind pour recevoir la reponse */
509
if (bind(sudp, (const struct sockaddr *)&sockudp_r,
510
ipv6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)) != 0)
513
*error = UPNPDISCOVER_SOCKET_ERROR;
514
PRINT_SOCKET_ERROR("bind");
520
*error = UPNPDISCOVER_SUCCESS;
521
/* Calculating maximum response time in seconds */
522
mx = ((unsigned int)delay) / 1000u;
523
/* receiving SSDP response packet */
524
for(n = 0; deviceList[deviceIndex]; deviceIndex++)
528
/* sending the SSDP M-SEARCH packet */
529
n = snprintf(bufr, sizeof(bufr),
532
(linklocal ? "[" UPNP_MCAST_LL_ADDR "]" : "[" UPNP_MCAST_SL_ADDR "]")
534
deviceList[deviceIndex], mx);
536
printf("Sending %s", bufr);
538
#ifdef NO_GETADDRINFO
539
/* the following code is not using getaddrinfo */
541
memset(&sockudp_w, 0, sizeof(struct sockaddr_storage));
543
struct sockaddr_in6 * p = (struct sockaddr_in6 *)&sockudp_w;
544
p->sin6_family = AF_INET6;
545
p->sin6_port = htons(PORT);
547
linklocal ? UPNP_MCAST_LL_ADDR : UPNP_MCAST_SL_ADDR,
550
struct sockaddr_in * p = (struct sockaddr_in *)&sockudp_w;
551
p->sin_family = AF_INET;
552
p->sin_port = htons(PORT);
553
p->sin_addr.s_addr = inet_addr(UPNP_MCAST_ADDR);
555
n = sendto(sudp, bufr, n, 0,
557
ipv6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in));
560
*error = UPNPDISCOVER_SOCKET_ERROR;
561
PRINT_SOCKET_ERROR("sendto");
564
#else /* #ifdef NO_GETADDRINFO */
565
memset(&hints, 0, sizeof(hints));
566
hints.ai_family = AF_UNSPEC; // AF_INET6 or AF_INET
567
hints.ai_socktype = SOCK_DGRAM;
568
/*hints.ai_flags = */
569
if ((rv = getaddrinfo(ipv6
570
? (linklocal ? UPNP_MCAST_LL_ADDR : UPNP_MCAST_SL_ADDR)
572
XSTR(PORT), &hints, &servinfo)) != 0) {
574
*error = UPNPDISCOVER_SOCKET_ERROR;
576
fprintf(stderr, "getaddrinfo() failed: %d\n", rv);
578
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
582
for(p = servinfo; p; p = p->ai_next) {
583
n = sendto(sudp, bufr, n, 0, p->ai_addr, p->ai_addrlen);
585
PRINT_SOCKET_ERROR("sendto");
589
freeaddrinfo(servinfo);
592
*error = UPNPDISCOVER_SOCKET_ERROR;
595
#endif /* #ifdef NO_GETADDRINFO */
597
/* Waiting for SSDP REPLY packet to M-SEARCH */
598
n = receivedata(sudp, bufr, sizeof(bufr), delay);
602
*error = UPNPDISCOVER_SOCKET_ERROR;
605
/* no data or Time Out */
607
/* no more device type to look for... */
609
*error = UPNPDISCOVER_SUCCESS;
621
const char * descURL=NULL;
623
const char * st=NULL;
625
/*printf("%d byte(s) :\n%s\n", n, bufr);*/ /* affichage du message */
626
parseMSEARCHReply(bufr, n, &descURL, &urlsize, &st, &stsize);
630
printf("M-SEARCH Reply:\nST: %.*s\nLocation: %.*s\n",
631
stsize, st, urlsize, descURL);
633
for(tmp=devlist; tmp; tmp = tmp->pNext) {
634
if(memcmp(tmp->descURL, descURL, urlsize) == 0 &&
635
tmp->descURL[urlsize] == '\0' &&
636
memcmp(tmp->st, st, stsize) == 0 &&
637
tmp->st[stsize] == '\0')
640
/* at the exit of the loop above, tmp is null if
641
* no duplicate device was found */
644
tmp = (struct UPNPDev *)malloc(sizeof(struct UPNPDev)+urlsize+stsize);
646
/* memory allocation error */
648
*error = UPNPDISCOVER_MEMORY_ERROR;
651
tmp->pNext = devlist;
652
tmp->descURL = tmp->buffer;
653
tmp->st = tmp->buffer + 1 + urlsize;
654
memcpy(tmp->buffer, descURL, urlsize);
655
tmp->buffer[urlsize] = '\0';
656
memcpy(tmp->buffer + urlsize + 1, st, stsize);
657
tmp->buffer[urlsize+1+stsize] = '\0';
666
/* freeUPNPDevlist() should be used to
667
* free the chained list returned by upnpDiscover() */
668
LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist)
670
struct UPNPDev * next;
673
next = devlist->pNext;
680
url_cpy_or_cat(char * dst, const char * src, int n)
690
strncpy(dst, src, n);
698
strncpy(dst + l, src, n - l);
702
/* Prepare the Urls for usage...
704
LIBSPEC void GetUPNPUrls(struct UPNPUrls * urls, struct IGDdatas * data,
705
const char * descURL)
709
n1 = strlen(data->urlbase);
711
n1 = strlen(descURL);
712
n1 += 2; /* 1 byte more for Null terminator, 1 byte for '/' if needed */
713
n2 = n1; n3 = n1; n4 = n1;
714
n1 += strlen(data->first.scpdurl);
715
n2 += strlen(data->first.controlurl);
716
n3 += strlen(data->CIF.controlurl);
717
n4 += strlen(data->IPv6FC.controlurl);
719
urls->ipcondescURL = (char *)malloc(n1);
720
urls->controlURL = (char *)malloc(n2);
721
urls->controlURL_CIF = (char *)malloc(n3);
722
urls->controlURL_6FC = (char *)malloc(n4);
723
/* maintenant on chope la desc du WANIPConnection */
724
if(data->urlbase[0] != '\0')
725
strncpy(urls->ipcondescURL, data->urlbase, n1);
727
strncpy(urls->ipcondescURL, descURL, n1);
728
p = strchr(urls->ipcondescURL+7, '/');
730
strncpy(urls->controlURL, urls->ipcondescURL, n2);
731
strncpy(urls->controlURL_CIF, urls->ipcondescURL, n3);
732
strncpy(urls->controlURL_6FC, urls->ipcondescURL, n4);
734
url_cpy_or_cat(urls->ipcondescURL, data->first.scpdurl, n1);
736
url_cpy_or_cat(urls->controlURL, data->first.controlurl, n2);
738
url_cpy_or_cat(urls->controlURL_CIF, data->CIF.controlurl, n3);
740
url_cpy_or_cat(urls->controlURL_6FC, data->IPv6FC.controlurl, n4);
743
printf("urls->ipcondescURL='%s' %u n1=%d\n", urls->ipcondescURL,
744
(unsigned)strlen(urls->ipcondescURL), n1);
745
printf("urls->controlURL='%s' %u n2=%d\n", urls->controlURL,
746
(unsigned)strlen(urls->controlURL), n2);
747
printf("urls->controlURL_CIF='%s' %u n3=%d\n", urls->controlURL_CIF,
748
(unsigned)strlen(urls->controlURL_CIF), n3);
749
printf("urls->controlURL_6FC='%s' %u n4=%d\n", urls->controlURL_6FC,
750
(unsigned)strlen(urls->controlURL_6FC), n4);
755
FreeUPNPUrls(struct UPNPUrls * urls)
759
free(urls->controlURL);
760
urls->controlURL = 0;
761
free(urls->ipcondescURL);
762
urls->ipcondescURL = 0;
763
free(urls->controlURL_CIF);
764
urls->controlURL_CIF = 0;
765
free(urls->controlURL_6FC);
766
urls->controlURL_6FC = 0;
770
UPNPIGD_IsConnected(struct UPNPUrls * urls, struct IGDdatas * data)
775
UPNP_GetStatusInfo(urls->controlURL, data->first.servicetype,
776
status, &uptime, NULL);
777
if(0 == strcmp("Connected", status))
786
/* UPNP_GetValidIGD() :
789
* 1 = A valid connected IGD has been found
790
* 2 = A valid IGD has been found but it reported as
792
* 3 = an UPnP device has been found but was not recognized as an IGD
794
* In any non zero return case, the urls and data structures
795
* passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to
796
* free allocated memory.
799
UPNP_GetValidIGD(struct UPNPDev * devlist,
800
struct UPNPUrls * urls,
801
struct IGDdatas * data,
802
char * lanaddr, int lanaddrlen)
806
struct UPNPDev * dev;
808
int state; /* state 1 : IGD connected. State 2 : IGD. State 3 : anything */
812
printf("Empty devlist\n");
816
for(state = 1; state <= 3; state++)
818
for(dev = devlist; dev; dev = dev->pNext)
820
/* we should choose an internet gateway device.
821
* with st == urn:schemas-upnp-org:device:InternetGatewayDevice:1 */
822
descXML = miniwget_getaddr(dev->descURL, &descXMLsize,
823
lanaddr, lanaddrlen);
827
memset(data, 0, sizeof(struct IGDdatas));
828
memset(urls, 0, sizeof(struct UPNPUrls));
829
parserootdesc(descXML, descXMLsize, data);
832
if(0==strcmp(data->CIF.servicetype,
833
"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")
836
GetUPNPUrls(urls, data, dev->descURL);
839
printf("UPNPIGD_IsConnected(%s) = %d\n",
841
UPNPIGD_IsConnected(urls, data));
843
if((state >= 2) || UPNPIGD_IsConnected(urls, data))
846
if(data->second.servicetype[0] != '\0') {
848
printf("We tried %s, now we try %s !\n",
849
data->first.servicetype, data->second.servicetype);
851
/* swaping WANPPPConnection and WANIPConnection ! */
852
memcpy(&data->tmp, &data->first, sizeof(struct IGDdatas_service));
853
memcpy(&data->first, &data->second, sizeof(struct IGDdatas_service));
854
memcpy(&data->second, &data->tmp, sizeof(struct IGDdatas_service));
855
GetUPNPUrls(urls, data, dev->descURL);
857
printf("UPNPIGD_IsConnected(%s) = %d\n",
859
UPNPIGD_IsConnected(urls, data));
861
if((state >= 2) || UPNPIGD_IsConnected(urls, data))
866
memset(data, 0, sizeof(struct IGDdatas));
871
printf("error getting XML description %s\n", dev->descURL);
879
/* UPNP_GetIGDFromUrl()
880
* Used when skipping the discovery process.
885
UPNP_GetIGDFromUrl(const char * rootdescurl,
886
struct UPNPUrls * urls,
887
struct IGDdatas * data,
888
char * lanaddr, int lanaddrlen)
892
descXML = miniwget_getaddr(rootdescurl, &descXMLsize,
893
lanaddr, lanaddrlen);
895
memset(data, 0, sizeof(struct IGDdatas));
896
memset(urls, 0, sizeof(struct UPNPUrls));
897
parserootdesc(descXML, descXMLsize, data);
900
GetUPNPUrls(urls, data, rootdescurl);