miniwget.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /* $Id: miniwget.c,v 1.76 2016/12/16 08:54:04 nanard Exp $ */
  2. /* Project : miniupnp
  3. * Website : http://miniupnp.free.fr/
  4. * Author : Thomas Bernard
  5. * Copyright (c) 2005-2016 Thomas Bernard
  6. * This software is subject to the conditions detailed in the
  7. * LICENCE file provided in this distribution. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #ifdef _WIN32
  13. #include <winsock2.h>
  14. #include <ws2tcpip.h>
  15. #include <io.h>
  16. #define MAXHOSTNAMELEN 64
  17. #define snprintf _snprintf
  18. #define socklen_t int
  19. #ifndef strncasecmp
  20. #if defined(_MSC_VER) && (_MSC_VER >= 1400)
  21. #define strncasecmp _memicmp
  22. #else /* defined(_MSC_VER) && (_MSC_VER >= 1400) */
  23. #define strncasecmp memicmp
  24. #endif /* defined(_MSC_VER) && (_MSC_VER >= 1400) */
  25. #endif /* #ifndef strncasecmp */
  26. #else /* #ifdef _WIN32 */
  27. #include <unistd.h>
  28. #include <sys/param.h>
  29. #if defined(__amigaos__) && !defined(__amigaos4__)
  30. #define socklen_t int
  31. #else /* #if defined(__amigaos__) && !defined(__amigaos4__) */
  32. #include <sys/select.h>
  33. #endif /* #else defined(__amigaos__) && !defined(__amigaos4__) */
  34. #include <sys/socket.h>
  35. #include <netinet/in.h>
  36. #include <arpa/inet.h>
  37. #include <net/if.h>
  38. #include <netdb.h>
  39. #define closesocket close
  40. #include <strings.h>
  41. #endif /* #else _WIN32 */
  42. #ifdef __GNU__
  43. #define MAXHOSTNAMELEN 64
  44. #endif /* __GNU__ */
  45. #ifndef MIN
  46. #define MIN(x,y) (((x)<(y))?(x):(y))
  47. #endif /* MIN */
  48. #ifdef _WIN32
  49. #define OS_STRING "Win32"
  50. #define MINIUPNPC_VERSION_STRING "2.0"
  51. #define UPNP_VERSION_STRING "UPnP/1.1"
  52. #endif
  53. #ifdef __ANDROID__
  54. #define OS_STRING "Android"
  55. #define MINIUPNPC_VERSION_STRING "2.0"
  56. #define UPNP_VERSION_STRING "UPnP/1.1"
  57. #endif
  58. #include "miniwget.h"
  59. #include "connecthostport.h"
  60. #include "receivedata.h"
  61. #ifndef MAXHOSTNAMELEN
  62. #define MAXHOSTNAMELEN 64
  63. #endif
  64. /*
  65. * Read a HTTP response from a socket.
  66. * Process Content-Length and Transfer-encoding headers.
  67. * return a pointer to the content buffer, which length is saved
  68. * to the length parameter.
  69. */
  70. void *
  71. getHTTPResponse(int s, int * size, int * status_code)
  72. {
  73. char buf[2048];
  74. int n;
  75. int endofheaders = 0;
  76. int chunked = 0;
  77. int content_length = -1;
  78. unsigned int chunksize = 0;
  79. unsigned int bytestocopy = 0;
  80. /* buffers : */
  81. char * header_buf;
  82. unsigned int header_buf_len = 2048;
  83. unsigned int header_buf_used = 0;
  84. char * content_buf;
  85. unsigned int content_buf_len = 2048;
  86. unsigned int content_buf_used = 0;
  87. char chunksize_buf[32];
  88. unsigned int chunksize_buf_index;
  89. #ifdef DEBUG
  90. char * reason_phrase = NULL;
  91. int reason_phrase_len = 0;
  92. #endif
  93. if(status_code) *status_code = -1;
  94. header_buf = malloc(header_buf_len);
  95. if(header_buf == NULL)
  96. {
  97. #ifdef DEBUG
  98. fprintf(stderr, "%s: Memory allocation error\n", "getHTTPResponse");
  99. #endif /* DEBUG */
  100. *size = -1;
  101. return NULL;
  102. }
  103. content_buf = malloc(content_buf_len);
  104. if(content_buf == NULL)
  105. {
  106. free(header_buf);
  107. #ifdef DEBUG
  108. fprintf(stderr, "%s: Memory allocation error\n", "getHTTPResponse");
  109. #endif /* DEBUG */
  110. *size = -1;
  111. return NULL;
  112. }
  113. chunksize_buf[0] = '\0';
  114. chunksize_buf_index = 0;
  115. while((n = receivedata(s, buf, 2048, 5000, NULL)) > 0)
  116. {
  117. if(endofheaders == 0)
  118. {
  119. int i;
  120. int linestart=0;
  121. int colon=0;
  122. int valuestart=0;
  123. if(header_buf_used + n > header_buf_len) {
  124. char * tmp = realloc(header_buf, header_buf_used + n);
  125. if(tmp == NULL) {
  126. /* memory allocation error */
  127. free(header_buf);
  128. free(content_buf);
  129. *size = -1;
  130. return NULL;
  131. }
  132. header_buf = tmp;
  133. header_buf_len = header_buf_used + n;
  134. }
  135. memcpy(header_buf + header_buf_used, buf, n);
  136. header_buf_used += n;
  137. /* search for CR LF CR LF (end of headers)
  138. * recognize also LF LF */
  139. i = 0;
  140. while(i < ((int)header_buf_used-1) && (endofheaders == 0)) {
  141. if(header_buf[i] == '\r') {
  142. i++;
  143. if(header_buf[i] == '\n') {
  144. i++;
  145. if(i < (int)header_buf_used && header_buf[i] == '\r') {
  146. i++;
  147. if(i < (int)header_buf_used && header_buf[i] == '\n') {
  148. endofheaders = i+1;
  149. }
  150. }
  151. }
  152. } else if(header_buf[i] == '\n') {
  153. i++;
  154. if(header_buf[i] == '\n') {
  155. endofheaders = i+1;
  156. }
  157. }
  158. i++;
  159. }
  160. if(endofheaders == 0)
  161. continue;
  162. /* parse header lines */
  163. for(i = 0; i < endofheaders - 1; i++) {
  164. if(linestart > 0 && colon <= linestart && header_buf[i]==':')
  165. {
  166. colon = i;
  167. while(i < (endofheaders-1)
  168. && (header_buf[i+1] == ' ' || header_buf[i+1] == '\t'))
  169. i++;
  170. valuestart = i + 1;
  171. }
  172. /* detecting end of line */
  173. else if(header_buf[i]=='\r' || header_buf[i]=='\n')
  174. {
  175. if(linestart == 0 && status_code)
  176. {
  177. /* Status line
  178. * HTTP-Version SP Status-Code SP Reason-Phrase CRLF */
  179. int sp;
  180. for(sp = 0; sp < i; sp++)
  181. if(header_buf[sp] == ' ')
  182. {
  183. if(*status_code < 0)
  184. *status_code = atoi(header_buf + sp + 1);
  185. else
  186. {
  187. #ifdef DEBUG
  188. reason_phrase = header_buf + sp + 1;
  189. reason_phrase_len = i - sp - 1;
  190. #endif
  191. break;
  192. }
  193. }
  194. #ifdef DEBUG
  195. printf("HTTP status code = %d, Reason phrase = %.*s\n",
  196. *status_code, reason_phrase_len, reason_phrase);
  197. #endif
  198. }
  199. else if(colon > linestart && valuestart > colon)
  200. {
  201. #ifdef DEBUG
  202. printf("header='%.*s', value='%.*s'\n",
  203. colon-linestart, header_buf+linestart,
  204. i-valuestart, header_buf+valuestart);
  205. #endif
  206. if(0==strncasecmp(header_buf+linestart, "content-length", colon-linestart))
  207. {
  208. content_length = atoi(header_buf+valuestart);
  209. #ifdef DEBUG
  210. printf("Content-Length: %d\n", content_length);
  211. #endif
  212. }
  213. else if(0==strncasecmp(header_buf+linestart, "transfer-encoding", colon-linestart)
  214. && 0==strncasecmp(header_buf+valuestart, "chunked", 7))
  215. {
  216. #ifdef DEBUG
  217. printf("chunked transfer-encoding!\n");
  218. #endif
  219. chunked = 1;
  220. }
  221. }
  222. while((i < (int)header_buf_used) && (header_buf[i]=='\r' || header_buf[i] == '\n'))
  223. i++;
  224. linestart = i;
  225. colon = linestart;
  226. valuestart = 0;
  227. }
  228. }
  229. /* copy the remaining of the received data back to buf */
  230. n = header_buf_used - endofheaders;
  231. memcpy(buf, header_buf + endofheaders, n);
  232. /* if(headers) */
  233. }
  234. if(endofheaders)
  235. {
  236. /* content */
  237. if(chunked)
  238. {
  239. int i = 0;
  240. while(i < n)
  241. {
  242. if(chunksize == 0)
  243. {
  244. /* reading chunk size */
  245. if(chunksize_buf_index == 0) {
  246. /* skipping any leading CR LF */
  247. if(i<n && buf[i] == '\r') i++;
  248. if(i<n && buf[i] == '\n') i++;
  249. }
  250. while(i<n && isxdigit(buf[i])
  251. && chunksize_buf_index < (sizeof(chunksize_buf)-1))
  252. {
  253. chunksize_buf[chunksize_buf_index++] = buf[i];
  254. chunksize_buf[chunksize_buf_index] = '\0';
  255. i++;
  256. }
  257. while(i<n && buf[i] != '\r' && buf[i] != '\n')
  258. i++; /* discarding chunk-extension */
  259. if(i<n && buf[i] == '\r') i++;
  260. if(i<n && buf[i] == '\n') {
  261. unsigned int j;
  262. for(j = 0; j < chunksize_buf_index; j++) {
  263. if(chunksize_buf[j] >= '0'
  264. && chunksize_buf[j] <= '9')
  265. chunksize = (chunksize << 4) + (chunksize_buf[j] - '0');
  266. else
  267. chunksize = (chunksize << 4) + ((chunksize_buf[j] | 32) - 'a' + 10);
  268. }
  269. chunksize_buf[0] = '\0';
  270. chunksize_buf_index = 0;
  271. i++;
  272. } else {
  273. /* not finished to get chunksize */
  274. continue;
  275. }
  276. #ifdef DEBUG
  277. printf("chunksize = %u (%x)\n", chunksize, chunksize);
  278. #endif
  279. if(chunksize == 0)
  280. {
  281. #ifdef DEBUG
  282. printf("end of HTTP content - %d %d\n", i, n);
  283. /*printf("'%.*s'\n", n-i, buf+i);*/
  284. #endif
  285. goto end_of_stream;
  286. }
  287. }
  288. bytestocopy = ((int)chunksize < (n - i))?chunksize:(unsigned int)(n - i);
  289. if((content_buf_used + bytestocopy) > content_buf_len)
  290. {
  291. char * tmp;
  292. if(content_length >= (int)(content_buf_used + bytestocopy)) {
  293. content_buf_len = content_length;
  294. } else {
  295. content_buf_len = content_buf_used + bytestocopy;
  296. }
  297. tmp = realloc(content_buf, content_buf_len);
  298. if(tmp == NULL) {
  299. /* memory allocation error */
  300. free(content_buf);
  301. free(header_buf);
  302. *size = -1;
  303. return NULL;
  304. }
  305. content_buf = tmp;
  306. }
  307. memcpy(content_buf + content_buf_used, buf + i, bytestocopy);
  308. content_buf_used += bytestocopy;
  309. i += bytestocopy;
  310. chunksize -= bytestocopy;
  311. }
  312. }
  313. else
  314. {
  315. /* not chunked */
  316. if(content_length > 0
  317. && (int)(content_buf_used + n) > content_length) {
  318. /* skipping additional bytes */
  319. n = content_length - content_buf_used;
  320. }
  321. if(content_buf_used + n > content_buf_len)
  322. {
  323. char * tmp;
  324. if(content_length >= (int)(content_buf_used + n)) {
  325. content_buf_len = content_length;
  326. } else {
  327. content_buf_len = content_buf_used + n;
  328. }
  329. tmp = realloc(content_buf, content_buf_len);
  330. if(tmp == NULL) {
  331. /* memory allocation error */
  332. free(content_buf);
  333. free(header_buf);
  334. *size = -1;
  335. return NULL;
  336. }
  337. content_buf = tmp;
  338. }
  339. memcpy(content_buf + content_buf_used, buf, n);
  340. content_buf_used += n;
  341. }
  342. }
  343. /* use the Content-Length header value if available */
  344. if(content_length > 0 && (int)content_buf_used >= content_length)
  345. {
  346. #ifdef DEBUG
  347. printf("End of HTTP content\n");
  348. #endif
  349. break;
  350. }
  351. }
  352. end_of_stream:
  353. free(header_buf); header_buf = NULL;
  354. *size = content_buf_used;
  355. if(content_buf_used == 0)
  356. {
  357. free(content_buf);
  358. content_buf = NULL;
  359. }
  360. return content_buf;
  361. }
  362. /* miniwget3() :
  363. * do all the work.
  364. * Return NULL if something failed. */
  365. static void *
  366. miniwget3(const char * host,
  367. unsigned short port, const char * path,
  368. int * size, char * addr_str, int addr_str_len,
  369. const char * httpversion, unsigned int scope_id,
  370. int * status_code)
  371. {
  372. char buf[2048];
  373. int s;
  374. int n;
  375. int len;
  376. int sent;
  377. void * content;
  378. *size = 0;
  379. s = connecthostport(host, port, scope_id);
  380. if(s < 0)
  381. return NULL;
  382. /* get address for caller ! */
  383. if(addr_str)
  384. {
  385. struct sockaddr_storage saddr;
  386. socklen_t saddrlen;
  387. saddrlen = sizeof(saddr);
  388. if(getsockname(s, (struct sockaddr *)&saddr, &saddrlen) < 0)
  389. {
  390. perror("getsockname");
  391. }
  392. else
  393. {
  394. #if defined(__amigaos__) && !defined(__amigaos4__)
  395. /* using INT WINAPI WSAAddressToStringA(LPSOCKADDR, DWORD, LPWSAPROTOCOL_INFOA, LPSTR, LPDWORD);
  396. * But his function make a string with the port : nn.nn.nn.nn:port */
  397. /* if(WSAAddressToStringA((SOCKADDR *)&saddr, sizeof(saddr),
  398. NULL, addr_str, (DWORD *)&addr_str_len))
  399. {
  400. printf("WSAAddressToStringA() failed : %d\n", WSAGetLastError());
  401. }*/
  402. /* the following code is only compatible with ip v4 addresses */
  403. strncpy(addr_str, inet_ntoa(((struct sockaddr_in *)&saddr)->sin_addr), addr_str_len);
  404. #else
  405. #if 0
  406. if(saddr.sa_family == AF_INET6) {
  407. inet_ntop(AF_INET6,
  408. &(((struct sockaddr_in6 *)&saddr)->sin6_addr),
  409. addr_str, addr_str_len);
  410. } else {
  411. inet_ntop(AF_INET,
  412. &(((struct sockaddr_in *)&saddr)->sin_addr),
  413. addr_str, addr_str_len);
  414. }
  415. #endif
  416. /* getnameinfo return ip v6 address with the scope identifier
  417. * such as : 2a01:e35:8b2b:7330::%4281128194 */
  418. n = getnameinfo((const struct sockaddr *)&saddr, saddrlen,
  419. addr_str, addr_str_len,
  420. NULL, 0,
  421. NI_NUMERICHOST | NI_NUMERICSERV);
  422. if(n != 0) {
  423. #ifdef _WIN32
  424. fprintf(stderr, "getnameinfo() failed : %d\n", n);
  425. #else
  426. fprintf(stderr, "getnameinfo() failed : %s\n", gai_strerror(n));
  427. #endif
  428. }
  429. #endif
  430. }
  431. #ifdef DEBUG
  432. printf("address miniwget : %s\n", addr_str);
  433. #endif
  434. }
  435. len = snprintf(buf, sizeof(buf),
  436. "GET %s HTTP/%s\r\n"
  437. "Host: %s:%d\r\n"
  438. "Connection: Close\r\n"
  439. "User-Agent: " OS_STRING ", " UPNP_VERSION_STRING ", MiniUPnPc/" MINIUPNPC_VERSION_STRING "\r\n"
  440. "\r\n",
  441. path, httpversion, host, port);
  442. if ((unsigned int)len >= sizeof(buf))
  443. {
  444. closesocket(s);
  445. return NULL;
  446. }
  447. sent = 0;
  448. /* sending the HTTP request */
  449. while(sent < len)
  450. {
  451. n = send(s, buf+sent, len-sent, 0);
  452. if(n < 0)
  453. {
  454. perror("send");
  455. closesocket(s);
  456. return NULL;
  457. }
  458. else
  459. {
  460. sent += n;
  461. }
  462. }
  463. content = getHTTPResponse(s, size, status_code);
  464. closesocket(s);
  465. return content;
  466. }
  467. /* miniwget2() :
  468. * Call miniwget3(); retry with HTTP/1.1 if 1.0 fails. */
  469. static void *
  470. miniwget2(const char * host,
  471. unsigned short port, const char * path,
  472. int * size, char * addr_str, int addr_str_len,
  473. unsigned int scope_id, int * status_code)
  474. {
  475. char * respbuffer;
  476. #if 1
  477. respbuffer = miniwget3(host, port, path, size,
  478. addr_str, addr_str_len, "1.1",
  479. scope_id, status_code);
  480. #else
  481. respbuffer = miniwget3(host, port, path, size,
  482. addr_str, addr_str_len, "1.0",
  483. scope_id, status_code);
  484. if (*size == 0)
  485. {
  486. #ifdef DEBUG
  487. printf("Retrying with HTTP/1.1\n");
  488. #endif
  489. free(respbuffer);
  490. respbuffer = miniwget3(host, port, path, size,
  491. addr_str, addr_str_len, "1.1",
  492. scope_id, status_code);
  493. }
  494. #endif
  495. return respbuffer;
  496. }
  497. /* parseURL()
  498. * arguments :
  499. * url : source string not modified
  500. * hostname : hostname destination string (size of MAXHOSTNAMELEN+1)
  501. * port : port (destination)
  502. * path : pointer to the path part of the URL
  503. *
  504. * Return values :
  505. * 0 - Failure
  506. * 1 - Success */
  507. int
  508. parseURL(const char * url,
  509. char * hostname, unsigned short * port,
  510. char * * path, unsigned int * scope_id)
  511. {
  512. char * p1, *p2, *p3;
  513. if(!url)
  514. return 0;
  515. p1 = strstr(url, "://");
  516. if(!p1)
  517. return 0;
  518. p1 += 3;
  519. if( (url[0]!='h') || (url[1]!='t')
  520. ||(url[2]!='t') || (url[3]!='p'))
  521. return 0;
  522. memset(hostname, 0, MAXHOSTNAMELEN + 1);
  523. if(*p1 == '[')
  524. {
  525. /* IP v6 : http://[2a00:1450:8002::6a]/path/abc */
  526. char * scope;
  527. scope = strchr(p1, '%');
  528. p2 = strchr(p1, ']');
  529. if(p2 && scope && scope < p2 && scope_id) {
  530. /* parse scope */
  531. #ifdef IF_NAMESIZE
  532. char tmp[IF_NAMESIZE];
  533. int l;
  534. scope++;
  535. /* "%25" is just '%' in URL encoding */
  536. if(scope[0] == '2' && scope[1] == '5')
  537. scope += 2; /* skip "25" */
  538. l = p2 - scope;
  539. if(l >= IF_NAMESIZE)
  540. l = IF_NAMESIZE - 1;
  541. memcpy(tmp, scope, l);
  542. tmp[l] = '\0';
  543. *scope_id = if_nametoindex(tmp);
  544. if(*scope_id == 0) {
  545. *scope_id = (unsigned int)strtoul(tmp, NULL, 10);
  546. }
  547. #else
  548. /* under windows, scope is numerical */
  549. char tmp[8];
  550. int l;
  551. scope++;
  552. /* "%25" is just '%' in URL encoding */
  553. if(scope[0] == '2' && scope[1] == '5')
  554. scope += 2; /* skip "25" */
  555. l = p2 - scope;
  556. if(l >= sizeof(tmp))
  557. l = sizeof(tmp) - 1;
  558. memcpy(tmp, scope, l);
  559. tmp[l] = '\0';
  560. *scope_id = (unsigned int)strtoul(tmp, NULL, 10);
  561. #endif
  562. }
  563. p3 = strchr(p1, '/');
  564. if(p2 && p3)
  565. {
  566. p2++;
  567. strncpy(hostname, p1, MIN(MAXHOSTNAMELEN, (int)(p2-p1)));
  568. if(*p2 == ':')
  569. {
  570. *port = 0;
  571. p2++;
  572. while( (*p2 >= '0') && (*p2 <= '9'))
  573. {
  574. *port *= 10;
  575. *port += (unsigned short)(*p2 - '0');
  576. p2++;
  577. }
  578. }
  579. else
  580. {
  581. *port = 80;
  582. }
  583. *path = p3;
  584. return 1;
  585. }
  586. }
  587. p2 = strchr(p1, ':');
  588. p3 = strchr(p1, '/');
  589. if(!p3)
  590. return 0;
  591. if(!p2 || (p2>p3))
  592. {
  593. strncpy(hostname, p1, MIN(MAXHOSTNAMELEN, (int)(p3-p1)));
  594. *port = 80;
  595. }
  596. else
  597. {
  598. strncpy(hostname, p1, MIN(MAXHOSTNAMELEN, (int)(p2-p1)));
  599. *port = 0;
  600. p2++;
  601. while( (*p2 >= '0') && (*p2 <= '9'))
  602. {
  603. *port *= 10;
  604. *port += (unsigned short)(*p2 - '0');
  605. p2++;
  606. }
  607. }
  608. *path = p3;
  609. return 1;
  610. }
  611. void *
  612. miniwget(const char * url, int * size,
  613. unsigned int scope_id, int * status_code)
  614. {
  615. unsigned short port;
  616. char * path;
  617. /* protocol://host:port/chemin */
  618. char hostname[MAXHOSTNAMELEN+1];
  619. *size = 0;
  620. if(!parseURL(url, hostname, &port, &path, &scope_id))
  621. return NULL;
  622. #ifdef DEBUG
  623. printf("parsed url : hostname='%s' port=%hu path='%s' scope_id=%u\n",
  624. hostname, port, path, scope_id);
  625. #endif
  626. return miniwget2(hostname, port, path, size, 0, 0, scope_id, status_code);
  627. }
  628. void *
  629. miniwget_getaddr(const char * url, int * size,
  630. char * addr, int addrlen, unsigned int scope_id,
  631. int * status_code)
  632. {
  633. unsigned short port;
  634. char * path;
  635. /* protocol://host:port/path */
  636. char hostname[MAXHOSTNAMELEN+1];
  637. *size = 0;
  638. if(addr)
  639. addr[0] = '\0';
  640. if(!parseURL(url, hostname, &port, &path, &scope_id))
  641. return NULL;
  642. #ifdef DEBUG
  643. printf("parsed url : hostname='%s' port=%hu path='%s' scope_id=%u\n",
  644. hostname, port, path, scope_id);
  645. #endif
  646. return miniwget2(hostname, port, path, size, addr, addrlen, scope_id, status_code);
  647. }