Missing dependency spotted by Robert P Day.
[oweals/busybox.git] / networking / nc.c
index bb6373fd3e51d29202f2aca67d8f006802f78203..85148c4a713be973ae535e64af84c5c7dcfc6578 100644 (file)
@@ -48,7 +48,9 @@ static void timeout(int signum)
 int nc_main(int argc, char **argv)
 {
        int do_listen = 0, lport = 0, delay = 0, wsecs = 0, tmpfd, opt, sfd, x;
-       char buf[BUFSIZ];
+
+#define buf bb_common_bufsiz1
+
 #ifdef CONFIG_NC_GAPING_SECURITY_HOLE
        char *pr00gie = NULL;
 #endif
@@ -82,21 +84,14 @@ int nc_main(int argc, char **argv)
                }
        }
 
-#ifdef CONFIG_NC_GAPING_SECURITY_HOLE
-       if (pr00gie) {
-               /* won't need stdin */
-               close (STDIN_FILENO);      
-       }
-#endif /* CONFIG_NC_GAPING_SECURITY_HOLE */
-
        if ((do_listen && optind != argc) || (!do_listen && optind + 2 != argc))
                bb_show_usage();
 
        if ((sfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
                bb_perror_msg_and_die("socket");
        x = 1;
-       if (setsockopt (sfd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof (x)) == -1)
-               bb_perror_msg_and_die ("reuseaddr failed");
+       if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof (x)) == -1)
+               bb_perror_msg_and_die("reuseaddr");
        address.sin_family = AF_INET;
 
        if (wsecs) {
@@ -168,20 +163,23 @@ int nc_main(int argc, char **argv)
                for (fd = 0; fd < FD_SETSIZE; fd++) {
                        if (FD_ISSET(fd, &testfds)) {
                                if ((nread = safe_read(fd, buf, sizeof(buf))) < 0)
-                                       bb_perror_msg_and_die("read");
+                                       bb_perror_msg_and_die(bb_msg_read_error);
 
                                if (fd == sfd) {
                                        if (nread == 0)
                                                exit(0);
                                        ofd = STDOUT_FILENO;
                                } else {
-                                       if (nread == 0)
-                                               shutdown(sfd, 1);
+                                       if (nread <= 0) {
+                                               shutdown(sfd, 1 /* send */ );
+                                               close(STDIN_FILENO);
+                                               FD_CLR(STDIN_FILENO, &readfds);
+                                       }
                                        ofd = sfd;
                                }
 
                                if (bb_full_write(ofd, buf, nread) < 0)
-                                       bb_perror_msg_and_die("write");
+                                       bb_perror_msg_and_die(bb_msg_write_error);
                                if (delay > 0) {
                                        sleep(delay);
                                }