diff options
author | ericj <> | 2000-09-26 17:46:40 +0000 |
---|---|---|
committer | ericj <> | 2000-09-26 17:46:40 +0000 |
commit | afba3ddf77a34cc5915c1fd95dff2d4babc98a81 (patch) | |
tree | 57f1456887c26724ea159e2b501fe1b6a01d8d6b /src/usr.bin | |
parent | dd6ae19c0716cf528026ca34ac6ea68fcc075eaa (diff) | |
download | openbsd-afba3ddf77a34cc5915c1fd95dff2d4babc98a81.tar.gz openbsd-afba3ddf77a34cc5915c1fd95dff2d4babc98a81.tar.bz2 openbsd-afba3ddf77a34cc5915c1fd95dff2d4babc98a81.zip |
no need to reset h_errno
do the cmdline correctly, deal with \n and \t
fix up nlog()
use arc4random instead of srandom()/random()
Diffstat (limited to 'src/usr.bin')
-rw-r--r-- | src/usr.bin/nc/netcat.c | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index e24a807743..cc62f4a683 100644 --- a/src/usr.bin/nc/netcat.c +++ b/src/usr.bin/nc/netcat.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: netcat.c,v 1.15 2000/09/26 05:19:37 ericj Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.16 2000/09/26 17:46:40 ericj Exp $ */ |
2 | 2 | ||
3 | /* Netcat 1.10 RELEASE 960320 | 3 | /* Netcat 1.10 RELEASE 960320 |
4 | * | 4 | * |
@@ -51,10 +51,6 @@ | |||
51 | #include <stdlib.h> | 51 | #include <stdlib.h> |
52 | #include <unistd.h> | 52 | #include <unistd.h> |
53 | 53 | ||
54 | /* Random Numbers aren't too needed here */ | ||
55 | #define SRAND srandom | ||
56 | #define RAND random | ||
57 | |||
58 | #define SLEAZE_PORT 31337 /* for UDP-scan RTT trick, change if ya want */ | 54 | #define SLEAZE_PORT 31337 /* for UDP-scan RTT trick, change if ya want */ |
59 | #define BIGSIZ 8192 /* big buffers */ | 55 | #define BIGSIZ 8192 /* big buffers */ |
60 | 56 | ||
@@ -76,8 +72,6 @@ int jval = 0; /* timer crud */ | |||
76 | int netfd = -1; | 72 | int netfd = -1; |
77 | int ofd = 0; /* hexdump output fd */ | 73 | int ofd = 0; /* hexdump output fd */ |
78 | 74 | ||
79 | /* extern int h_errno; */ | ||
80 | |||
81 | int gatesidx = 0; /* LSRR hop count */ | 75 | int gatesidx = 0; /* LSRR hop count */ |
82 | int gatesptr = 4; /* initial LSRR pointer, settable */ | 76 | int gatesptr = 4; /* initial LSRR pointer, settable */ |
83 | u_short Single = 1; /* zero if scanning */ | 77 | u_short Single = 1; /* zero if scanning */ |
@@ -206,7 +200,6 @@ comparehosts(hinfo, hp) | |||
206 | struct hostent *hp; | 200 | struct hostent *hp; |
207 | { | 201 | { |
208 | errno = 0; | 202 | errno = 0; |
209 | h_errno = 0; | ||
210 | if (strcasecmp(hinfo->name, hp->h_name) != 0) { | 203 | if (strcasecmp(hinfo->name, hp->h_name) != 0) { |
211 | nlog(0, "DNS fwd/rev mismatch: %s != %s", hinfo->name, hp->h_name); | 204 | nlog(0, "DNS fwd/rev mismatch: %s != %s", hinfo->name, hp->h_name); |
212 | return (1); | 205 | return (1); |
@@ -232,7 +225,6 @@ gethinfo(name, numeric) | |||
232 | int x; | 225 | int x; |
233 | 226 | ||
234 | errno = 0; | 227 | errno = 0; |
235 | h_errno = 0; | ||
236 | if (name) | 228 | if (name) |
237 | hinfo = (struct host_info *) calloc(1, sizeof(struct host_info)); | 229 | hinfo = (struct host_info *) calloc(1, sizeof(struct host_info)); |
238 | 230 | ||
@@ -313,7 +305,6 @@ gethinfo(name, numeric) | |||
313 | * Whatever-all went down previously, we should now have a host_info | 305 | * Whatever-all went down previously, we should now have a host_info |
314 | * struct with at least one IP address in it. | 306 | * struct with at least one IP address in it. |
315 | */ | 307 | */ |
316 | h_errno = 0; | ||
317 | return (hinfo); | 308 | return (hinfo); |
318 | } | 309 | } |
319 | 310 | ||
@@ -421,7 +412,7 @@ nextport(block) | |||
421 | 412 | ||
422 | y = 70000; /* high safety count for rnd-tries */ | 413 | y = 70000; /* high safety count for rnd-tries */ |
423 | while (y > 0) { | 414 | while (y > 0) { |
424 | x = (RAND() & 0xffff); | 415 | x = (arc4random() & 0xffff); |
425 | if (block[x] == 1) { /* try to find a not-done one... */ | 416 | if (block[x] == 1) { /* try to find a not-done one... */ |
426 | block[x] = 2; | 417 | block[x] = 2; |
427 | break; | 418 | break; |
@@ -509,9 +500,6 @@ doconnect(rad, rp, lad, lp) | |||
509 | 500 | ||
510 | /* fill in all the right sockaddr crud */ | 501 | /* fill in all the right sockaddr crud */ |
511 | lclend->sin_family = AF_INET; | 502 | lclend->sin_family = AF_INET; |
512 | |||
513 | /* fill in all the right sockaddr crud */ | ||
514 | lclend->sin_family = AF_INET; | ||
515 | remend->sin_family = AF_INET; | 503 | remend->sin_family = AF_INET; |
516 | 504 | ||
517 | /* if lad/lp, do appropriate binding */ | 505 | /* if lad/lp, do appropriate binding */ |
@@ -1062,6 +1050,7 @@ shovel: | |||
1062 | 1050 | ||
1063 | /* main : | 1051 | /* main : |
1064 | now we pull it all together... */ | 1052 | now we pull it all together... */ |
1053 | int | ||
1065 | main(argc, argv) | 1054 | main(argc, argv) |
1066 | int argc; | 1055 | int argc; |
1067 | char **argv; | 1056 | char **argv; |
@@ -1091,7 +1080,6 @@ main(argc, argv) | |||
1091 | 1080 | ||
1092 | errno = 0; | 1081 | errno = 0; |
1093 | gatesptr = 4; | 1082 | gatesptr = 4; |
1094 | h_errno = 0; | ||
1095 | 1083 | ||
1096 | /* | 1084 | /* |
1097 | * We want to catch a few of these signals. | 1085 | * We want to catch a few of these signals. |
@@ -1108,17 +1096,21 @@ main(argc, argv) | |||
1108 | * and hand anything left over to readwrite(). | 1096 | * and hand anything left over to readwrite(). |
1109 | */ | 1097 | */ |
1110 | if (argc == 1) { | 1098 | if (argc == 1) { |
1111 | cp = argv[0]; | 1099 | /* Loop until we get a command to try */ |
1112 | /* XXX - 128 ? */ | 1100 | for (;;) { |
1113 | argv = (char **) calloc(1, 128 * sizeof(char *)); | 1101 | cp = argv[0]; |
1114 | argv[0] = cp; /* leave old prog name intact */ | 1102 | argv = (char **) calloc(1, 128 * sizeof(char *)); |
1115 | cp = calloc(1, BIGSIZ); | 1103 | argv[0] = cp; /* leave old prog name intact */ |
1116 | argv[1] = cp; /* head of new arg block */ | 1104 | cp = calloc(1, BIGSIZ); |
1117 | fprintf(stderr, "Cmd line: "); | 1105 | argv[1] = cp; /* head of new arg block */ |
1118 | fflush(stderr); /* I dont care if it's unbuffered or not! */ | 1106 | fprintf(stderr, "Cmd line: "); |
1119 | insaved = read(0, cp, BIGSIZ-1); /* we're gonna fake fgets() | 1107 | fflush(stderr); /* I dont care if it's unbuffered or not! */ |
1120 | * here */ | 1108 | insaved = read(0, cp, BIGSIZ-1); /* we're gonna fake fgets() |
1121 | cp[BIGSIZ-1] = '\0'; | 1109 | * here */ |
1110 | cp[BIGSIZ-1] = '\0'; | ||
1111 | if (*cp != '\n' && *cp != '\t') | ||
1112 | break; | ||
1113 | } | ||
1122 | if (insaved <= 0) | 1114 | if (insaved <= 0) |
1123 | nlog(1, "wrong"); | 1115 | nlog(1, "wrong"); |
1124 | x = findline(cp, insaved); | 1116 | x = findline(cp, insaved); |
@@ -1239,7 +1231,6 @@ main(argc, argv) | |||
1239 | /* other misc initialization */ | 1231 | /* other misc initialization */ |
1240 | FD_SET(0, &fds1); /* stdin *is* initially open */ | 1232 | FD_SET(0, &fds1); /* stdin *is* initially open */ |
1241 | if (o_random) { | 1233 | if (o_random) { |
1242 | SRAND(time(0)); | ||
1243 | randports = calloc(1, 65536); /* big flag array for ports */ | 1234 | randports = calloc(1, 65536); /* big flag array for ports */ |
1244 | } | 1235 | } |
1245 | if (o_wfile) { | 1236 | if (o_wfile) { |
@@ -1256,7 +1247,6 @@ main(argc, argv) | |||
1256 | if (themaddr) | 1247 | if (themaddr) |
1257 | optind++; /* skip past valid host lookup */ | 1248 | optind++; /* skip past valid host lookup */ |
1258 | errno = 0; | 1249 | errno = 0; |
1259 | h_errno = 0; | ||
1260 | 1250 | ||
1261 | /* | 1251 | /* |
1262 | * Handle listen mode here, and exit afterward. Only does one connect; | 1252 | * Handle listen mode here, and exit afterward. Only does one connect; |
@@ -1302,9 +1292,9 @@ main(argc, argv) | |||
1302 | loport = getpinfo(argv[optind], 0); | 1292 | loport = getpinfo(argv[optind], 0); |
1303 | if (loport == 0) | 1293 | if (loport == 0) |
1304 | nlog(1, "invalid port %s", argv[optind]); | 1294 | nlog(1, "invalid port %s", argv[optind]); |
1305 | if (hiport > loport) { /* was it genuinely a range? */ | 1295 | if (hiport > loport) { |
1306 | Single = 0; /* multi-mode, case B */ | 1296 | Single = 0; |
1307 | if (o_random) { /* maybe populate the random array */ | 1297 | if (o_random) { |
1308 | loadports(randports, loport, hiport); | 1298 | loadports(randports, loport, hiport); |
1309 | curport = nextport(randports); | 1299 | curport = nextport(randports); |
1310 | } else | 1300 | } else |
@@ -1376,6 +1366,7 @@ nlog(doexit, fmt) | |||
1376 | herror(NULL); | 1366 | herror(NULL); |
1377 | else | 1367 | else |
1378 | putc('\n', stderr); | 1368 | putc('\n', stderr); |
1369 | va_end(args); | ||
1379 | } | 1370 | } |
1380 | 1371 | ||
1381 | if (doexit) | 1372 | if (doexit) |