diff --git a/Csocket.cpp b/Csocket.cpp index 893c0302..a41046fd 100644 --- a/Csocket.cpp +++ b/Csocket.cpp @@ -28,7 +28,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * -* $Revision: 1.97 $ +* $Revision: 1.98 $ */ #include "Csocket.h" @@ -193,7 +193,7 @@ static int __GetHostByName( const CS_STRING & sHostName, struct in_addr *paddr, if ( iReturn == 0 ) memcpy( &paddr->s_addr, hent->h_addr_list[0], sizeof( paddr->s_addr ) ); - return( iReturn ); + return( iReturn == TRY_AGAIN ? EAGAIN : iReturn ); } #endif /* !HAVE_IPV6 */ @@ -858,7 +858,7 @@ bool Csock::Listen( u_short iPort, int iMaxConns, const CS_STRING & sBindHost, u m_sBindHost = sBindHost; if ( !sBindHost.empty() ) { - if( GetAddrInfo( sBindHost, this, m_address ) != 0 ) + if( GetAddrInfo( sBindHost, m_address ) != 0 ) return( false ); } @@ -2011,6 +2011,11 @@ int Csock::GetPending() #endif /* HAVE_LIBSSL */ } +int Csock::GetAddrInfo( const CS_STRING & sHostname, CSSockAddr & csSockAddr ) +{ + return( ::GetAddrInfo( sHostname, this, csSockAddr ) ); +} + int Csock::DNSLookup( EDNSLType eDNSLType ) { if ( eDNSLType == DNS_VHOST ) @@ -2029,7 +2034,7 @@ int Csock::DNSLookup( EDNSLType eDNSLType ) int iRet = ETIMEDOUT; if ( eDNSLType == DNS_VHOST ) { - iRet = GetAddrInfo( m_sBindHost, this, m_bindhost ); + iRet = GetAddrInfo( m_sBindHost, m_bindhost ); #ifdef HAVE_IPV6 if( m_bindhost.GetIPv6() ) { @@ -2043,7 +2048,7 @@ int Csock::DNSLookup( EDNSLType eDNSLType ) } else { - iRet = GetAddrInfo( m_shostname, this, m_address ); + iRet = GetAddrInfo( m_shostname, m_address ); } if( !CreateSocksFD() ) @@ -2056,7 +2061,7 @@ int Csock::DNSLookup( EDNSLType eDNSLType ) m_iDNSTryCount = 0; return( 0 ); } - else if ( iRet == TRY_AGAIN ) + else if ( iRet == EAGAIN ) { m_iDNSTryCount++; if ( m_iDNSTryCount > 20 ) diff --git a/Csocket.h b/Csocket.h index 4a5ce147..91bbfd21 100644 --- a/Csocket.h +++ b/Csocket.h @@ -28,7 +28,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * -* $Revision: 1.205 $ +* $Revision: 1.206 $ */ // note to compile with win32 need to link to winsock2, using gcc its -lws2_32 @@ -109,7 +109,7 @@ #else # define PERROR( f ) (void)0 #endif /* __DEBUG__ */ -#endif +#endif /* PERROR */ #ifndef _NO_CSOCKET_NS // some people may not want to use a namespace namespace Csocket @@ -955,6 +955,14 @@ public: void SetSkipConnect( bool b ) { m_bSkipConnect = b; } + /** + * @brief override this call with your own DNS lookup method if you have one. By default this function is blocking + * @param sHostname the hostname to resolve + * @param csSockAddr the destination sock address info @see CSSockAddr + * @return 0 on success, ETIMEDOUT if no lookup was found, EAGAIN if you should check again later for an answer + */ + virtual int GetAddrInfo( const CS_STRING & sHostname, CSSockAddr & csSockAddr ); + private: //! making private for safety Csock( const Csock & cCopy ) {}