diff --git a/upnp/src/genlib/miniserver/miniserver.c b/upnp/src/genlib/miniserver/miniserver.c index ab84cc2..32f8e9b 100644 --- a/upnp/src/genlib/miniserver/miniserver.c +++ b/upnp/src/genlib/miniserver/miniserver.c @@ -2,6 +2,7 @@ * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. + * Copyright (C) 2012 France Telecom All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -512,6 +513,7 @@ static int get_miniserver_sockets( struct sockaddr_in6* serverAddr6 = (struct sockaddr_in6*)&__ss_v6; SOCKET listenfd6; uint16_t actual_port6; + int onOff; #endif int ret_code; int reuseaddr_on = 0; @@ -527,8 +529,17 @@ static int get_miniserver_sockets( #ifdef UPNP_ENABLE_IPV6 listenfd6 = socket(AF_INET6, SOCK_STREAM, 0); if (listenfd6 == INVALID_SOCKET) { + sock_close(listenfd4); return UPNP_E_OUTOF_SOCKET; } + onOff = 1; + sockError = setsockopt(listenfd6, IPPROTO_IPV6, IPV6_V6ONLY, + (char *)&onOff, sizeof(onOff)); + if (sockError == SOCKET_ERROR) { + sock_close(listenfd4); + sock_close(listenfd6); + return UPNP_E_SOCKET_BIND; + } #endif /* As per the IANA specifications for the use of ports by applications * override the listen port passed in with the first available. */ diff --git a/upnp/src/ssdp/ssdp_server.c b/upnp/src/ssdp/ssdp_server.c index 267e6d9..336b293 100644 --- a/upnp/src/ssdp/ssdp_server.c +++ b/upnp/src/ssdp/ssdp_server.c @@ -2,7 +2,7 @@ * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. - * Copyright (C) 2011 France Telecom All rights reserved. + * Copyright (C) 2011-2012 France Telecom All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -948,6 +948,19 @@ static int create_ssdp_sock_v6( return UPNP_E_SOCKET_ERROR; } #endif /* BSD, __OSX__, __APPLE__ */ + onOff = 1; + ret = setsockopt(*ssdpSock, IPPROTO_IPV6, IPV6_V6ONLY, + (char *)&onOff, sizeof(onOff)); + if (ret == -1) { + strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); + UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, + "Error in setsockopt() IPV6_V6ONLY: %s\n", + errorBuffer); + shutdown(*ssdpSock, SD_BOTH); + UpnpCloseSocket(*ssdpSock); + + return UPNP_E_SOCKET_ERROR; + } memset(&__ss, 0, sizeof(__ss)); ssdpAddr6->sin6_family = AF_INET6; ssdpAddr6->sin6_addr = in6addr_any; @@ -1049,6 +1062,19 @@ static int create_ssdp_sock_v6_ula_gua( return UPNP_E_SOCKET_ERROR; } #endif /* BSD, __OSX__, __APPLE__ */ + onOff = 1; + ret = setsockopt(*ssdpSock, IPPROTO_IPV6, IPV6_V6ONLY, + (char *)&onOff, sizeof(onOff)); + if (ret == -1) { + strerror_r(errno, errorBuffer, ERROR_BUFFER_LEN); + UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__, + "Error in setsockopt() IPV6_V6ONLY: %s\n", + errorBuffer); + shutdown(*ssdpSock, SD_BOTH); + UpnpCloseSocket(*ssdpSock); + + return UPNP_E_SOCKET_ERROR; + } memset(&__ss, 0, sizeof(__ss)); ssdpAddr6->sin6_family = AF_INET6; ssdpAddr6->sin6_addr = in6addr_any;