diff options
Diffstat (limited to 'src/usr.bin/nc/netcat.c')
-rw-r--r-- | src/usr.bin/nc/netcat.c | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index beca89e01c..505cbd77b1 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.66 2004/01/31 21:09:15 henning Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.67 2004/02/20 10:53:10 jmc Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
4 | * | 4 | * |
@@ -63,7 +63,7 @@ | |||
63 | int iflag; /* Interval Flag */ | 63 | int iflag; /* Interval Flag */ |
64 | int kflag; /* More than one connect */ | 64 | int kflag; /* More than one connect */ |
65 | int lflag; /* Bind to local port */ | 65 | int lflag; /* Bind to local port */ |
66 | int nflag; /* Dont do name lookup */ | 66 | int nflag; /* Don't do name look up */ |
67 | char *pflag; /* Localport flag */ | 67 | char *pflag; /* Localport flag */ |
68 | int rflag; /* Random ports flag */ | 68 | int rflag; /* Random ports flag */ |
69 | char *sflag; /* Source Address */ | 69 | char *sflag; /* Source Address */ |
@@ -216,7 +216,7 @@ main(int argc, char *argv[]) | |||
216 | if (!lflag && kflag) | 216 | if (!lflag && kflag) |
217 | errx(1, "must use -l with -k"); | 217 | errx(1, "must use -l with -k"); |
218 | 218 | ||
219 | /* Initialize addrinfo structure */ | 219 | /* Initialize addrinfo structure. */ |
220 | if (family != AF_UNIX) { | 220 | if (family != AF_UNIX) { |
221 | memset(&hints, 0, sizeof(struct addrinfo)); | 221 | memset(&hints, 0, sizeof(struct addrinfo)); |
222 | hints.ai_family = family; | 222 | hints.ai_family = family; |
@@ -261,7 +261,7 @@ main(int argc, char *argv[]) | |||
261 | if (family == AF_UNIX) | 261 | if (family == AF_UNIX) |
262 | s = unix_listen(host); | 262 | s = unix_listen(host); |
263 | 263 | ||
264 | /* Allow only one connection at a time, but stay alive */ | 264 | /* Allow only one connection at a time, but stay alive. */ |
265 | for (;;) { | 265 | for (;;) { |
266 | if (family != AF_UNIX) | 266 | if (family != AF_UNIX) |
267 | s = local_listen(host, uport, hints); | 267 | s = local_listen(host, uport, hints); |
@@ -315,10 +315,10 @@ main(int argc, char *argv[]) | |||
315 | } else { | 315 | } else { |
316 | int i = 0; | 316 | int i = 0; |
317 | 317 | ||
318 | /* construct the portlist[] array */ | 318 | /* Construct the portlist[] array. */ |
319 | build_ports(uport); | 319 | build_ports(uport); |
320 | 320 | ||
321 | /* Cycle through portlist, connecting to each port */ | 321 | /* Cycle through portlist, connecting to each port. */ |
322 | for (i = 0; portlist[i] != NULL; i++) { | 322 | for (i = 0; portlist[i] != NULL; i++) { |
323 | if (s) | 323 | if (s) |
324 | close(s); | 324 | close(s); |
@@ -334,7 +334,7 @@ main(int argc, char *argv[]) | |||
334 | 334 | ||
335 | ret = 0; | 335 | ret = 0; |
336 | if (vflag || zflag) { | 336 | if (vflag || zflag) { |
337 | /* For UDP, make sure we are connected */ | 337 | /* For UDP, make sure we are connected. */ |
338 | if (uflag) { | 338 | if (uflag) { |
339 | if (udptest(s) == -1) { | 339 | if (udptest(s) == -1) { |
340 | ret = 1; | 340 | ret = 1; |
@@ -342,7 +342,7 @@ main(int argc, char *argv[]) | |||
342 | } | 342 | } |
343 | } | 343 | } |
344 | 344 | ||
345 | /* Don't lookup port if -n */ | 345 | /* Don't look up port if -n. */ |
346 | if (nflag) | 346 | if (nflag) |
347 | sv = NULL; | 347 | sv = NULL; |
348 | else { | 348 | else { |
@@ -368,7 +368,7 @@ main(int argc, char *argv[]) | |||
368 | 368 | ||
369 | /* | 369 | /* |
370 | * unix_connect() | 370 | * unix_connect() |
371 | * Return's a socket connected to a local unix socket. Return's -1 on failure. | 371 | * Returns a socket connected to a local unix socket. Returns -1 on failure. |
372 | */ | 372 | */ |
373 | int | 373 | int |
374 | unix_connect(char *path) | 374 | unix_connect(char *path) |
@@ -399,7 +399,7 @@ unix_connect(char *path) | |||
399 | 399 | ||
400 | /* | 400 | /* |
401 | * unix_listen() | 401 | * unix_listen() |
402 | * create a unix domain socket, and listen on it. | 402 | * Create a unix domain socket, and listen on it. |
403 | */ | 403 | */ |
404 | int | 404 | int |
405 | unix_listen(char *path) | 405 | unix_listen(char *path) |
@@ -407,7 +407,7 @@ unix_listen(char *path) | |||
407 | struct sockaddr_un sun; | 407 | struct sockaddr_un sun; |
408 | int s; | 408 | int s; |
409 | 409 | ||
410 | /* create unix domain socket */ | 410 | /* Create unix domain socket. */ |
411 | if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) | 411 | if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) |
412 | return (-1); | 412 | return (-1); |
413 | 413 | ||
@@ -435,8 +435,8 @@ unix_listen(char *path) | |||
435 | 435 | ||
436 | /* | 436 | /* |
437 | * remote_connect() | 437 | * remote_connect() |
438 | * Return's a socket connected to a remote host. Properly bind's to a local | 438 | * Returns a socket connected to a remote host. Properly binds to a local |
439 | * port or source address if needed. Return's -1 on failure. | 439 | * port or source address if needed. Returns -1 on failure. |
440 | */ | 440 | */ |
441 | int | 441 | int |
442 | remote_connect(char *host, char *port, struct addrinfo hints) | 442 | remote_connect(char *host, char *port, struct addrinfo hints) |
@@ -453,7 +453,7 @@ remote_connect(char *host, char *port, struct addrinfo hints) | |||
453 | res0->ai_protocol)) < 0) | 453 | res0->ai_protocol)) < 0) |
454 | continue; | 454 | continue; |
455 | 455 | ||
456 | /* Bind to a local port or source address if specified */ | 456 | /* Bind to a local port or source address if specified. */ |
457 | if (sflag || pflag) { | 457 | if (sflag || pflag) { |
458 | struct addrinfo ahints, *ares; | 458 | struct addrinfo ahints, *ares; |
459 | 459 | ||
@@ -497,8 +497,8 @@ remote_connect(char *host, char *port, struct addrinfo hints) | |||
497 | 497 | ||
498 | /* | 498 | /* |
499 | * local_listen() | 499 | * local_listen() |
500 | * Return's a socket listening on a local port, binds to specified source | 500 | * Returns a socket listening on a local port, binds to specified source |
501 | * address. Return's -1 on failure. | 501 | * address. Returns -1 on failure. |
502 | */ | 502 | */ |
503 | int | 503 | int |
504 | local_listen(char *host, char *port, struct addrinfo hints) | 504 | local_listen(char *host, char *port, struct addrinfo hints) |
@@ -507,7 +507,7 @@ local_listen(char *host, char *port, struct addrinfo hints) | |||
507 | int s, ret, x = 1; | 507 | int s, ret, x = 1; |
508 | int error; | 508 | int error; |
509 | 509 | ||
510 | /* Allow nodename to be null */ | 510 | /* Allow nodename to be null. */ |
511 | hints.ai_flags |= AI_PASSIVE; | 511 | hints.ai_flags |= AI_PASSIVE; |
512 | 512 | ||
513 | /* | 513 | /* |
@@ -570,7 +570,7 @@ readwrite(int nfd) | |||
570 | pfd[0].fd = nfd; | 570 | pfd[0].fd = nfd; |
571 | pfd[0].events = POLLIN; | 571 | pfd[0].events = POLLIN; |
572 | 572 | ||
573 | /* Setup STDIN FD */ | 573 | /* Set up STDIN FD. */ |
574 | pfd[1].fd = wfd; | 574 | pfd[1].fd = wfd; |
575 | pfd[1].events = POLLIN; | 575 | pfd[1].events = POLLIN; |
576 | 576 | ||
@@ -620,7 +620,7 @@ readwrite(int nfd) | |||
620 | } | 620 | } |
621 | } | 621 | } |
622 | 622 | ||
623 | /* Deal with RFC854 WILL/WONT DO/DONT negotiation */ | 623 | /* Deal with RFC 854 WILL/WONT DO/DONT negotiation. */ |
624 | void | 624 | void |
625 | atelnet(int nfd, unsigned char *buf, unsigned int size) | 625 | atelnet(int nfd, unsigned char *buf, unsigned int size) |
626 | { | 626 | { |
@@ -657,7 +657,7 @@ atelnet(int nfd, unsigned char *buf, unsigned int size) | |||
657 | /* | 657 | /* |
658 | * build_ports() | 658 | * build_ports() |
659 | * Build an array or ports in portlist[], listing each port | 659 | * Build an array or ports in portlist[], listing each port |
660 | * that we should try to connect too. | 660 | * that we should try to connect to. |
661 | */ | 661 | */ |
662 | void | 662 | void |
663 | build_ports(char *p) | 663 | build_ports(char *p) |
@@ -673,7 +673,7 @@ build_ports(char *p) | |||
673 | *n = '\0'; | 673 | *n = '\0'; |
674 | n++; | 674 | n++; |
675 | 675 | ||
676 | /* Make sure the ports are in order: lowest->highest */ | 676 | /* Make sure the ports are in order: lowest->highest. */ |
677 | hi = (int)strtoul(n, &endp, 10); | 677 | hi = (int)strtoul(n, &endp, 10); |
678 | if (hi <= 0 || hi > PORT_MAX || *endp != '\0') | 678 | if (hi <= 0 || hi > PORT_MAX || *endp != '\0') |
679 | errx(1, "port range not valid"); | 679 | errx(1, "port range not valid"); |
@@ -687,7 +687,7 @@ build_ports(char *p) | |||
687 | lo = cp; | 687 | lo = cp; |
688 | } | 688 | } |
689 | 689 | ||
690 | /* Load ports sequentially */ | 690 | /* Load ports sequentially. */ |
691 | for (cp = lo; cp <= hi; cp++) { | 691 | for (cp = lo; cp <= hi; cp++) { |
692 | portlist[x] = calloc(1, PORT_MAX_LEN); | 692 | portlist[x] = calloc(1, PORT_MAX_LEN); |
693 | if (portlist[x] == NULL) | 693 | if (portlist[x] == NULL) |
@@ -696,7 +696,7 @@ build_ports(char *p) | |||
696 | x++; | 696 | x++; |
697 | } | 697 | } |
698 | 698 | ||
699 | /* Randomly swap ports */ | 699 | /* Randomly swap ports. */ |
700 | if (rflag) { | 700 | if (rflag) { |
701 | int y; | 701 | int y; |
702 | char *c; | 702 | char *c; |
@@ -722,7 +722,7 @@ build_ports(char *p) | |||
722 | /* | 722 | /* |
723 | * udptest() | 723 | * udptest() |
724 | * Do a few writes to see if the UDP port is there. | 724 | * Do a few writes to see if the UDP port is there. |
725 | * XXX - Better way of doing this? Doesn't work for IPv6 | 725 | * XXX - Better way of doing this? Doesn't work for IPv6. |
726 | * Also fails after around 100 ports checked. | 726 | * Also fails after around 100 ports checked. |
727 | */ | 727 | */ |
728 | int | 728 | int |
@@ -746,9 +746,6 @@ help(void) | |||
746 | fprintf(stderr, "\tCommand Summary:\n\ | 746 | fprintf(stderr, "\tCommand Summary:\n\ |
747 | \t-4 Use IPv4\n\ | 747 | \t-4 Use IPv4\n\ |
748 | \t-6 Use IPv6\n\ | 748 | \t-6 Use IPv6\n\ |
749 | \t-S Enable the TCP MD5 signature option\n\ | ||
750 | \t-U Use UNIX domain socket\n\ | ||
751 | \t-X vers\t SOCKS version (4 or 5)\n\ | ||
752 | \t-h This help text\n\ | 749 | \t-h This help text\n\ |
753 | \t-i secs\t Delay interval for lines sent, ports scanned\n\ | 750 | \t-i secs\t Delay interval for lines sent, ports scanned\n\ |
754 | \t-k Keep inbound sockets open for multiple connects\n\ | 751 | \t-k Keep inbound sockets open for multiple connects\n\ |
@@ -756,11 +753,14 @@ help(void) | |||
756 | \t-n Suppress name/port resolutions\n\ | 753 | \t-n Suppress name/port resolutions\n\ |
757 | \t-p port\t Specify local port for remote connects\n\ | 754 | \t-p port\t Specify local port for remote connects\n\ |
758 | \t-r Randomize remote ports\n\ | 755 | \t-r Randomize remote ports\n\ |
756 | \t-S Enable the TCP MD5 signature option\n\ | ||
759 | \t-s addr\t Local source address\n\ | 757 | \t-s addr\t Local source address\n\ |
760 | \t-t Answer TELNET negotiation\n\ | 758 | \t-t Answer TELNET negotiation\n\ |
759 | \t-U Use UNIX domain socket\n\ | ||
761 | \t-u UDP mode\n\ | 760 | \t-u UDP mode\n\ |
762 | \t-v Verbose\n\ | 761 | \t-v Verbose\n\ |
763 | \t-w secs\t Timeout for connects and final net reads\n\ | 762 | \t-w secs\t Timeout for connects and final net reads\n\ |
763 | \t-X vers\t SOCKS version (4 or 5)\n\ | ||
764 | \t-x addr[:port]\tSpecify socks proxy address and port\n\ | 764 | \t-x addr[:port]\tSpecify socks proxy address and port\n\ |
765 | \t-z Zero-I/O mode [used for scanning]\n\ | 765 | \t-z Zero-I/O mode [used for scanning]\n\ |
766 | Port numbers can be individual or ranges: lo-hi [inclusive]\n"); | 766 | Port numbers can be individual or ranges: lo-hi [inclusive]\n"); |
@@ -770,9 +770,9 @@ help(void) | |||
770 | void | 770 | void |
771 | usage(int ret) | 771 | usage(int ret) |
772 | { | 772 | { |
773 | fprintf(stderr, "usage: nc [-46SUhklnrtuvz] [-i interval] [-p source port]\n"); | 773 | fprintf(stderr, "usage: nc [-46hklnrStUuvz] [-i interval] [-p source_port] [-s source_ip_address]\n"); |
774 | fprintf(stderr, "\t [-s ip address] [-w timeout] [-X vers] [-x proxy address [:port]]\n"); | 774 | fprintf(stderr, "\t [-w timeout] [-X socks_version] [-x proxy_address[:port]] [hostname]\n"); |
775 | fprintf(stderr, "\t [hostname] [port[s...]]\n"); | 775 | fprintf(stderr, "\t [port[s]]\n"); |
776 | if (ret) | 776 | if (ret) |
777 | exit(1); | 777 | exit(1); |
778 | } | 778 | } |