From: Guy Harris Date: Mon, 2 Apr 2018 03:12:59 +0000 (-0700) Subject: Rename SOCK_MESSAGE() to SOCK_DEBUG_MESSAGE(). X-Git-Tag: libpcap-1.9-bp~130 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/e6491164d8e72989a74ec4ff4e6535fb15f601f8 Rename SOCK_MESSAGE() to SOCK_DEBUG_MESSAGE(). This emphasizes that it's for *debugging* messages, not for errors sent to the peer or logged to a daemon log file. Any message that would be useful if printed/logged in a production environment should *not* be reported with SOCK_DEBUG_MESSAGE(). --- diff --git a/pcap-rpcap.c b/pcap-rpcap.c index cf84bd9d..42f381c8 100644 --- a/pcap-rpcap.c +++ b/pcap-rpcap.c @@ -1260,7 +1260,7 @@ static int pcap_startcapture_remote(pcap_t *fp) if (res == -1) { sock_geterror("pcap_startcapture_remote()", fp->errbuf, PCAP_ERRBUF_SIZE); - SOCK_MESSAGE(fp->errbuf); + SOCK_DEBUG_MESSAGE(fp->errbuf); } /* @@ -2730,7 +2730,7 @@ SOCKET pcap_remoteact_accept(const char *address, const char *port, const char * { if (sock_initaddress(address, RPCAP_DEFAULT_NETPORT_ACTIVE, &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1) { - SOCK_MESSAGE(errbuf); + SOCK_DEBUG_MESSAGE(errbuf); return (SOCKET)-2; } } @@ -2738,7 +2738,7 @@ SOCKET pcap_remoteact_accept(const char *address, const char *port, const char * { if (sock_initaddress(address, port, &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1) { - SOCK_MESSAGE(errbuf); + SOCK_DEBUG_MESSAGE(errbuf); return (SOCKET)-2; } } @@ -2746,7 +2746,7 @@ SOCKET pcap_remoteact_accept(const char *address, const char *port, const char * if ((sockmain = sock_open(addrinfo, SOCKOPEN_SERVER, 1, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) { - SOCK_MESSAGE(errbuf); + SOCK_DEBUG_MESSAGE(errbuf); freeaddrinfo(addrinfo); return (SOCKET)-2; } diff --git a/rpcapd/daemon.c b/rpcapd/daemon.c index a0acd4af..7c310111 100755 --- a/rpcapd/daemon.c +++ b/rpcapd/daemon.c @@ -648,7 +648,7 @@ daemon_serviceloop(SOCKET sockctrl_in, SOCKET sockctrl_out, int isactive, int nu // This is used only in case of active mode. // client_told_us_to_close = 1; - SOCK_MESSAGE("The other end system asked to close the connection."); + SOCK_DEBUG_MESSAGE("The other end system asked to close the connection."); goto end; } @@ -850,8 +850,8 @@ end: } // Print message and return - SOCK_MESSAGE("I'm exiting from the child loop"); - SOCK_MESSAGE(errbuf); + SOCK_DEBUG_MESSAGE("I'm exiting from the child loop"); + SOCK_DEBUG_MESSAGE(errbuf); return client_told_us_to_close; } diff --git a/rpcapd/fileconf.c b/rpcapd/fileconf.c index 099cdf37..ab1e9dd3 100755 --- a/rpcapd/fileconf.c +++ b/rpcapd/fileconf.c @@ -42,7 +42,7 @@ #include #include // for PCAP_ERRBUF_SIZE -#include "sockutils.h" // for SOCK_MESSAGE +#include "sockutils.h" // for SOCK_DEBUG_MESSAGE #include "portability.h" #include "rpcapd.h" #include "config_params.h" // configuration file parameters @@ -94,7 +94,7 @@ void fileconf_read(void) activelist[i].port[MAX_LINE] = 0; } else - SOCK_MESSAGE("Only MAX_ACTIVE_LIST active connections are currently supported."); + SOCK_DEBUG_MESSAGE("Only MAX_ACTIVE_LIST active connections are currently supported."); i++; continue; @@ -134,7 +134,7 @@ void fileconf_read(void) strrem(hostlist, '\n'); pcap_snprintf(msg, PCAP_ERRBUF_SIZE, "New passive host list: %s\n\n", hostlist); - SOCK_MESSAGE(msg); + SOCK_DEBUG_MESSAGE(msg); fclose(fp); } } diff --git a/rpcapd/rpcapd.c b/rpcapd/rpcapd.c index 7ea0ba90..c6e34285 100755 --- a/rpcapd/rpcapd.c +++ b/rpcapd/rpcapd.c @@ -178,7 +178,7 @@ int main(int argc, char *argv[]) if (sock_init(errbuf, PCAP_ERRBUF_SIZE) == -1) { - SOCK_MESSAGE(errbuf); + SOCK_DEBUG_MESSAGE(errbuf); exit(-1); } @@ -253,7 +253,7 @@ int main(int argc, char *argv[]) } if (i > MAX_ACTIVE_LIST) - SOCK_MESSAGE("Only MAX_ACTIVE_LIST active connections are currently supported."); + SOCK_DEBUG_MESSAGE("Only MAX_ACTIVE_LIST active connections are currently supported."); // I don't initialize the remaining part of the structure, since // it is already zeroed (it is a global var) @@ -284,7 +284,7 @@ int main(int argc, char *argv[]) #endif if (savefile[0] && fileconf_save(savefile)) - SOCK_MESSAGE("Error when saving the configuration to file"); + SOCK_DEBUG_MESSAGE("Error when saving the configuration to file"); // If the file does not exist, it keeps the settings provided by the command line if (loadfile[0]) @@ -442,7 +442,7 @@ int main(int argc, char *argv[]) // If this call succeeds, it is blocking on Win32 // if (svc_start() != 1) - SOCK_MESSAGE("Unable to start the service"); + SOCK_DEBUG_MESSAGE("Unable to start the service"); // When the previous call returns, the entire application has to be stopped. exit(0); @@ -503,7 +503,7 @@ void main_startup(void) (void *)&activelist[i], 0, NULL); if (threadId == 0) { - SOCK_MESSAGE("Error creating the active child threads"); + SOCK_DEBUG_MESSAGE("Error creating the active child threads"); continue; } CloseHandle(threadId); @@ -538,7 +538,7 @@ void main_startup(void) // if (sock_initaddress((address[0]) ? address : NULL, port, &mainhints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1) { - SOCK_MESSAGE(errbuf); + SOCK_DEBUG_MESSAGE(errbuf); return; } @@ -550,7 +550,7 @@ void main_startup(void) if ((sock = sock_open(tempaddrinfo, SOCKOPEN_SERVER, SOCKET_MAXCONN, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) { - SOCK_MESSAGE(errbuf); + SOCK_DEBUG_MESSAGE(errbuf); continue; } @@ -576,7 +576,7 @@ void main_startup(void) // // We're done; exit. // - SOCK_MESSAGE(PROGRAM_NAME " is closing.\n"); + SOCK_DEBUG_MESSAGE(PROGRAM_NAME " is closing.\n"); #ifndef _WIN32 // @@ -722,7 +722,7 @@ static void main_reap_children(int sign) // For reference, Stevens, pg 128 while ((pid = waitpid(-1, &exitstat, WNOHANG)) > 0) - SOCK_MESSAGE("Child terminated"); + SOCK_DEBUG_MESSAGE("Child terminated"); return; } @@ -1197,7 +1197,7 @@ main_active(void *ptr) pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "Connecting to host %s, port %s, using protocol %s", activepars->address, activepars->port, (hints.ai_family == AF_INET) ? "IPv4": (hints.ai_family == AF_INET6) ? "IPv6" : "Unspecified"); - SOCK_MESSAGE(errbuf); + SOCK_DEBUG_MESSAGE(errbuf); // Initialize errbuf memset(errbuf, 0, sizeof(errbuf)); @@ -1205,7 +1205,7 @@ main_active(void *ptr) // Do the work if (sock_initaddress(activepars->address, activepars->port, &hints, &addrinfo, errbuf, PCAP_ERRBUF_SIZE) == -1) { - SOCK_MESSAGE(errbuf); + SOCK_DEBUG_MESSAGE(errbuf); return 0; } @@ -1215,13 +1215,13 @@ main_active(void *ptr) if ((sockctrl = sock_open(addrinfo, SOCKOPEN_CLIENT, 0, errbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET) { - SOCK_MESSAGE(errbuf); + SOCK_DEBUG_MESSAGE(errbuf); pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "Error connecting to host %s, port %s, using protocol %s", activepars->address, activepars->port, (hints.ai_family == AF_INET) ? "IPv4": (hints.ai_family == AF_INET6) ? "IPv6" : "Unspecified"); - SOCK_MESSAGE(errbuf); + SOCK_DEBUG_MESSAGE(errbuf); sleep_secs(RPCAP_ACTIVE_WAIT); diff --git a/rpcapd/win32-svc.c b/rpcapd/win32-svc.c index ea9d9835..b5943781 100755 --- a/rpcapd/win32-svc.c +++ b/rpcapd/win32-svc.c @@ -33,7 +33,7 @@ #include "rpcapd.h" #include // for PCAP_ERRBUF_SIZE -#include "sockutils.h" // for SOCK_MESSAGE +#include "sockutils.h" // for SOCK_DEBUG_MESSAGE #include "portability.h" #include "fileconf.h" @@ -75,7 +75,7 @@ void svc_geterr(char *str) pcap_snprintf(message, PCAP_ERRBUF_SIZE, "%s failed with error %d: %s", str, val, string); - SOCK_MESSAGE(message); + SOCK_DEBUG_MESSAGE(message); } void WINAPI svc_control_handler(DWORD Opcode) diff --git a/sockutils.c b/sockutils.c index 420fd5bc..079c49db 100644 --- a/sockutils.c +++ b/sockutils.c @@ -848,7 +848,7 @@ int sock_recv(SOCKET sock, void *buffer, size_t size, int flags, if (size == 0) { - SOCK_MESSAGE("I have been requested to read zero bytes"); + SOCK_DEBUG_MESSAGE("I have been requested to read zero bytes"); return 0; } if (size > INT_MAX) @@ -939,7 +939,7 @@ int sock_recv_dgram(SOCKET sock, void *buffer, size_t size, if (size == 0) { - SOCK_MESSAGE("I have been requested to read zero bytes"); + SOCK_DEBUG_MESSAGE("I have been requested to read zero bytes"); return 0; } if (size > INT_MAX) @@ -1095,7 +1095,7 @@ int sock_discard(SOCKET sock, int size, char *errbuf, int errbuflen) return -1; } - SOCK_MESSAGE("I'm currently discarding data\n"); + SOCK_DEBUG_MESSAGE("I'm currently discarding data\n"); return 0; } @@ -1170,7 +1170,7 @@ int sock_check_hostlist(char *hostlist, const char *sep, struct sockaddr_storage if (errbuf) pcap_snprintf(errbuf, errbuflen, "getaddrinfo() %s", gai_strerror(retval)); - SOCK_MESSAGE(errbuf); + SOCK_DEBUG_MESSAGE(errbuf); /* Get next token */ token = pcap_strtok_r(NULL, sep, &lasts); diff --git a/sockutils.h b/sockutils.h index 6c7198df..1df1ef7b 100644 --- a/sockutils.h +++ b/sockutils.h @@ -139,15 +139,15 @@ int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD, * \return No return values. */ #ifdef NDEBUG - #define SOCK_MESSAGE(msg) ((void)0) + #define SOCK_DEBUG_MESSAGE(msg) ((void)0) #else #if (defined(_WIN32) && defined(_MSC_VER)) #include /* for _CrtDbgReport */ /* Use MessageBox(NULL, msg, "warning", MB_OK)' instead of the other calls if you want to debug a Win32 service */ /* Remember to activate the 'allow service to interact with desktop' flag of the service */ - #define SOCK_MESSAGE(msg) { _CrtDbgReport(_CRT_WARN, NULL, 0, NULL, "%s\n", msg); fprintf(stderr, "%s\n", msg); } + #define SOCK_DEBUG_MESSAGE(msg) { _CrtDbgReport(_CRT_WARN, NULL, 0, NULL, "%s\n", msg); fprintf(stderr, "%s\n", msg); } #else - #define SOCK_MESSAGE(msg) { fprintf(stderr, "%s\n", msg); } + #define SOCK_DEBUG_MESSAGE(msg) { fprintf(stderr, "%s\n", msg); } #endif #endif