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;
}
// 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;
}
}
* 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,
#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;
}