0624ec
diff --git a/ncat/ncat_core.c b/ncat/ncat_core.c
0624ec
index 649e478..21eca9e 100644
0624ec
--- a/ncat/ncat_core.c
0624ec
+++ b/ncat/ncat_core.c
0624ec
@@ -458,7 +458,7 @@ int ncat_broadcast(fd_set *fds, const fd_list_t *fdlist, const char *msg, size_t
0624ec
 
0624ec
     ret = 0;
0624ec
     for (i = 0; i <= fdlist->fdmax; i++) {
0624ec
-        if (!FD_ISSET(i, fds))
0624ec
+        if (!checked_fd_isset(i, fds))
0624ec
             continue;
0624ec
 
0624ec
         fdn = get_fdinfo(fdlist, i);
0624ec
diff --git a/ncat/ncat_listen.c b/ncat/ncat_listen.c
0624ec
index 5c4bb33..bb779cf 100644
0624ec
--- a/ncat/ncat_listen.c
0624ec
+++ b/ncat/ncat_listen.c
0624ec
@@ -312,10 +312,10 @@ static int ncat_listen_stream(int proto)
0624ec
         unblock_socket(listen_socket[num_sockets]);
0624ec
 
0624ec
         /* setup select sets and max fd */
0624ec
-        FD_SET(listen_socket[num_sockets], &master_readfds);
0624ec
+        checked_fd_set(listen_socket[num_sockets], &master_readfds);
0624ec
         add_fd(&client_fdlist, listen_socket[num_sockets]);
0624ec
 
0624ec
-        FD_SET(listen_socket[num_sockets], &listen_fds);
0624ec
+        checked_fd_set(listen_socket[num_sockets], &listen_fds);
0624ec
 
0624ec
         num_sockets++;
0624ec
     }
0624ec
@@ -368,7 +368,7 @@ static int ncat_listen_stream(int proto)
0624ec
          */
0624ec
         for (i = 0; i <= client_fdlist.fdmax && fds_ready > 0; i++) {
0624ec
             /* Loop through descriptors until there's something to read */
0624ec
-            if (!FD_ISSET(i, &readfds) && !FD_ISSET(i, &writefds))
0624ec
+            if (!checked_fd_isset(i, &readfds) && !checked_fd_isset(i, &writefds))
0624ec
                 continue;
0624ec
 
0624ec
             if (o.debug > 1)
0624ec
@@ -376,30 +376,30 @@ static int ncat_listen_stream(int proto)
0624ec
 
0624ec
 #ifdef HAVE_OPENSSL
0624ec
             /* Is this an ssl socket pending a handshake? If so handle it. */
0624ec
-            if (o.ssl && FD_ISSET(i, &sslpending_fds)) {
0624ec
+            if (o.ssl && checked_fd_isset(i, &sslpending_fds)) {
0624ec
                 struct fdinfo *fdi = NULL;
0624ec
-                FD_CLR(i, &master_readfds);
0624ec
-                FD_CLR(i, &master_writefds);
0624ec
+                checked_fd_clr(i, &master_readfds);
0624ec
+                checked_fd_clr(i, &master_writefds);
0624ec
                 fdi = get_fdinfo(&client_fdlist, i);
0624ec
                 ncat_assert(fdi != NULL);
0624ec
                 switch (ssl_handshake(fdi)) {
0624ec
                 case NCAT_SSL_HANDSHAKE_COMPLETED:
0624ec
                     /* Clear from sslpending_fds once ssl is established */
0624ec
-                    FD_CLR(i, &sslpending_fds);
0624ec
+                    checked_fd_clr(i, &sslpending_fds);
0624ec
                     post_handle_connection(*fdi);
0624ec
                     break;
0624ec
                 case NCAT_SSL_HANDSHAKE_PENDING_WRITE:
0624ec
-                    FD_SET(i, &master_writefds);
0624ec
+                    checked_fd_set(i, &master_writefds);
0624ec
                     break;
0624ec
                 case NCAT_SSL_HANDSHAKE_PENDING_READ:
0624ec
-                    FD_SET(i, &master_readfds);
0624ec
+                    checked_fd_set(i, &master_readfds);
0624ec
                     break;
0624ec
                 case NCAT_SSL_HANDSHAKE_FAILED:
0624ec
                 default:
0624ec
                     SSL_free(fdi->ssl);
0624ec
                     Close(fdi->fd);
0624ec
-                    FD_CLR(i, &sslpending_fds);
0624ec
-                    FD_CLR(i, &master_readfds);
0624ec
+                    checked_fd_clr(i, &sslpending_fds);
0624ec
+                    checked_fd_clr(i, &master_readfds);
0624ec
                     rm_fd(&client_fdlist, i);
0624ec
                     /* Are we in single listening mode(without -k)? If so
0624ec
                        then we should quit also. */
0624ec
@@ -410,7 +410,7 @@ static int ncat_listen_stream(int proto)
0624ec
                 }
0624ec
             } else
0624ec
 #endif
0624ec
-            if (FD_ISSET(i, &listen_fds)) {
0624ec
+            if (checked_fd_isset(i, &listen_fds)) {
0624ec
                 /* we have a new connection request */
0624ec
                 handle_connection(i);
0624ec
             } else if (i == STDIN_FILENO) {
0624ec
@@ -490,7 +490,7 @@ static void handle_connection(int socket_accept)
0624ec
         int i;
0624ec
         for (i = 0; i < num_listenaddrs; i++) {
0624ec
             Close(listen_socket[i]);
0624ec
-            FD_CLR(listen_socket[i], &master_readfds);
0624ec
+            checked_fd_clr(listen_socket[i], &master_readfds);
0624ec
             rm_fd(&client_fdlist, listen_socket[i]);
0624ec
         }
0624ec
     }
0624ec
@@ -528,9 +528,9 @@ static void handle_connection(int socket_accept)
0624ec
 #ifdef HAVE_OPENSSL
0624ec
     if (o.ssl) {
0624ec
         /* Add the socket to the necessary descriptor lists. */
0624ec
-        FD_SET(s.fd, &sslpending_fds);
0624ec
-        FD_SET(s.fd, &master_readfds);
0624ec
-        FD_SET(s.fd, &master_writefds);
0624ec
+        checked_fd_set(s.fd, &sslpending_fds);
0624ec
+        checked_fd_set(s.fd, &master_readfds);
0624ec
+        checked_fd_set(s.fd, &master_writefds);
0624ec
         /* Add it to our list of fds too for maintaining maxfd. */
0624ec
         if (add_fdinfo(&client_fdlist, &s) < 0)
0624ec
             bye("add_fdinfo() failed.");
0624ec
@@ -563,10 +563,10 @@ static void post_handle_connection(struct fdinfo sinfo)
0624ec
     } else {
0624ec
         /* Now that a client is connected, pay attention to stdin. */
0624ec
         if (!stdin_eof)
0624ec
-            FD_SET(STDIN_FILENO, &master_readfds);
0624ec
+            checked_fd_set(STDIN_FILENO, &master_readfds);
0624ec
         if (!o.sendonly) {
0624ec
             /* add to our lists */
0624ec
-            FD_SET(sinfo.fd, &master_readfds);
0624ec
+            checked_fd_set(sinfo.fd, &master_readfds);
0624ec
             /* add it to our list of fds for maintaining maxfd */
0624ec
 #ifdef HAVE_OPENSSL
0624ec
             /* Don't add it twice (see handle_connection above) */
0624ec
@@ -578,7 +578,7 @@ static void post_handle_connection(struct fdinfo sinfo)
0624ec
             }
0624ec
 #endif
0624ec
         }
0624ec
-        FD_SET(sinfo.fd, &master_broadcastfds);
0624ec
+        checked_fd_set(sinfo.fd, &master_broadcastfds);
0624ec
         if (add_fdinfo(&broadcast_fdlist, &sinfo) < 0)
0624ec
             bye("add_fdinfo() failed.");
0624ec
 
0624ec
@@ -603,7 +603,7 @@ int read_stdin(void)
0624ec
             logdebug("EOF on stdin\n");
0624ec
 
0624ec
         /* Don't close the file because that allows a socket to be fd 0. */
0624ec
-        FD_CLR(STDIN_FILENO, &master_readfds);
0624ec
+        checked_fd_clr(STDIN_FILENO, &master_readfds);
0624ec
         /* Buf mark that we've seen EOF so it doesn't get re-added to the
0624ec
            select list. */
0624ec
         stdin_eof = 1;
0624ec
@@ -656,14 +656,14 @@ int read_socket(int recv_fd)
0624ec
             }
0624ec
 #endif
0624ec
             close(recv_fd);
0624ec
-            FD_CLR(recv_fd, &master_readfds);
0624ec
+            checked_fd_clr(recv_fd, &master_readfds);
0624ec
             rm_fd(&client_fdlist, recv_fd);
0624ec
-            FD_CLR(recv_fd, &master_broadcastfds);
0624ec
+            checked_fd_clr(recv_fd, &master_broadcastfds);
0624ec
             rm_fd(&broadcast_fdlist, recv_fd);
0624ec
 
0624ec
             conn_inc--;
0624ec
             if (get_conn_count() == 0)
0624ec
-                FD_CLR(STDIN_FILENO, &master_readfds);
0624ec
+                checked_fd_clr(STDIN_FILENO, &master_readfds);
0624ec
 
0624ec
             return n;
0624ec
         }
0624ec
@@ -753,7 +753,7 @@ static int ncat_listen_dgram(int proto)
0624ec
                 logdebug("do_listen(\"%s\"): %s\n", inet_ntop_ez(&listenaddrs[i].storage, sizeof(listenaddrs[i].storage)), socket_strerror(socket_errno()));
0624ec
             continue;
0624ec
         }
0624ec
-        FD_SET(sockfd[num_sockets].fd, &listen_fds);
0624ec
+        checked_fd_set(sockfd[num_sockets].fd, &listen_fds);
0624ec
         add_fd(&listen_fdlist, sockfd[num_sockets].fd);
0624ec
         sockfd[num_sockets].addr = listenaddrs[i];
0624ec
         num_sockets++;
0624ec
@@ -773,14 +773,14 @@ static int ncat_listen_dgram(int proto)
0624ec
 
0624ec
         if (fdn != -1) {
0624ec
             /*remove socket descriptor which is burnt */
0624ec
-            FD_CLR(sockfd[fdn].fd, &listen_fds);
0624ec
+            checked_fd_clr(sockfd[fdn].fd, &listen_fds);
0624ec
             rm_fd(&listen_fdlist, sockfd[fdn].fd);
0624ec
 
0624ec
             /* Rebuild the udp socket which got burnt */
0624ec
             sockfd[fdn].fd = do_listen(SOCK_DGRAM, proto, &sockfd[fdn].addr);
0624ec
             if (sockfd[fdn].fd == -1)
0624ec
                 bye("do_listen: %s", socket_strerror(socket_errno()));
0624ec
-            FD_SET(sockfd[fdn].fd, &listen_fds);
0624ec
+            checked_fd_set(sockfd[fdn].fd, &listen_fds);
0624ec
             add_fd(&listen_fdlist, sockfd[fdn].fd);
0624ec
 
0624ec
         }
0624ec
@@ -818,7 +818,7 @@ static int ncat_listen_dgram(int proto)
0624ec
              */
0624ec
             for (i = 0; i <= listen_fdlist.fdmax && fds_ready > 0; i++) {
0624ec
                 /* Loop through descriptors until there is something ready */
0624ec
-                if (!FD_ISSET(i, &fds))
0624ec
+                if (!checked_fd_isset(i, &fds))
0624ec
                     continue;
0624ec
 
0624ec
                 /* Check each listening socket */
0624ec
@@ -905,8 +905,8 @@ static int ncat_listen_dgram(int proto)
0624ec
             continue;
0624ec
         }
0624ec
 
0624ec
-        FD_SET(socket_n, &read_fds);
0624ec
-        FD_SET(STDIN_FILENO, &read_fds);
0624ec
+        checked_fd_set(socket_n, &read_fds);
0624ec
+        checked_fd_set(STDIN_FILENO, &read_fds);
0624ec
         fdmax = socket_n;
0624ec
 
0624ec
         /* stdin -> socket and socket -> stdout */
0624ec
@@ -926,7 +926,7 @@ static int ncat_listen_dgram(int proto)
0624ec
             if (fds_ready == 0)
0624ec
                 bye("Idle timeout expired (%d ms).", o.idletimeout);
0624ec
 
0624ec
-            if (FD_ISSET(STDIN_FILENO, &fds)) {
0624ec
+            if (checked_fd_isset(STDIN_FILENO, &fds)) {
0624ec
                 nbytes = Read(STDIN_FILENO, buf, sizeof(buf));
0624ec
                 if (nbytes <= 0) {
0624ec
                     if (nbytes < 0 && o.verbose) {
0624ec
@@ -934,7 +934,7 @@ static int ncat_listen_dgram(int proto)
0624ec
                     } else if (nbytes == 0 && o.debug) {
0624ec
                         logdebug("EOF on stdin\n");
0624ec
                     }
0624ec
-                    FD_CLR(STDIN_FILENO, &read_fds);
0624ec
+                    checked_fd_clr(STDIN_FILENO, &read_fds);
0624ec
                     if (nbytes < 0)
0624ec
                         return 1;
0624ec
                     continue;
0624ec
@@ -958,7 +958,7 @@ static int ncat_listen_dgram(int proto)
0624ec
                     tempbuf = NULL;
0624ec
                 }
0624ec
             }
0624ec
-            if (FD_ISSET(socket_n, &fds)) {
0624ec
+            if (checked_fd_isset(socket_n, &fds)) {
0624ec
                 nbytes = recv(socket_n, buf, sizeof(buf), 0);
0624ec
                 if (nbytes < 0) {
0624ec
                     loguser("%s.\n", socket_strerror(socket_errno()));
0624ec
@@ -1034,7 +1034,7 @@ static void read_and_broadcast(int recv_fd)
0624ec
 
0624ec
                 /* Don't close the file because that allows a socket to be
0624ec
                    fd 0. */
0624ec
-                FD_CLR(recv_fd, &master_readfds);
0624ec
+                checked_fd_clr(recv_fd, &master_readfds);
0624ec
                 /* But mark that we've seen EOF so it doesn't get re-added to
0624ec
                    the select list. */
0624ec
                 stdin_eof = 1;
0624ec
@@ -1061,14 +1061,14 @@ static void read_and_broadcast(int recv_fd)
0624ec
                 }
0624ec
 #endif
0624ec
                 close(recv_fd);
0624ec
-                FD_CLR(recv_fd, &master_readfds);
0624ec
+                checked_fd_clr(recv_fd, &master_readfds);
0624ec
                 rm_fd(&client_fdlist, recv_fd);
0624ec
-                FD_CLR(recv_fd, &master_broadcastfds);
0624ec
+                checked_fd_clr(recv_fd, &master_broadcastfds);
0624ec
                 rm_fd(&broadcast_fdlist, recv_fd);
0624ec
 
0624ec
                 conn_inc--;
0624ec
                 if (conn_inc == 0)
0624ec
-                    FD_CLR(STDIN_FILENO, &master_readfds);
0624ec
+                    checked_fd_clr(STDIN_FILENO, &master_readfds);
0624ec
 
0624ec
                 if (o.chat)
0624ec
                     chat_announce_disconnect(recv_fd);
0624ec
@@ -1099,7 +1099,7 @@ static void read_and_broadcast(int recv_fd)
0624ec
 
0624ec
         /* Send to everyone except the one who sent this message. */
0624ec
         broadcastfds = master_broadcastfds;
0624ec
-        FD_CLR(recv_fd, &broadcastfds);
0624ec
+        checked_fd_clr(recv_fd, &broadcastfds);
0624ec
         ncat_broadcast(&broadcastfds, &broadcast_fdlist, outbuf, n);
0624ec
 
0624ec
         free(chatbuf);
0624ec
@@ -1114,7 +1114,7 @@ static void shutdown_sockets(int how)
0624ec
     int i;
0624ec
 
0624ec
     for (i = 0; i <= broadcast_fdlist.fdmax; i++) {
0624ec
-        if (!FD_ISSET(i, &master_broadcastfds))
0624ec
+        if (!checked_fd_isset(i, &master_broadcastfds))
0624ec
             continue;
0624ec
 
0624ec
         fdn = get_fdinfo(&broadcast_fdlist, i);
0624ec
@@ -1139,7 +1139,7 @@ static int chat_announce_connect(int fd, const union sockaddr_u *su)
0624ec
         union sockaddr_u su;
0624ec
         socklen_t len = sizeof(su.storage);
0624ec
 
0624ec
-        if (i == fd || !FD_ISSET(i, &master_broadcastfds))
0624ec
+        if (i == fd || !checked_fd_isset(i, &master_broadcastfds))
0624ec
             continue;
0624ec
 
0624ec
         if (getpeername(i, &su.sockaddr, &len) == -1)
0624ec
diff --git a/ncat/ncat_posix.c b/ncat/ncat_posix.c
0624ec
index 3b01936..59e801e 100644
0624ec
--- a/ncat/ncat_posix.c
0624ec
+++ b/ncat/ncat_posix.c
0624ec
@@ -273,8 +273,8 @@ void netexec(struct fdinfo *info, char *cmdexec)
0624ec
         int r, n_r;
0624ec
 
0624ec
         FD_ZERO(&fds);
0624ec
-        FD_SET(info->fd, &fds);
0624ec
-        FD_SET(child_stdout[0], &fds);
0624ec
+        checked_fd_set(info->fd, &fds);
0624ec
+        checked_fd_set(child_stdout[0], &fds);
0624ec
 
0624ec
         r = fselect(maxfd + 1, &fds, NULL, NULL, NULL);
0624ec
         if (r == -1) {
0624ec
@@ -283,7 +283,7 @@ void netexec(struct fdinfo *info, char *cmdexec)
0624ec
             else
0624ec
                 break;
0624ec
         }
0624ec
-        if (FD_ISSET(info->fd, &fds)) {
0624ec
+        if (checked_fd_isset(info->fd, &fds)) {
0624ec
             int pending;
0624ec
 
0624ec
             do {
0624ec
@@ -293,7 +293,7 @@ void netexec(struct fdinfo *info, char *cmdexec)
0624ec
                 write_loop(child_stdin[1], buf, n_r);
0624ec
             } while (pending);
0624ec
         }
0624ec
-        if (FD_ISSET(child_stdout[0], &fds)) {
0624ec
+        if (checked_fd_isset(child_stdout[0], &fds)) {
0624ec
             char *crlf = NULL, *wbuf;
0624ec
             n_r = read(child_stdout[0], buf, sizeof(buf));
0624ec
             if (n_r <= 0)
0624ec
diff --git a/ncat/ncat_proxy.c b/ncat/ncat_proxy.c
0624ec
index d7227fc..e060e3e 100644
0624ec
--- a/ncat/ncat_proxy.c
0624ec
+++ b/ncat/ncat_proxy.c
0624ec
@@ -234,7 +234,7 @@ int ncat_http_server(void)
0624ec
         unblock_socket(listen_socket[num_sockets]);
0624ec
 
0624ec
         /* setup select sets and max fd */
0624ec
-        FD_SET(listen_socket[num_sockets], &listen_fds);
0624ec
+        checked_fd_set(listen_socket[num_sockets], &listen_fds);
0624ec
         add_fd(&listen_fdlist, listen_socket[num_sockets]);
0624ec
 
0624ec
         num_sockets++;
0624ec
@@ -267,7 +267,7 @@ int ncat_http_server(void)
0624ec
 
0624ec
         for (i = 0; i <= listen_fdlist.fdmax && fds_ready > 0; i++) {
0624ec
             /* Loop through descriptors until there is something ready */
0624ec
-            if (!FD_ISSET(i, &read_fds))
0624ec
+            if (!checked_fd_isset(i, &read_fds))
0624ec
                 continue;
0624ec
 
0624ec
             /* Check each listening socket */
0624ec
@@ -525,8 +525,8 @@ static int handle_connect(struct socket_buffer *client_sock,
0624ec
 
0624ec
     maxfd = client_sock->fdn.fd < s ? s : client_sock->fdn.fd;
0624ec
     FD_ZERO(&m);
0624ec
-    FD_SET(client_sock->fdn.fd, &m);
0624ec
-    FD_SET(s, &m);
0624ec
+    checked_fd_set(client_sock->fdn.fd, &m);
0624ec
+    checked_fd_set(s, &m);
0624ec
 
0624ec
     errno = 0;
0624ec
 
0624ec
@@ -540,7 +540,7 @@ static int handle_connect(struct socket_buffer *client_sock,
0624ec
 
0624ec
         zmem(buf, sizeof(buf));
0624ec
 
0624ec
-        if (FD_ISSET(client_sock->fdn.fd, &r)) {
0624ec
+        if (checked_fd_isset(client_sock->fdn.fd, &r)) {
0624ec
             do {
0624ec
                 do {
0624ec
                     len = fdinfo_recv(&client_sock->fdn, buf, sizeof(buf));
0624ec
@@ -556,7 +556,7 @@ static int handle_connect(struct socket_buffer *client_sock,
0624ec
             } while (fdinfo_pending(&client_sock->fdn));
0624ec
         }
0624ec
 
0624ec
-        if (FD_ISSET(s, &r)) {
0624ec
+        if (checked_fd_isset(s, &r)) {
0624ec
             do {
0624ec
                 len = recv(s, buf, sizeof(buf), 0);
0624ec
             } while (len == -1 && socket_errno() == EINTR);