socket-default: to bind to one dynamic port on OS X, create v4 socket before v6
authorMartin Willi <martin@revosec.ch>
Thu, 11 Apr 2013 18:22:06 +0000 (20:22 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 6 May 2013 14:10:11 +0000 (16:10 +0200)
It seems that the order of binding sockets of different address families to the
same dynamic port must be v6-before-v4 on Linux, but v4-before-v6 on OS X.

src/libcharon/plugins/socket_default/socket_default_socket.c

index 9c1bce3..a9c2983 100644 (file)
@@ -692,9 +692,15 @@ socket_default_socket_t *socket_default_socket_create()
        }
 
        /* we allocate IPv6 sockets first as that will reserve randomly allocated
-        * ports also for IPv4 */
+        * ports also for IPv4. On OS X, we have to do it the other way round
+        * for the same effect. */
+#ifdef __APPLE__
+       open_socketpair(this, AF_INET, &this->ipv4, &this->ipv4_natt, "IPv4");
+       open_socketpair(this, AF_INET6, &this->ipv6, &this->ipv6_natt, "IPv6");
+#else /* !__APPLE__ */
        open_socketpair(this, AF_INET6, &this->ipv6, &this->ipv6_natt, "IPv6");
        open_socketpair(this, AF_INET, &this->ipv4, &this->ipv4_natt, "IPv4");
+#endif /* __APPLE__ */
 
        if (this->ipv4 == -1 && this->ipv6 == -1)
        {