*
* 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
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 */
FD_SET(cfd, &readfds);
FD_SET(STDIN_FILENO, &readfds);
+#define iobuf bb_common_bufsiz1
+ setup_common_bufsiz();
for (;;) {
int fd;
int ofd;
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);
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;