version 1.64, 2003/10/19 22:50:35 |
version 1.65, 2004/01/22 13:28:46 |
|
|
#include <sys/un.h> |
#include <sys/un.h> |
|
|
#include <netinet/in.h> |
#include <netinet/in.h> |
|
#include <netinet/tcp.h> |
#include <arpa/telnet.h> |
#include <arpa/telnet.h> |
|
|
#include <err.h> |
#include <err.h> |
|
|
int vflag; /* Verbosity */ |
int vflag; /* Verbosity */ |
int xflag; /* Socks proxy */ |
int xflag; /* Socks proxy */ |
int zflag; /* Port Scan Flag */ |
int zflag; /* Port Scan Flag */ |
|
int Sflag; /* TCP MD5 signature option */ |
|
|
int timeout = -1; |
int timeout = -1; |
int family = AF_UNSPEC; |
int family = AF_UNSPEC; |
|
|
endp = NULL; |
endp = NULL; |
sv = NULL; |
sv = NULL; |
|
|
while ((ch = getopt(argc, argv, "46UX:hi:klnp:rs:tuvw:x:z")) != -1) { |
while ((ch = getopt(argc, argv, "46UX:hi:klnp:rs:tuvw:x:zS")) != -1) { |
switch (ch) { |
switch (ch) { |
case '4': |
case '4': |
family = AF_INET; |
family = AF_INET; |
|
|
case 'z': |
case 'z': |
zflag = 1; |
zflag = 1; |
break; |
break; |
|
case 'S': |
|
Sflag = 1; |
|
break; |
default: |
default: |
usage(1); |
usage(1); |
} |
} |
|
|
remote_connect(char *host, char *port, struct addrinfo hints) |
remote_connect(char *host, char *port, struct addrinfo hints) |
{ |
{ |
struct addrinfo *res, *res0; |
struct addrinfo *res, *res0; |
int s, error; |
int s, error, x = 1; |
|
|
if ((error = getaddrinfo(host, port, &hints, &res))) |
if ((error = getaddrinfo(host, port, &hints, &res))) |
errx(1, "getaddrinfo: %s", gai_strerror(error)); |
errx(1, "getaddrinfo: %s", gai_strerror(error)); |
|
|
errx(1, "bind failed: %s", strerror(errno)); |
errx(1, "bind failed: %s", strerror(errno)); |
freeaddrinfo(ares); |
freeaddrinfo(ares); |
} |
} |
|
if (Sflag) { |
|
if (setsockopt(s, IPPROTO_TCP, TCP_SIGNATURE_ENABLE, |
|
&x, sizeof(x)) == -1) |
|
err(1, NULL); |
|
} |
|
|
if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0) |
if (connect(s, res0->ai_addr, res0->ai_addrlen) == 0) |
break; |
break; |
|
|
ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); |
ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); |
if (ret == -1) |
if (ret == -1) |
err(1, NULL); |
err(1, NULL); |
|
if (Sflag) { |
|
ret = setsockopt(s, IPPROTO_TCP, TCP_SIGNATURE_ENABLE, |
|
&x, sizeof(x)); |
|
if (ret == -1) |
|
err(1, NULL); |
|
} |
|
|
if (bind(s, (struct sockaddr *)res0->ai_addr, |
if (bind(s, (struct sockaddr *)res0->ai_addr, |
res0->ai_addrlen) == 0) |
res0->ai_addrlen) == 0) |
|
|
fprintf(stderr, "\tCommand Summary:\n\ |
fprintf(stderr, "\tCommand Summary:\n\ |
\t-4 Use IPv4\n\ |
\t-4 Use IPv4\n\ |
\t-6 Use IPv6\n\ |
\t-6 Use IPv6\n\ |
|
\t-S Enable the TCP MD5 signature option\n\ |
\t-U Use UNIX domain socket\n\ |
\t-U Use UNIX domain socket\n\ |
\t-X vers\t SOCKS version (4 or 5)\n\ |
\t-X vers\t SOCKS version (4 or 5)\n\ |
\t-h This help text\n\ |
\t-h This help text\n\ |
|
|
void |
void |
usage(int ret) |
usage(int ret) |
{ |
{ |
fprintf(stderr, "usage: nc [-46Uhklnrtuvz] [-i interval] [-p source port]\n"); |
fprintf(stderr, "usage: nc [-46SUhklnrtuvz] [-i interval] [-p source port]\n"); |
fprintf(stderr, "\t [-s ip address] [-w timeout] [-X vers] [-x proxy address [:port]]\n"); |
fprintf(stderr, "\t [-s ip address] [-w timeout] [-X vers] [-x proxy address [:port]]\n"); |
fprintf(stderr, "\t [hostname] [port[s...]]\n"); |
fprintf(stderr, "\t [hostname] [port[s...]]\n"); |
if (ret) |
if (ret) |