From 1638d964fbb7114ea880b75439ae2cf369773223 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 16 Jul 2013 06:38:26 -0700 Subject: [PATCH] log socket address to try to track down apparent misaddressing --- xwords4/relay/xwrelay.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/xwords4/relay/xwrelay.cpp b/xwords4/relay/xwrelay.cpp index c39fcda57..7112d29a4 100644 --- a/xwords4/relay/xwrelay.cpp +++ b/xwords4/relay/xwrelay.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #if defined(__FreeBSD__) # if (OSVERSION > 500000) @@ -90,8 +91,8 @@ static int s_nSpawns = 0; static int g_maxsocks = -1; static int g_udpsock = -1; -void -logf( XW_LogLevel level, const char* format, ... ) +static bool +willLog( XW_LogLevel level ) { RelayConfigs* rc = RelayConfigs::GetConfigs(); int configLevel = level; @@ -103,7 +104,13 @@ logf( XW_LogLevel level, const char* format, ... ) } } - if ( level <= configLevel ) { + return level <= configLevel; +} + +void +logf( XW_LogLevel level, const char* format, ... ) +{ + if ( willLog( level ) ) { #ifdef USE_SYSLOG char buf[256]; va_list ap; @@ -118,6 +125,7 @@ logf( XW_LogLevel level, const char* format, ... ) bool useFile; char logFile[256]; + RelayConfigs* rc = RelayConfigs::GetConfigs(); useFile = rc->GetValueFor( "LOGFILE_PATH", logFile, sizeof(logFile) ); if ( useFile ) { @@ -451,7 +459,14 @@ send_via_udp( int socket, const struct sockaddr *dest_addr, if ( 0 > nSent ) { logf( XW_LOGERROR, "sendmsg->errno %d (%s)", errno, strerror(errno) ); } - logf( XW_LOGINFO, "%s()=>%d", __func__, nSent ); + + XW_LogLevel level = XW_LOGINFO; + if ( willLog( level ) ) { + gchar* b64 = g_base64_encode( (unsigned char*)dest_addr, sizeof(dest_addr) ); + logf( level, "%s()=>%d; addr=%s", __func__, nSent, b64 ); + g_free( b64 ); + } + return nSent; }