X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=networking%2Fnc_bloaty.c;h=9aaeec100a27702c9a61a47332bfafd4a5de7523;hb=ed1667e8ee91243b77b02cc4f160fe4b80a30385;hp=dd94a14605d12e8149b8d02c3dd853bd18a42202;hpb=1d42665b6b0571b9fa5d3b10fbf2dd03382f0ba2;p=oweals%2Fbusybox.git diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c index dd94a1460..9aaeec100 100644 --- a/networking/nc_bloaty.c +++ b/networking/nc_bloaty.c @@ -177,7 +177,7 @@ static void unarm(void) } /* timeout and other signal handling cruft */ -static void tmtravel(int sig ATTRIBUTE_UNUSED) +static void tmtravel(int sig UNUSED_PARAM) { unarm(); longjmp(jbuf, 1); @@ -222,7 +222,7 @@ Debug("findline returning whole thing: %d", siz); that would be security-critical, which is why it's ifdefed out by default. Use at your own hairy risk; if you leave shells lying around behind open listening ports you deserve to lose!! */ -static int doexec(char **proggie) ATTRIBUTE_NORETURN; +static int doexec(char **proggie) NORETURN; static int doexec(char **proggie) { xmove_fd(netfd, 0); @@ -278,9 +278,9 @@ static void dolisten(void) random unknown port is probably not very useful without "netstat". */ if (o_verbose) { char *addr; - rr = getsockname(netfd, &ouraddr->u.sa, &ouraddr->len); - if (rr < 0) - bb_perror_msg_and_die("getsockname after bind"); + getsockname(netfd, &ouraddr->u.sa, &ouraddr->len); + //if (rr < 0) + // bb_perror_msg_and_die("getsockname after bind"); addr = xmalloc_sockaddr2dotted(&ouraddr->u.sa); fprintf(stderr, "listening on %s ...\n", addr); free(addr); @@ -359,9 +359,9 @@ create new one, and bind() it. TODO */ doing a listen-on-any on a multihomed machine. This allows one to offer different services via different alias addresses, such as the "virtual web site" hack. */ - rr = getsockname(netfd, &ouraddr->u.sa, &ouraddr->len); - if (rr < 0) - bb_perror_msg_and_die("getsockname after accept"); + getsockname(netfd, &ouraddr->u.sa, &ouraddr->len); + //if (rr < 0) + // bb_perror_msg_and_die("getsockname after accept"); } if (o_verbose) { @@ -374,12 +374,10 @@ create new one, and bind() it. TODO */ thing to emerge after all the intervening crud. Doesn't work for UDP on any machines I've tested, but feel free to surprise me. */ char optbuf[40]; - int x = sizeof(optbuf); + socklen_t x = sizeof(optbuf); rr = getsockopt(netfd, IPPROTO_IP, IP_OPTIONS, optbuf, &x); - if (rr < 0) - bb_perror_msg("getsockopt failed"); - else if (x) { /* we've got options, lessee em... */ + if (rr >= 0 && x) { /* we've got options, lessee em... */ bin2hex(bigbuf_net, optbuf, x); bigbuf_net[2*x] = '\0'; fprintf(stderr, "IP options: %s\n", bigbuf_net); @@ -487,7 +485,7 @@ static void oprint(int direction, unsigned char *p, unsigned bc) memset(&stage[11], ' ', 16*3); x = bc; } - sprintf(&stage[1], " %8.8x ", obc); /* xxx: still slow? */ + sprintf((char *)&stage[1], " %8.8x ", obc); /* xxx: still slow? */ bc -= x; /* fix current count */ obc += x; /* fix current offset */ op = &stage[11]; /* where hex starts */ @@ -562,7 +560,7 @@ static int readwrite(void) /* if we have a timeout AND stdin is closed AND we haven't heard anything from the net during that time, assume it's dead and close it too. */ if (rr == 0) { - if (!FD_ISSET(0, &ding1)) + if (!FD_ISSET(STDIN_FILENO, &ding1)) netretry--; /* we actually try a coupla times. */ if (!netretry) { if (o_verbose > 1) /* normally we don't care */ @@ -597,13 +595,16 @@ Debug("got %d from the net, errno %d", rr, errno); goto shovel; /* okay, suck more stdin */ - if (FD_ISSET(0, &ding2)) { /* stdin: ding! */ - rr = read(0, bigbuf_in, BIGSIZ); + if (FD_ISSET(STDIN_FILENO, &ding2)) { /* stdin: ding! */ + rr = read(STDIN_FILENO, bigbuf_in, BIGSIZ); /* Considered making reads here smaller for UDP mode, but 8192-byte mobygrams are kinda fun and exercise the reassembler. */ if (rr <= 0) { /* at end, or fukt, or ... */ - FD_CLR(0, &ding1); /* disable and close stdin */ - close(0); + FD_CLR(STDIN_FILENO, &ding1); /* disable and close stdin */ + close(STDIN_FILENO); +// Does it make sense to shutdown(net_fd, SHUT_WR) +// to let other side know that we won't write anything anymore? +// (and what about keeping compat if we do that?) } else { rzleft = rr; zp = bigbuf_in; @@ -625,10 +626,10 @@ Debug("got %d from the net, errno %d", rr, errno); return 1; } if (rnleft) { - rr = write(1, np, rnleft); + rr = write(STDOUT_FILENO, np, rnleft); if (rr > 0) { - if (o_ofile) - oprint('<', np, rr); /* log the stdout */ + if (o_ofile) /* log the stdout */ + oprint('<', (unsigned char *)np, rr); np += rr; /* fix up ptrs and whatnot */ rnleft -= rr; /* will get sanity-checked above */ wrote_out += rr; /* global count */ @@ -642,8 +643,8 @@ Debug("wrote %d to stdout, errno %d", rr, errno); rr = rzleft; rr = write(netfd, zp, rr); /* one line, or the whole buffer */ if (rr > 0) { - if (o_ofile) - oprint('>', zp, rr); /* log what got sent */ + if (o_ofile) /* log what got sent */ + oprint('>', (unsigned char *)zp, rr); zp += rr; rzleft -= rr; wrote_net += rr; /* global count */ @@ -675,7 +676,7 @@ int nc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int nc_main(int argc, char **argv) { char *str_p, *str_s; - USE_NC_EXTRA(char *str_i, *str_o;) + IF_NC_EXTRA(char *str_i, *str_o;) char *themdotted = themdotted; /* gcc */ char **proggie; int x; @@ -711,10 +712,10 @@ int nc_main(int argc, char **argv) // -g -G -t -r deleted, unimplemented -a deleted too opt_complementary = "?2:vv:w+"; /* max 2 params; -v is a counter; -w N */ - getopt32(argv, "hnp:s:uvw:" USE_NC_SERVER("l") - USE_NC_EXTRA("i:o:z"), + getopt32(argv, "hnp:s:uvw:" IF_NC_SERVER("l") + IF_NC_EXTRA("i:o:z"), &str_p, &str_s, &o_wait - USE_NC_EXTRA(, &str_i, &str_o, &o_verbose)); + IF_NC_EXTRA(, &str_i, &str_o, &o_verbose)); argv += optind; #if ENABLE_NC_EXTRA if (option_mask32 & OPT_i) /* line-interval time */ @@ -768,7 +769,12 @@ int nc_main(int argc, char **argv) setsockopt_reuseaddr(netfd); if (o_udpmode) socket_want_pktinfo(netfd); - xbind(netfd, &ouraddr->u.sa, ouraddr->len); + if (!ENABLE_FEATURE_UNIX_LOCAL + || o_listen + || ouraddr->u.sa.sa_family != AF_UNIX + ) { + xbind(netfd, &ouraddr->u.sa, ouraddr->len); + } #if 0 setsockopt(netfd, SOL_SOCKET, SO_RCVBUF, &o_rcvbuf, sizeof o_rcvbuf); setsockopt(netfd, SOL_SOCKET, SO_SNDBUF, &o_sndbuf, sizeof o_sndbuf); @@ -783,7 +789,7 @@ int nc_main(int argc, char **argv) } #endif - FD_SET(0, &ding1); /* stdin *is* initially open */ + FD_SET(STDIN_FILENO, &ding1); /* stdin *is* initially open */ if (proggie) { close(0); /* won't need stdin */ option_mask32 &= ~OPT_o; /* -o with -e is meaningless! */