diff --git a/miniupnpc/Changelog.txt b/miniupnpc/Changelog.txt index 6e5319c..e1a0f3f 100644 --- a/miniupnpc/Changelog.txt +++ b/miniupnpc/Changelog.txt @@ -3,6 +3,7 @@ miniUPnP client Changelog. 2012/06/23: More error return checks in upnpc.c + #define MINIUPNPC_GET_SRC_ADDR enables receivedata() to get scope_id increment API_VERSION to 9 2012/06/20: diff --git a/miniupnpc/Makefile b/miniupnpc/Makefile index 475369f..0305f3f 100644 --- a/miniupnpc/Makefile +++ b/miniupnpc/Makefile @@ -28,6 +28,7 @@ CFLAGS += -Wall CFLAGS += -W -Wstrict-prototypes CFLAGS += -fno-common CFLAGS += -DMINIUPNPC_SET_SOCKET_TIMEOUT +CFLAGS += -DMINIUPNPC_GET_SRC_ADDR CFLAGS += -D_BSD_SOURCE -D_POSIX_C_SOURCE=1 CFLAGS += -ansi # -DNO_GETADDRINFO diff --git a/miniupnpc/miniupnpc.c b/miniupnpc/miniupnpc.c index 15435ea..e2adb8a 100644 --- a/miniupnpc/miniupnpc.c +++ b/miniupnpc/miniupnpc.c @@ -327,6 +327,7 @@ upnpDiscover(int delay, const char * multicastif, { struct UPNPDev * tmp; struct UPNPDev * devlist = 0; + unsigned int scope_id = 0; int opt = 1; static const char MSearchMsgFmt[] = "M-SEARCH * HTTP/1.1\r\n" @@ -625,7 +626,7 @@ upnpDiscover(int delay, const char * multicastif, #endif /* #ifdef NO_GETADDRINFO */ } /* Waiting for SSDP REPLY packet to M-SEARCH */ - n = receivedata(sudp, bufr, sizeof(bufr), delay); + n = receivedata(sudp, bufr, sizeof(bufr), delay, &scope_id); if (n < 0) { /* error */ if(error) diff --git a/miniupnpc/miniwget.c b/miniupnpc/miniwget.c index 036379a..4f45d72 100644 --- a/miniupnpc/miniwget.c +++ b/miniupnpc/miniwget.c @@ -82,7 +82,7 @@ getHTTPResponse(int s, int * size) chunksize_buf[0] = '\0'; chunksize_buf_index = 0; - while((n = receivedata(s, buf, 2048, 5000)) > 0) + while((n = receivedata(s, buf, 2048, 5000, NULL)) > 0) { if(endofheaders == 0) { diff --git a/miniupnpc/receivedata.c b/miniupnpc/receivedata.c index 5b21779..f9b9901 100644 --- a/miniupnpc/receivedata.c +++ b/miniupnpc/receivedata.c @@ -1,4 +1,4 @@ -/* $Id: receivedata.c,v 1.2 2012/01/21 13:30:33 nanard Exp $ */ +/* $Id: receivedata.c,v 1.4 2012/06/23 22:34:47 nanard Exp $ */ /* Project : miniupnp * Website : http://miniupnp.free.fr/ * Author : Thomas Bernard @@ -18,6 +18,7 @@ #include #endif /* #else defined(__amigaos__) && !defined(__amigaos4__) */ #include +#include #if !defined(__amigaos__) && !defined(__amigaos4__) #include #endif @@ -34,8 +35,14 @@ #include "receivedata.h" int -receivedata(int socket, char * data, int length, int timeout) +receivedata(int socket, + char * data, int length, + int timeout, unsigned int * scope_id) { +#if MINIUPNPC_GET_SRC_ADDR + struct sockaddr_storage src_addr; + socklen_t src_addr_len = sizeof(src_addr); +#endif int n; #if !defined(_WIN32) && !defined(__amigaos__) && !defined(__amigaos4__) /* using poll */ @@ -72,10 +79,25 @@ receivedata(int socket, char * data, int length, int timeout) return 0; } #endif +#if MINIUPNPC_GET_SRC_ADDR + n = recvfrom(socket, data, length, 0, + (struct sockaddr *)&src_addr, &src_addr_len); +#else n = recv(socket, data, length, 0); +#endif if(n<0) { PRINT_SOCKET_ERROR("recv"); } +#if MINIUPNPC_GET_SRC_ADDR + if (src_addr.ss_family == AF_INET6) { + const struct sockaddr_in6 * src_addr6 = (struct sockaddr_in6 *)&src_addr; +#ifdef DEBUG + printf("scope_id=%u\n", src_addr6->sin6_scope_id); +#endif + if(scope_id) + *scope_id = src_addr6->sin6_scope_id; + } +#endif return n; } diff --git a/miniupnpc/receivedata.h b/miniupnpc/receivedata.h index fd1444b..35f531c 100644 --- a/miniupnpc/receivedata.h +++ b/miniupnpc/receivedata.h @@ -1,8 +1,8 @@ -/* $Id: receivedata.h,v 1.1 2011/04/11 08:21:47 nanard Exp $ */ +/* $Id: receivedata.h,v 1.3 2012/06/23 22:34:47 nanard Exp $ */ /* Project: miniupnp * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * Author: Thomas Bernard - * Copyright (c) 2011 Thomas Bernard + * Copyright (c) 2011-2012 Thomas Bernard * This software is subjects to the conditions detailed * in the LICENCE file provided within this distribution */ #ifndef __RECEIVEDATA_H__ @@ -11,7 +11,9 @@ /* Reads data from the specified socket. * Returns the number of bytes read if successful, zero if no bytes were * read or if we timed out. Returns negative if there was an error. */ -int receivedata(int socket, char * data, int length, int timeout); +int receivedata(int socket, + char * data, int length, + int timeout, unsigned int * scope_id); #endif