miniupnpd: add missing patch from previous commit
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 14 Jan 2013 15:20:49 +0000 (15:20 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 14 Jan 2013 15:20:49 +0000 (15:20 +0000)
SVN-Revision: 35150

net/miniupnpd/patches/100-gracefully-handle-missing-ipv6.patch [new file with mode: 0644]

diff --git a/net/miniupnpd/patches/100-gracefully-handle-missing-ipv6.patch b/net/miniupnpd/patches/100-gracefully-handle-missing-ipv6.patch
new file mode 100644 (file)
index 0000000..1e027d9
--- /dev/null
@@ -0,0 +1,120 @@
+--- a/miniupnpd.c
++++ b/miniupnpd.c
+@@ -106,25 +106,20 @@ volatile sig_atomic_t should_send_public
+ /* OpenAndConfHTTPSocket() :
+  * setup the socket used to handle incoming HTTP connections. */
+ static int
+-OpenAndConfHTTPSocket(unsigned short port)
++OpenAndConfHTTPSocket(unsigned short port, int family)
+ {
+       int s;
+       int i = 1;
+-#ifdef ENABLE_IPV6
+-      struct sockaddr_in6 listenname;
+-#else
+-      struct sockaddr_in listenname;
+-#endif
++      struct sockaddr_storage listenname;
++      struct sockaddr_in *ln4 = (struct sockaddr_in *)&listenname;
++      struct sockaddr_in6 *ln6 = (struct sockaddr_in6 *)&listenname;
+       socklen_t listenname_len;
+-      if( (s = socket(
+-#ifdef ENABLE_IPV6
+-                      PF_INET6,
+-#else
+-                      PF_INET,
+-#endif
+-                      SOCK_STREAM, 0)) < 0)
++      if( (s = socket(family, SOCK_STREAM, 0)) < 0)
+       {
++              if ((family == AF_INET6) && (errno == EAFNOSUPPORT))
++                      return OpenAndConfHTTPSocket(port, AF_INET);
++
+               syslog(LOG_ERR, "socket(http): %m");
+               return -1;
+       }
+@@ -147,18 +142,20 @@ OpenAndConfHTTPSocket(unsigned short por
+               syslog(LOG_WARNING, "set_non_blocking(http): %m");
+       }
+-#ifdef ENABLE_IPV6
+-      memset(&listenname, 0, sizeof(struct sockaddr_in6));
+-      listenname.sin6_family = AF_INET6;
+-      listenname.sin6_port = htons(port);
+-      listenname.sin6_addr = in6addr_any;
+-      listenname_len =  sizeof(struct sockaddr_in6);
+-#else
+-      listenname.sin_family = AF_INET;
+-      listenname.sin_port = htons(port);
+-      listenname.sin_addr.s_addr = htonl(INADDR_ANY);
+-      listenname_len =  sizeof(struct sockaddr_in);
+-#endif
++      memset(&listenname, 0, sizeof(listenname));
++      ln6->sin6_family = family;
++      ln6->sin6_port   = htons(port);
++
++      if (family == AF_INET6)
++      {
++              ln6->sin6_addr = in6addr_any;
++              listenname_len = sizeof(struct sockaddr_in6);
++      }
++      else
++      {
++              ln4->sin_addr.s_addr = htonl(INADDR_ANY);
++              listenname_len = sizeof(struct sockaddr_in);
++      }
+       if(bind(s, (struct sockaddr *)&listenname, listenname_len) < 0)
+       {
+@@ -1253,6 +1250,9 @@ main(int argc, char * * argv)
+       int sudp = -1;          /* IP v4 socket for receiving SSDP */
+ #ifdef ENABLE_IPV6
+       int sudpv6 = -1;        /* IP v6 socket for receiving SSDP */
++      int addr_family = AF_INET6;
++#else
++      int addr_family = AF_INET;
+ #endif
+ #ifdef ENABLE_NATPMP
+       int * snatpmp = NULL;
+@@ -1337,7 +1337,7 @@ main(int argc, char * * argv)
+       {
+               /* open socket for HTTP connections. Listen on the 1st LAN address */
+-              shttpl = OpenAndConfHTTPSocket((v.port > 0) ? v.port : 0);
++              shttpl = OpenAndConfHTTPSocket((v.port > 0) ? v.port : 0, addr_family);
+               if(shttpl < 0)
+               {
+                       syslog(LOG_ERR, "Failed to open socket for HTTP. EXITING");
+--- a/minissdp.c
++++ b/minissdp.c
+@@ -277,8 +277,6 @@ OpenAndConfSSDPNotifySockets(int * socke
+               i++;
+ #ifdef ENABLE_IPV6
+               sockets[i] = OpenAndConfSSDPNotifySocketIPv6(lan_addr->index);
+-              if(sockets[i] < 0)
+-                      goto error;
+               i++;
+ #endif
+       }
+@@ -406,6 +404,9 @@ SendSSDPNotifies(int s, const char * hos
+       char bufr[512];
+       char ver_str[4];
++      if (s < 0)
++              return;
++
+       memset(&sockname, 0, sizeof(sockname));
+ #ifdef ENABLE_IPV6
+       if(ipv6)
+@@ -739,6 +740,10 @@ SendSSDPGoodbye(int * sockets, int n_soc
+ #ifdef ENABLE_IPV6
+               ipv6 = j & 1;
+ #endif
++
++          if (sockets[j] < 0)
++              continue;
++
+           for(i=0; known_service_types[i].s; i++)
+           {
+                       if(i==0)