]> The Tcpdump Group git mirrors - libpcap/commitdiff
Don't log errors due to the peer dropping the connection.
authorGuy Harris <[email protected]>
Sun, 1 Apr 2018 03:36:01 +0000 (20:36 -0700)
committerGuy Harris <[email protected]>
Sun, 1 Apr 2018 03:36:01 +0000 (20:36 -0700)
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.

rpcapd/daemon.c
sockutils.c

index e2d89d96b2ad6eb8fe360bff460a65a8a8a87c9b..54b259b8bf168c984f50468eef2d53efc0a309ae 100755 (executable)
@@ -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;
                }
        }
index e7912fbef1d5befda1b5ca56c70a6b53436d926a..2dfa9f90a157326eade77ec1f83648488547ba53 100644 (file)
@@ -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;
                }