Created
May 27, 2011 16:36
-
-
Save psychon/995636 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..e97f734 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() | |
{ | |
@@ -247,12 +262,14 @@ static void AresHostCallback( void *pArg, int status, int timeouts, struct hoste | |
if( hent->h_addrtype == AF_INET ) | |
{ | |
pSock->SetIPv6( false ); | |
+ v6_foo(pSock, false, "dns callback"); | |
memcpy( pSockAddr->GetAddr(), hent->h_addr_list[0], sizeof( *(pSockAddr->GetAddr()) ) ); | |
} | |
#ifdef HAVE_IPV6 | |
else if( hent->h_addrtype == AF_INET6 ) | |
{ | |
pSock->SetIPv6( true ); | |
+ v6_foo(pSock, true, "dns callback"); | |
memcpy( pSockAddr->GetAddr6(), hent->h_addr_list[0], sizeof( *(pSockAddr->GetAddr6()) ) ); | |
} | |
#endif /* HAVE_IPV6 */ | |
@@ -276,6 +293,7 @@ int GetAddrInfo( const CS_STRING & sHostname, Csock *pSock, CSSockAddr & csSockA | |
if( pSock ) | |
pSock->SetIPv6( false ); | |
csSockAddr.SetIPv6( false ); | |
+ v6_foo(csSockAddr, false, "GetAddrInfo"); | |
if( __GetHostByName( sHostname, csSockAddr.GetAddr(), 3 ) == 0 ) | |
return( 0 ); | |
@@ -326,6 +344,7 @@ int GetAddrInfo( const CS_STRING & sHostname, Csock *pSock, CSSockAddr & csSockA | |
if( pSock ) | |
pSock->SetIPv6( false ); | |
csSockAddr.SetIPv6( false ); | |
+ v6_foo(pSock, false, "getaddrinfo, case AF_INET"); | |
struct sockaddr_in *pTmp = (struct sockaddr_in *)pRes->ai_addr; | |
memcpy( csSockAddr.GetAddr(), &(pTmp->sin_addr), sizeof( *(csSockAddr.GetAddr()) ) ); | |
if( pSock && pSock->GetConState() == Csock::CST_DESTDNS && pSock->GetType() == Csock::OUTBOUND ) | |
@@ -343,6 +362,7 @@ int GetAddrInfo( const CS_STRING & sHostname, Csock *pSock, CSSockAddr & csSockA | |
if( pSock ) | |
pSock->SetIPv6( true ); | |
csSockAddr.SetIPv6( true ); | |
+ v6_foo(pSock, true, "getaddrinfo, case AF_INET6"); | |
struct sockaddr_in6 *pTmp = (struct sockaddr_in6 *)pRes->ai_addr; | |
memcpy( csSockAddr.GetAddr6(), &(pTmp->sin6_addr), sizeof( *(csSockAddr.GetAddr6()) ) ); | |
if( pSock && pSock->GetConState() == Csock::CST_DESTDNS && pSock->GetType() == Csock::OUTBOUND ) | |
@@ -2199,6 +2219,7 @@ int Csock::GetAddrInfo( const CS_STRING & sHostname, CSSockAddr & csSockAddr ) | |
if( csSockAddr.GetAFRequire() != AF_INET && inet_pton( AF_INET6, sHostname.c_str(), csSockAddr.GetAddr6() ) > 0 ) | |
{ | |
SetIPv6( true ); | |
+ v6_foo(this, true, "Csock::getaddrinfo, got an IP"); | |
return( 0 ); | |
} | |
#endif /* HAVE_IPV6 */ | |
@@ -2206,6 +2227,7 @@ int Csock::GetAddrInfo( const CS_STRING & sHostname, CSSockAddr & csSockAddr ) | |
{ | |
#ifdef HAVE_IPV6 | |
SetIPv6( false ); | |
+ v6_foo(this, false, "Csock::getaddrinfo, got an IPv6"); | |
#endif /* HAVE_IPV6 */ | |
return( 0 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment