aboutsummaryrefslogtreecommitdiff
path: root/src/nat/miniupnp/miniupnpc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nat/miniupnp/miniupnpc.c')
-rw-r--r--src/nat/miniupnp/miniupnpc.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/nat/miniupnp/miniupnpc.c b/src/nat/miniupnp/miniupnpc.c
index 412c8ec25..34bae0ad8 100644
--- a/src/nat/miniupnp/miniupnpc.c
+++ b/src/nat/miniupnp/miniupnpc.c
@@ -238,6 +238,7 @@ simpleUPnPcommand (int s, const char *url, const char *service,
238 /* Test IPv4 address, else use IPv6 */ 238 /* Test IPv4 address, else use IPv6 */
239 if (inet_pton (AF_INET, hostname, &dest.sin_addr) == 1) 239 if (inet_pton (AF_INET, hostname, &dest.sin_addr) == 1)
240 { 240 {
241 memset (&dest, 0, sizeof (dest));
241 dest.sin_family = AF_INET; 242 dest.sin_family = AF_INET;
242 dest.sin_port = htons (port); 243 dest.sin_port = htons (port);
243#ifdef HAVE_SOCKADDR_IN_SIN_LEN 244#ifdef HAVE_SOCKADDR_IN_SIN_LEN
@@ -253,9 +254,9 @@ simpleUPnPcommand (int s, const char *url, const char *service,
253 } 254 }
254 else if (inet_pton (AF_INET6, hostname, &dest6.sin6_addr) == 1) 255 else if (inet_pton (AF_INET6, hostname, &dest6.sin6_addr) == 1)
255 { 256 {
257 memset (&dest6, 0, sizeof (dest6));
256 dest6.sin6_family = AF_INET6; 258 dest6.sin6_family = AF_INET6;
257 dest6.sin6_port = htons (port); 259 dest6.sin6_port = htons (port);
258 dest6.sin6_flowinfo = 0;
259#ifdef HAVE_SOCKADDR_IN_SIN_LEN 260#ifdef HAVE_SOCKADDR_IN_SIN_LEN
260 dest6.sin6_len = sizeof (dest6); 261 dest6.sin6_len = sizeof (dest6);
261#endif 262#endif
@@ -270,7 +271,9 @@ simpleUPnPcommand (int s, const char *url, const char *service,
270 else 271 else
271 { 272 {
272 PRINT_SOCKET_ERROR ("inet_pton"); 273 PRINT_SOCKET_ERROR ("inet_pton");
273 closesocket (s); 274 if (s > 0)
275 closesocket (s);
276
274 *bufsize = 0; 277 *bufsize = 0;
275 return -1; 278 return -1;
276 } 279 }
@@ -495,7 +498,11 @@ upnpDiscover (int delay, const char *multicastif,
495 memset (&sockudp6_w, 0, sizeof (struct sockaddr_in6)); 498 memset (&sockudp6_w, 0, sizeof (struct sockaddr_in6));
496 sockudp6_w.sin6_family = AF_INET6; 499 sockudp6_w.sin6_family = AF_INET6;
497 sockudp6_w.sin6_port = htons (PORT); 500 sockudp6_w.sin6_port = htons (PORT);
498 inet_pton (AF_INET6, UPNP_MCAST_ADDR6, &sockudp6_w.sin6_addr); 501 if (inet_pton (AF_INET6, UPNP_MCAST_ADDR6, &sockudp6_w.sin6_addr) != 1)
502 {
503 PRINT_SOCKET_ERROR ("inet_pton");
504 return NULL;
505 }
499#ifdef HAVE_SOCKADDR_IN_SIN_LEN 506#ifdef HAVE_SOCKADDR_IN_SIN_LEN
500 sockudp6_w.sin6_len = sizeof (struct sockaddr_in6); 507 sockudp6_w.sin6_len = sizeof (struct sockaddr_in6);
501#endif 508#endif
@@ -535,13 +542,17 @@ upnpDiscover (int delay, const char *multicastif,
535 } 542 }
536 else 543 else
537 { 544 {
538 if (multicastif && !(if_index = if_nametoindex (multicastif))) 545 if (multicastif)
539 PRINT_SOCKET_ERROR ("if_nametoindex");
540
541 if (setsockopt
542 (sudp, IPPROTO_IPV6, IPV6_MULTICAST_IF, &if_index, sizeof (if_index)) < 0)
543 { 546 {
544 PRINT_SOCKET_ERROR ("setsockopt"); 547 if_index = if_nametoindex (multicastif);
548 if (!if_index)
549 PRINT_SOCKET_ERROR ("if_nametoindex");
550
551 if (setsockopt
552 (sudp, IPPROTO_IPV6, IPV6_MULTICAST_IF, &if_index, sizeof (if_index)) < 0)
553 {
554 PRINT_SOCKET_ERROR ("setsockopt");
555 }
545 } 556 }
546 557
547 /* Bind to receive response before sending packet */ 558 /* Bind to receive response before sending packet */