diff options
author | Denis Vlasenko | 2006-10-08 12:49:22 +0000 |
---|---|---|
committer | Denis Vlasenko | 2006-10-08 12:49:22 +0000 |
commit | 1385899416a4396385ad421ae1f532be7103738a (patch) | |
tree | fc4d14a910593d1235318bb36abe5e9f72d2039e /networking/nc.c | |
parent | 5625415085e68ac5e150f54e685417c866620d76 (diff) | |
download | busybox-1385899416a4396385ad421ae1f532be7103738a.zip busybox-1385899416a4396385ad421ae1f532be7103738a.tar.gz |
attempt to regularize atoi mess.
Diffstat (limited to 'networking/nc.c')
-rw-r--r-- | networking/nc.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/networking/nc.c b/networking/nc.c index f8b3fb2..bde5e66 100644 --- a/networking/nc.c +++ b/networking/nc.c @@ -11,13 +11,15 @@ static void timeout(int signum) { - bb_error_msg_and_die("Timed out"); + bb_error_msg_and_die("timed out"); } int nc_main(int argc, char **argv) { - int do_listen = 0, lport = 0, delay = 0, wsecs = 0, execflag = 0, opt, - sfd = 0, cfd; + int sfd = 0, cfd; + unsigned opt; + unsigned lport = 0, wsecs = 0, delay = 0; + unsigned do_listen = 0, execflag = 0; struct sockaddr_in address; struct hostent *hostinfo; fd_set readfds, testfds; @@ -30,8 +32,8 @@ int nc_main(int argc, char **argv) if (ENABLE_NC_SERVER && opt=='l') do_listen++; else if (ENABLE_NC_SERVER && opt=='p') lport = bb_lookup_port(optarg, "tcp", 0); - else if (ENABLE_NC_EXTRA && opt=='w') wsecs = atoi(optarg); - else if (ENABLE_NC_EXTRA && opt=='i') delay = atoi(optarg); + else if (ENABLE_NC_EXTRA && opt=='w') wsecs = xatou(optarg); + else if (ENABLE_NC_EXTRA && opt=='i') delay = xatou(optarg); else if (ENABLE_NC_EXTRA && opt=='f') infile = optarg; else if (ENABLE_NC_EXTRA && opt=='e' && optind!=argc) { execflag++; @@ -40,11 +42,10 @@ int nc_main(int argc, char **argv) } } - // For listen or file we need zero arguments, dialout is 2. // For exec we need at least one more argument at the end, more ok - opt = (do_listen || infile) ? 0 : 2 + execflag; + opt = (do_listen || infile) ? 0 : 2 + execflag; if (execflag ? argc-optind < opt : argc-optind!=opt || (infile && do_listen)) bb_show_usage(); @@ -66,7 +67,6 @@ int nc_main(int argc, char **argv) if (lport != 0) { address.sin_port = lport; - xbind(sfd, (struct sockaddr *) &address, sizeof(address)); } @@ -83,7 +83,8 @@ int nc_main(int argc, char **argv) fdprintf(2, "%d\n", SWAP_BE16(address.sin_port)); } repeatyness: - if ((cfd = accept(sfd, (struct sockaddr *) &address, &addrlen)) < 0) + cfd = accept(sfd, (struct sockaddr *) &address, &addrlen); + if (cfd < 0) bb_perror_msg_and_die("accept"); if (!execflag) close(sfd); @@ -116,10 +117,11 @@ repeatyness: // With more than one -l, repeatedly act as server. - if (do_listen>1 && vfork()) { + if (do_listen > 1 && vfork()) { // This is a bit weird as cleanup goes, since we wind up with no // stdin/stdout/stderr. But it's small and shouldn't hurt anything. // We check for cfd == 0 above. + logmode = LOGMODE_NONE; close(0); close(1); close(2); |