From 4c14b1bf61081c216c204cde9c3d9fe57beb080e Mon Sep 17 00:00:00 2001 From: psychon Date: Sat, 4 Jul 2009 12:54:15 +0000 Subject: [PATCH] Fix a DNS bug in Csocket with non-blocking resolvers After the first attempt to lookup an address, Csocket already created the socket used for communicating. Since at this point it wasn't yet known whether we will yield a IPv4 or IPv6 address, Csocket just always used IPv4. This would then later fail to connect() with 'Address family not supported by protocol'. This patch fixes this by creating the socket fd only when the DNS lookup completed successfully. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1556 726aef4b-f618-498e-8847-2d620e286838 --- Csocket.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Csocket.cpp b/Csocket.cpp index 27e9b65f..c510c39b 100644 --- a/Csocket.cpp +++ b/Csocket.cpp @@ -2051,11 +2051,14 @@ int Csock::DNSLookup( EDNSLType eDNSLType ) iRet = GetAddrInfo( m_shostname, m_address ); } - if( !CreateSocksFD() ) - iRet = ETIMEDOUT; - if ( iRet == 0 ) { + if( !CreateSocksFD() ) + { + m_iDNSTryCount = 0; + return ETIMEDOUT; + } + if ( m_eConState != CST_OK ) m_eConState = ( ( eDNSLType == DNS_VHOST ) ? CST_BINDVHOST : CST_CONNECT ); m_iDNSTryCount = 0;