diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-08 12:49:22 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-08 12:49:22 +0000 |
commit | 1385899416a4396385ad421ae1f532be7103738a (patch) | |
tree | fc4d14a910593d1235318bb36abe5e9f72d2039e /networking/nc.c | |
parent | 5625415085e68ac5e150f54e685417c866620d76 (diff) | |
download | busybox-w32-1385899416a4396385ad421ae1f532be7103738a.tar.gz busybox-w32-1385899416a4396385ad421ae1f532be7103738a.tar.bz2 busybox-w32-1385899416a4396385ad421ae1f532be7103738a.zip |
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 f8b3fb2dd..bde5e6600 100644 --- a/networking/nc.c +++ b/networking/nc.c | |||
@@ -11,13 +11,15 @@ | |||
11 | 11 | ||
12 | static void timeout(int signum) | 12 | static void timeout(int signum) |
13 | { | 13 | { |
14 | bb_error_msg_and_die("Timed out"); | 14 | bb_error_msg_and_die("timed out"); |
15 | } | 15 | } |
16 | 16 | ||
17 | int nc_main(int argc, char **argv) | 17 | int nc_main(int argc, char **argv) |
18 | { | 18 | { |
19 | int do_listen = 0, lport = 0, delay = 0, wsecs = 0, execflag = 0, opt, | 19 | int sfd = 0, cfd; |
20 | sfd = 0, cfd; | 20 | unsigned opt; |
21 | unsigned lport = 0, wsecs = 0, delay = 0; | ||
22 | unsigned do_listen = 0, execflag = 0; | ||
21 | struct sockaddr_in address; | 23 | struct sockaddr_in address; |
22 | struct hostent *hostinfo; | 24 | struct hostent *hostinfo; |
23 | fd_set readfds, testfds; | 25 | fd_set readfds, testfds; |
@@ -30,8 +32,8 @@ int nc_main(int argc, char **argv) | |||
30 | if (ENABLE_NC_SERVER && opt=='l') do_listen++; | 32 | if (ENABLE_NC_SERVER && opt=='l') do_listen++; |
31 | else if (ENABLE_NC_SERVER && opt=='p') | 33 | else if (ENABLE_NC_SERVER && opt=='p') |
32 | lport = bb_lookup_port(optarg, "tcp", 0); | 34 | lport = bb_lookup_port(optarg, "tcp", 0); |
33 | else if (ENABLE_NC_EXTRA && opt=='w') wsecs = atoi(optarg); | 35 | else if (ENABLE_NC_EXTRA && opt=='w') wsecs = xatou(optarg); |
34 | else if (ENABLE_NC_EXTRA && opt=='i') delay = atoi(optarg); | 36 | else if (ENABLE_NC_EXTRA && opt=='i') delay = xatou(optarg); |
35 | else if (ENABLE_NC_EXTRA && opt=='f') infile = optarg; | 37 | else if (ENABLE_NC_EXTRA && opt=='f') infile = optarg; |
36 | else if (ENABLE_NC_EXTRA && opt=='e' && optind!=argc) { | 38 | else if (ENABLE_NC_EXTRA && opt=='e' && optind!=argc) { |
37 | execflag++; | 39 | execflag++; |
@@ -40,11 +42,10 @@ int nc_main(int argc, char **argv) | |||
40 | } | 42 | } |
41 | } | 43 | } |
42 | 44 | ||
43 | |||
44 | // For listen or file we need zero arguments, dialout is 2. | 45 | // For listen or file we need zero arguments, dialout is 2. |
45 | // For exec we need at least one more argument at the end, more ok | 46 | // For exec we need at least one more argument at the end, more ok |
46 | 47 | ||
47 | opt = (do_listen || infile) ? 0 : 2 + execflag; | 48 | opt = (do_listen || infile) ? 0 : 2 + execflag; |
48 | if (execflag ? argc-optind < opt : argc-optind!=opt || | 49 | if (execflag ? argc-optind < opt : argc-optind!=opt || |
49 | (infile && do_listen)) | 50 | (infile && do_listen)) |
50 | bb_show_usage(); | 51 | bb_show_usage(); |
@@ -66,7 +67,6 @@ int nc_main(int argc, char **argv) | |||
66 | 67 | ||
67 | if (lport != 0) { | 68 | if (lport != 0) { |
68 | address.sin_port = lport; | 69 | address.sin_port = lport; |
69 | |||
70 | xbind(sfd, (struct sockaddr *) &address, sizeof(address)); | 70 | xbind(sfd, (struct sockaddr *) &address, sizeof(address)); |
71 | } | 71 | } |
72 | 72 | ||
@@ -83,7 +83,8 @@ int nc_main(int argc, char **argv) | |||
83 | fdprintf(2, "%d\n", SWAP_BE16(address.sin_port)); | 83 | fdprintf(2, "%d\n", SWAP_BE16(address.sin_port)); |
84 | } | 84 | } |
85 | repeatyness: | 85 | repeatyness: |
86 | if ((cfd = accept(sfd, (struct sockaddr *) &address, &addrlen)) < 0) | 86 | cfd = accept(sfd, (struct sockaddr *) &address, &addrlen); |
87 | if (cfd < 0) | ||
87 | bb_perror_msg_and_die("accept"); | 88 | bb_perror_msg_and_die("accept"); |
88 | 89 | ||
89 | if (!execflag) close(sfd); | 90 | if (!execflag) close(sfd); |
@@ -116,10 +117,11 @@ repeatyness: | |||
116 | 117 | ||
117 | // With more than one -l, repeatedly act as server. | 118 | // With more than one -l, repeatedly act as server. |
118 | 119 | ||
119 | if (do_listen>1 && vfork()) { | 120 | if (do_listen > 1 && vfork()) { |
120 | // This is a bit weird as cleanup goes, since we wind up with no | 121 | // This is a bit weird as cleanup goes, since we wind up with no |
121 | // stdin/stdout/stderr. But it's small and shouldn't hurt anything. | 122 | // stdin/stdout/stderr. But it's small and shouldn't hurt anything. |
122 | // We check for cfd == 0 above. | 123 | // We check for cfd == 0 above. |
124 | logmode = LOGMODE_NONE; | ||
123 | close(0); | 125 | close(0); |
124 | close(1); | 126 | close(1); |
125 | close(2); | 127 | close(2); |