]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Fix broken linking over IPv4 on IPv6 capable systems.
authorPeter Powell <petpow@saberuk.com>
Thu, 25 Apr 2019 18:20:07 +0000 (19:20 +0100)
committerPeter Powell <petpow@saberuk.com>
Thu, 25 Apr 2019 18:24:35 +0000 (19:24 +0100)
If no bind address was specified then one would be
created which had an incompatible address family to
the address that the server was trying to connect to.

src/modules/m_spanningtree/treesocket1.cpp

index fd20d04c4568efaa31ee5f6596fa73dba91443e9..1913fa4de673a2608f1a9c4e6caaded88f7d0fde 100644 (file)
@@ -47,12 +47,22 @@ TreeSocket::TreeSocket(Link* link, Autoconnect* myac, const irc::sockets::sockad
 
        irc::sockets::sockaddrs bind;
        memset(&bind, 0, sizeof(bind));
-       if ((dest.family() == AF_INET || dest.family() == AF_INET6) && !irc::sockets::aptosa(link->Bind, 0, bind))
+       if (!link->Bind.empty() && (dest.family() == AF_INET || dest.family() == AF_INET6))
        {
-               state = I_ERROR;
-               SetError("Bind address '" + link->Bind + "' is not an valid IPv4 or IPv6 address");
-               TreeSocket::OnError(I_ERR_BIND);
-               return;
+               if (!irc::sockets::aptosa(link->Bind, 0, bind))
+               {
+                       state = I_ERROR;
+                       SetError("Bind address '" + link->Bind + "' is not an valid IPv4 or IPv6 address");
+                       TreeSocket::OnError(I_ERR_BIND);
+                       return;
+               }
+               else if (bind.family() != dest.family())
+               {
+                       state = I_ERROR;
+                       SetError("Bind address '" + bind.addr() + "' is not the same address family as destination address '" + dest.addr() + "'");
+                       TreeSocket::OnError(I_ERR_BIND);
+                       return;
+               }
        }
 
        DoConnect(dest, bind, link->Timeout);