httpd: fix handling of range requests
[oweals/busybox.git] / networking / nc.c
index 8cb4b306e39d92605ef07627d31c037a99a734e4..1b70434ac3f3d1de0e9bd02f85b4a055151419c4 100644 (file)
@@ -6,9 +6,6 @@
  *
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
-
-#include "libbb.h"
-
 //config:config NC
 //config:      bool "nc"
 //config:      default y
 //config:        This option makes nc closely follow original nc-1.10.
 //config:        The code is about 2.5k bigger. It enables
 //config:        -s ADDR, -n, -u, -v, -o FILE, -z options, but loses
-//config:        busybox-specific extensions: -f FILE and -ll.
+//config:        busybox-specific extensions: -f FILE.
+
+//applet:IF_NC(APPLET(nc, BB_DIR_USR_BIN, BB_SUID_DROP))
 
+//kbuild:lib-$(CONFIG_NC) += nc.o
+
+#include "libbb.h"
+#include "common_bufsiz.h"
 #if ENABLE_NC_110_COMPAT
 # include "nc_bloaty.c"
 #else
@@ -229,7 +232,7 @@ int nc_main(int argc, char **argv)
                xdup2(0, 1);
                /*xdup2(0, 2); - original nc 1.10 does this, we don't */
                IF_NC_EXTRA(BB_EXECVP(execparam[0], execparam);)
-               bb_perror_msg_and_die("can't execute '%s'", execparam[0]);
+               IF_NC_EXTRA(bb_perror_msg_and_die("can't execute '%s'", execparam[0]);)
        }
 
        /* Select loop copying stdin to cfd, and cfd to stdout */
@@ -238,6 +241,8 @@ int nc_main(int argc, char **argv)
        FD_SET(cfd, &readfds);
        FD_SET(STDIN_FILENO, &readfds);
 
+#define iobuf bb_common_bufsiz1
+       setup_common_bufsiz();
        for (;;) {
                int fd;
                int ofd;
@@ -248,11 +253,10 @@ int nc_main(int argc, char **argv)
                if (select(cfd + 1, &testfds, NULL, NULL, NULL) < 0)
                        bb_perror_msg_and_die("select");
 
-#define iobuf bb_common_bufsiz1
                fd = STDIN_FILENO;
                while (1) {
                        if (FD_ISSET(fd, &testfds)) {
-                               nread = safe_read(fd, iobuf, sizeof(iobuf));
+                               nread = safe_read(fd, iobuf, COMMON_BUFSIZE);
                                if (fd == cfd) {
                                        if (nread < 1)
                                                exit(EXIT_SUCCESS);
@@ -261,7 +265,7 @@ int nc_main(int argc, char **argv)
                                        if (nread < 1) {
                                                /* Close outgoing half-connection so they get EOF,
                                                 * but leave incoming alone so we can see response */
-                                               shutdown(cfd, 1);
+                                               shutdown(cfd, SHUT_WR);
                                                FD_CLR(STDIN_FILENO, &readfds);
                                        }
                                        ofd = cfd;