]> The Tcpdump Group git mirrors - libpcap/commitdiff
Don't tell the client if we can't turn non-blocking mode off.
authorGuy Harris <[email protected]>
Mon, 7 Jan 2019 04:22:45 +0000 (20:22 -0800)
committerGuy Harris <[email protected]>
Mon, 7 Jan 2019 04:22:45 +0000 (20:22 -0800)
If the control socket is in non-blocking mode, there's no guarantee that
we can easily send an error message to the client - we *probably* can,
but let's not rely on it, especially given that there are "shouldn't
happen" errors.  Log them instead.

While we're at it, fix a copy-and-pasteo and fix indentation.

rpcapd/rpcapd.c

index 0509147a841845969084163e521b24ec2b295091..5d9dd34377d8e682f8570fcd1948720f7992a95c 100644 (file)
@@ -1193,17 +1193,25 @@ accept_connection(SOCKET listen_sock)
        // First, we have to un-WSAEventSelect() this socket, and then
        // we can turn non-blocking mode off.
        //
+       // If this fails, we aren't guaranteed that, for example, any
+       // of the error message will be sent - if it can't be put in
+       // the socket queue, the send will just fail.
+       //
+       // So we just log the message and close the connection.
+       //
        if (WSAEventSelect(sockctrl, NULL, 0) == SOCKET_ERROR)
        {
-               sock_geterror("ioctlsocket(FIONBIO): ", errbuf, PCAP_ERRBUF_SIZE);
-               rpcap_senderror(sockctrl, ssl, 0, PCAP_ERR_HOSTNOAUTH, errbuf, NULL);
-               goto error;
+               sock_geterror("WSAEventSelect: ", errbuf, PCAP_ERRBUF_SIZE);
+               rpcapd_log(LOGPRIO_ERROR, "%s", errbuf);
+               sock_close(sockctrl, NULL, 0);
+               return;
        }
        if (ioctlsocket(sockctrl, FIONBIO, &off) == SOCKET_ERROR)
        {
                sock_geterror("ioctlsocket(FIONBIO): ", errbuf, PCAP_ERRBUF_SIZE);
-               rpcap_senderror(sockctrl, ssl, 0, PCAP_ERR_HOSTNOAUTH, errbuf, NULL);
-               goto error;
+               rpcapd_log(LOGPRIO_ERROR, "%s", errbuf);
+               sock_close(sockctrl, NULL, 0);
+               return;
        }
 
        //
@@ -1289,7 +1297,7 @@ accept_connection(SOCKET listen_sock)
 #endif
        closesocket(sockctrl);
 #endif
-  return;
+       return;
 
 error:
 #ifdef _WIN32