From: Guy Harris Date: Sun, 1 Apr 2018 03:36:01 +0000 (-0700) Subject: Don't log errors due to the peer dropping the connection. X-Git-Tag: libpcap-1.9-bp~143 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/e750801220bf0e56852b319b2d5a4b2d342604d5 Don't log errors due to the peer dropping the connection. They may happen because somebody ^C's a tcpdump; that's not worth logging. On UN*X, that might show up as ECONNRESET or EPIPE; on Windows, that might show up as WSAECONNRESET or WSAECONNABORTED. --- diff --git a/rpcapd/daemon.c b/rpcapd/daemon.c index e2d89d96..54b259b8 100755 --- a/rpcapd/daemon.c +++ b/rpcapd/daemon.c @@ -2232,6 +2232,7 @@ daemon_thrdatamain(void *ptr) size_t sendbufsize; // size for the send buffer char *sendbuf; // temporary buffer in which data to be sent is buffered int sendbufidx; // index which keeps the number of bytes currently buffered + int status; session = (struct session *) ptr; @@ -2329,10 +2330,26 @@ daemon_thrdatamain(void *ptr) } // Send the packet - if (sock_send(session->sockdata, sendbuf, sendbufidx, errbuf, PCAP_ERRBUF_SIZE) == -1) + // If the client dropped the connection, don't report an + // error, just quit. + status = sock_send(session->sockdata, sendbuf, sendbufidx, errbuf, PCAP_ERRBUF_SIZE); + if (status < 0) { - rpcapd_log(LOGPRIO_ERROR, - "Send of packet to client failed: %s", errbuf); + if (status == -1) + { + // + // Error other than "client closed the + // connection out from under us"; report + // it. + // + rpcapd_log(LOGPRIO_ERROR, + "Send of packet to client failed: %s", + errbuf); + } + + // + // Give up in either case. + // goto error; } } diff --git a/sockutils.c b/sockutils.c index e7912fbe..2dfa9f90 100644 --- a/sockutils.c +++ b/sockutils.c @@ -640,7 +640,8 @@ int sock_initaddress(const char *host, const char *port, * larger than 'errbuflen - 1' because the last char is reserved for the string terminator. * * \return '0' if everything is fine, '-1' if an error other than - * "connection reset" occurred, '-2' if "connection reset" occurred. + * "connection reset" or "peer has closed the receive side" occurred, + * '-2' if we got one of those errors. * For errors, an error message is returned in the 'errbuf' variable. */ int sock_send(SOCKET sock, const char *buffer, size_t size, @@ -686,15 +687,30 @@ int sock_send(SOCKET sock, const char *buffer, size_t size, #ifdef _WIN32 errcode = GetLastError(); - - sock_fmterror("send(): ", errcode, errbuf, errbuflen); - if (errcode == WSAECONNRESET) + if (errcode == WSAECONNRESET || + errcode == WSAECONNABORTED) + { + /* + * WSAECONNABORTED appears to be the error + * returned in Winsock when you try to send + * on a connection where the peer has closed + * the receive side. + */ return -2; + } + sock_fmterror("send(): ", errcode, errbuf, errbuflen); #else errcode = errno; - sock_fmterror("send(): ", errcode, errbuf, errbuflen); - if (errcode == ECONNRESET) + if (errcode == ECONNRESET || errcode == EPIPE) + { + /* + * EPIPE is what's returned on UN*X when + * you try to send on a connection when + * the peer has closed the receive side. + */ return -2; + } + sock_fmterror("send(): ", errcode, errbuf, errbuflen); #endif return -1; }