Logo Search packages:      
Sourcecode: znc version File versions  Download package

int Csock::DNSLookup ( EDNSLType  eDNSLType  ) 

DNSLookup nonblocking dns lookup (when -pthread is set to compile

Returns:
0 for success, EAGAIN to check back again (same arguments as before, ETIMEDOUT on failure

Definition at line 1724 of file Csocket.cpp.

References CreateSocksFD().

Referenced by Connect().

{
      if ( eDNSLType == DNS_VHOST )
      {
            if ( m_sBindHost.empty() )
            {
                  if ( m_eConState != CST_OK )
                        m_eConState = CST_BINDVHOST;
                  return( 0 );
            }

            m_bindhost.SinFamily();
            m_bindhost.SinPort( 0 );
      }

#ifdef ___DO_THREADS
      if ( m_iDNSTryCount == 0 )
      {
            m_cResolver.Lookup( ( eDNSLType == DNS_VHOST ) ? m_sBindHost : m_shostname );
            m_iDNSTryCount++;
      }
   
      if ( m_cResolver.IsCompleted() )
      {
            m_iDNSTryCount = 0;
            if ( m_cResolver.Suceeded() )
            {
                  if ( eDNSLType == DNS_VHOST )
                  {
                        if( !m_cResolver.GetSockAddr()->GetIPv6() )
                        {
                              SetIPv6( false );
                              memcpy( m_bindhost.GetAddr(), m_cResolver.GetSockAddr()->GetAddr(), sizeof( *(m_bindhost.GetAddr()) ) );
                        }
#ifdef HAVE_IPV6
                        else
                        {
                              SetIPv6( true );
                              memcpy( m_bindhost.GetAddr6(), m_cResolver.GetSockAddr()->GetAddr6(), sizeof( *(m_bindhost.GetAddr6()) ) );
                        }
#endif /* HAVE_IPV6 */
                  }
                  else
                  {
                        if( m_cResolver.GetSockAddr()->GetIPv6() )
                        {
                              SetIPv6( false );
                              memcpy( m_address.GetAddr(), m_cResolver.GetSockAddr()->GetAddr(), sizeof( *(m_address.GetAddr()) ) );
                        }
#ifdef HAVE_IPV6
                        else
                        {
                              SetIPv6( true );
                              memcpy( m_address.GetAddr6(), m_cResolver.GetSockAddr()->GetAddr6(), sizeof( *(m_address.GetAddr6()) ) );
                        }
#endif /* HAVE_IPV6 */
                  }

                  if ( m_eConState != CST_OK )
                        m_eConState = ( ( eDNSLType == DNS_VHOST ) ? CST_BINDVHOST : CST_VHOSTDNS );
      
                  if( !CreateSocksFD() )
                        return( ETIMEDOUT );

                  return( 0 );
            }

            return( ETIMEDOUT );
      }
      return( EAGAIN );
      
#else
      int iRet = ETIMEDOUT;
      if ( eDNSLType == DNS_VHOST )
      {
            iRet = GetAddrInfo( m_sBindHost, this, m_bindhost );
      }
      else
      {
            iRet = GetAddrInfo( m_shostname, this, m_address );
      }

      if( !CreateSocksFD() )
            iRet = ETIMEDOUT;
      
      if ( iRet == 0 )
      {
            if ( m_eConState != CST_OK )
                  m_eConState = ( ( eDNSLType == DNS_VHOST ) ? CST_BINDVHOST : CST_VHOSTDNS );
            m_iDNSTryCount = 0;
            return( 0 );
      }
      else if ( iRet == TRY_AGAIN )
      {
            m_iDNSTryCount++;
            if ( m_iDNSTryCount > 20 )
            {
                  m_iDNSTryCount = 0;
                  return( ETIMEDOUT );
            }
            return( EAGAIN );
      }
      m_iDNSTryCount = 0;
      return( ETIMEDOUT );
#endif /* ___DO_THREADS */
}


Generated by  Doxygen 1.6.0   Back to index