Created
May 27, 2011 16:38
-
-
Save psychon/995638 to your computer and use it in GitHub Desktop.
Add some debug output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Csocket.cpp b/Csocket.cpp | |
index b2bcf44..3c6640c 100644 | |
--- a/Csocket.cpp | |
+++ b/Csocket.cpp | |
@@ -53,6 +53,21 @@ namespace Csocket | |
{ | |
#endif /* _NO_CSOCKET_NS */ | |
+#include <execinfo.h> | |
+static inline void v6_foo(bool old_val, bool new_val, const char *msg) | |
+{ | |
+ const int max_stack = 64; | |
+ void *stack[max_stack]; | |
+ CS_DEBUG("Setting v6 from " << old_val << " to " << new_val << " due to: " << msg); | |
+ int stack_size = backtrace(stack, max_stack); | |
+ backtrace_symbols_fd(stack, stack_size, 1); | |
+} | |
+ | |
+static inline void v6_foo(Csock * pSock, bool new_val, const char *msg) | |
+{ | |
+ v6_foo(pSock->GetIPv6(), new_val, msg); | |
+} | |
+ | |
static int g_iCsockSSLIdx = 0; //!< this get setup once in InitSSL | |
int GetCsockClassIdx() | |
{ | |
@@ -246,12 +261,14 @@ static void AresHostCallback( void *pArg, int status, int timeouts, struct hoste | |
CSSockAddr *pSockAddr = pSock->GetCurrentAddr(); | |
if( hent->h_addrtype == AF_INET ) | |
{ | |
+ v6_foo(pSock, false, "dns callback"); | |
pSock->SetIPv6( false ); | |
memcpy( pSockAddr->GetAddr(), hent->h_addr_list[0], sizeof( *(pSockAddr->GetAddr()) ) ); | |
} | |
#ifdef HAVE_IPV6 | |
else if( hent->h_addrtype == AF_INET6 ) | |
{ | |
+ v6_foo(pSock, true, "dns callback"); | |
pSock->SetIPv6( true ); | |
memcpy( pSockAddr->GetAddr6(), hent->h_addr_list[0], sizeof( *(pSockAddr->GetAddr6()) ) ); | |
} | |
@@ -273,6 +290,7 @@ int GetAddrInfo( const CS_STRING & sHostname, Csock *pSock, CSSockAddr & csSockA | |
{ | |
#ifndef HAVE_IPV6 | |
// if ipv6 is not enabled, then simply use gethostbyname, nothing special outside of this is done | |
+ v6_foo(csSockAddr, false, "GetAddrInfo"); | |
if( pSock ) | |
pSock->SetIPv6( false ); | |
csSockAddr.SetIPv6( false ); | |
@@ -323,6 +341,7 @@ int GetAddrInfo( const CS_STRING & sHostname, Csock *pSock, CSSockAddr & csSockA | |
bool bTryConnect = false; | |
if( pRes->ai_family == AF_INET ) | |
{ | |
+ v6_foo(pSock, false, "getaddrinfo, case AF_INET"); | |
if( pSock ) | |
pSock->SetIPv6( false ); | |
csSockAddr.SetIPv6( false ); | |
@@ -340,6 +359,7 @@ int GetAddrInfo( const CS_STRING & sHostname, Csock *pSock, CSSockAddr & csSockA | |
} | |
else if( pRes->ai_family == AF_INET6 ) | |
{ | |
+ v6_foo(pSock, true, "getaddrinfo, case AF_INET6"); | |
if( pSock ) | |
pSock->SetIPv6( true ); | |
csSockAddr.SetIPv6( true ); | |
@@ -2198,6 +2218,7 @@ int Csock::GetAddrInfo( const CS_STRING & sHostname, CSSockAddr & csSockAddr ) | |
#ifdef HAVE_IPV6 | |
if( csSockAddr.GetAFRequire() != AF_INET && inet_pton( AF_INET6, sHostname.c_str(), csSockAddr.GetAddr6() ) > 0 ) | |
{ | |
+ v6_foo(this, true, "Csock::getaddrinfo, got an IP"); | |
SetIPv6( true ); | |
return( 0 ); | |
} | |
@@ -2205,6 +2226,7 @@ int Csock::GetAddrInfo( const CS_STRING & sHostname, CSSockAddr & csSockAddr ) | |
if( inet_pton( AF_INET, sHostname.c_str(), csSockAddr.GetAddr() ) > 0 ) | |
{ | |
#ifdef HAVE_IPV6 | |
+ v6_foo(this, false, "Csock::getaddrinfo, got an IPv6"); | |
SetIPv6( false ); | |
#endif /* HAVE_IPV6 */ | |
return( 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment