Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/netcat/netcat.c
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
int Fflag; /* fdpass sock to stdout */ | int Fflag; /* fdpass sock to stdout */ | ||||
unsigned int iflag; /* Interval Flag */ | unsigned int iflag; /* Interval Flag */ | ||||
int kflag; /* More than one connect */ | int kflag; /* More than one connect */ | ||||
int lflag; /* Bind to local port */ | int lflag; /* Bind to local port */ | ||||
int FreeBSD_Mflag; /* Measure using stats(3) */ | int FreeBSD_Mflag; /* Measure using stats(3) */ | ||||
int Nflag; /* shutdown() network socket */ | int Nflag; /* shutdown() network socket */ | ||||
int nflag; /* Don't do name look up */ | int nflag; /* Don't do name look up */ | ||||
int FreeBSD_Oflag; /* Do not use TCP options */ | int FreeBSD_Oflag; /* Do not use TCP options */ | ||||
int FreeBSD_sctp; /* Use SCTP */ | |||||
char *Pflag; /* Proxy username */ | char *Pflag; /* Proxy username */ | ||||
char *pflag; /* Localport flag */ | char *pflag; /* Localport flag */ | ||||
int rflag; /* Random ports flag */ | int rflag; /* Random ports flag */ | ||||
char *sflag; /* Source Address */ | char *sflag; /* Source Address */ | ||||
int tflag; /* Telnet Emulation */ | int tflag; /* Telnet Emulation */ | ||||
int uflag; /* UDP - Default to TCP */ | int uflag; /* UDP - Default to TCP */ | ||||
int vflag; /* Verbosity */ | int vflag; /* Verbosity */ | ||||
int xflag; /* Socks proxy */ | int xflag; /* Socks proxy */ | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | main(int argc, char *argv[]) | ||||
socklen_t len; | socklen_t len; | ||||
struct sockaddr_storage cliaddr; | struct sockaddr_storage cliaddr; | ||||
char *proxy; | char *proxy; | ||||
const char *errstr, *proxyhost = "", *proxyport = NULL; | const char *errstr, *proxyhost = "", *proxyport = NULL; | ||||
struct addrinfo proxyhints; | struct addrinfo proxyhints; | ||||
char unix_dg_tmp_socket_buf[UNIX_DG_TMP_SOCKET_SIZE]; | char unix_dg_tmp_socket_buf[UNIX_DG_TMP_SOCKET_SIZE]; | ||||
struct option longopts[] = { | struct option longopts[] = { | ||||
{ "no-tcpopt", no_argument, &FreeBSD_Oflag, 1 }, | { "no-tcpopt", no_argument, &FreeBSD_Oflag, 1 }, | ||||
{ "sctp", no_argument, &FreeBSD_sctp, 1 }, | |||||
{ NULL, 0, NULL, 0 } | { NULL, 0, NULL, 0 } | ||||
}; | }; | ||||
ret = 1; | ret = 1; | ||||
ipsec_count = 0; | ipsec_count = 0; | ||||
s = 0; | s = 0; | ||||
socksv = 5; | socksv = 5; | ||||
host = NULL; | host = NULL; | ||||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | case 'T': | ||||
optarg[1] == 'x') | optarg[1] == 'x') | ||||
Tflag = (int)strtol(optarg, NULL, 16); | Tflag = (int)strtol(optarg, NULL, 16); | ||||
else | else | ||||
Tflag = (int)strtonum(optarg, 0, 255, | Tflag = (int)strtonum(optarg, 0, 255, | ||||
&errstr); | &errstr); | ||||
if (Tflag < 0 || Tflag > 255 || errstr || errno) | if (Tflag < 0 || Tflag > 255 || errstr || errno) | ||||
errx(1, "illegal tos value %s", optarg); | errx(1, "illegal tos value %s", optarg); | ||||
break; | break; | ||||
case 0: | |||||
/* Long option. */ | |||||
break; | |||||
default: | default: | ||||
usage(1); | usage(1); | ||||
} | } | ||||
} | } | ||||
argc -= optind; | argc -= optind; | ||||
argv += optind; | argv += optind; | ||||
/* Cruft to make sure options are clean, and used properly. */ | /* Cruft to make sure options are clean, and used properly. */ | ||||
Show All 14 Lines | #endif | ||||
if (lflag && sflag) | if (lflag && sflag) | ||||
errx(1, "cannot use -s and -l"); | errx(1, "cannot use -s and -l"); | ||||
if (lflag && pflag) | if (lflag && pflag) | ||||
errx(1, "cannot use -p and -l"); | errx(1, "cannot use -p and -l"); | ||||
if (lflag && zflag) | if (lflag && zflag) | ||||
errx(1, "cannot use -z and -l"); | errx(1, "cannot use -z and -l"); | ||||
if (!lflag && kflag) | if (!lflag && kflag) | ||||
errx(1, "must use -l with -k"); | errx(1, "must use -l with -k"); | ||||
if (FreeBSD_sctp) { | |||||
if (uflag) | |||||
errx(1, "cannot use -u and --sctp"); | |||||
if (family == AF_UNIX) | |||||
errx(1, "cannot use -U and --sctp"); | |||||
} | |||||
/* Get name of temporary socket for unix datagram client */ | /* Get name of temporary socket for unix datagram client */ | ||||
if ((family == AF_UNIX) && uflag && !lflag) { | if ((family == AF_UNIX) && uflag && !lflag) { | ||||
if (sflag) { | if (sflag) { | ||||
unix_dg_tmp_socket = sflag; | unix_dg_tmp_socket = sflag; | ||||
} else { | } else { | ||||
strlcpy(unix_dg_tmp_socket_buf, "/tmp/nc.XXXXXXXXXX", | strlcpy(unix_dg_tmp_socket_buf, "/tmp/nc.XXXXXXXXXX", | ||||
UNIX_DG_TMP_SOCKET_SIZE); | UNIX_DG_TMP_SOCKET_SIZE); | ||||
if (mktemp(unix_dg_tmp_socket_buf) == NULL) | if (mktemp(unix_dg_tmp_socket_buf) == NULL) | ||||
err(1, "mktemp"); | err(1, "mktemp"); | ||||
unix_dg_tmp_socket = unix_dg_tmp_socket_buf; | unix_dg_tmp_socket = unix_dg_tmp_socket_buf; | ||||
} | } | ||||
} | } | ||||
/* Initialize addrinfo structure. */ | /* Initialize addrinfo structure. */ | ||||
if (family != AF_UNIX) { | if (family != AF_UNIX) { | ||||
memset(&hints, 0, sizeof(struct addrinfo)); | memset(&hints, 0, sizeof(struct addrinfo)); | ||||
hints.ai_family = family; | hints.ai_family = family; | ||||
hints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM; | hints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM; | ||||
hints.ai_protocol = uflag ? IPPROTO_UDP : IPPROTO_TCP; | hints.ai_protocol = uflag ? IPPROTO_UDP : | ||||
FreeBSD_sctp ? IPPROTO_SCTP : IPPROTO_TCP; | |||||
if (nflag) | if (nflag) | ||||
hints.ai_flags |= AI_NUMERICHOST; | hints.ai_flags |= AI_NUMERICHOST; | ||||
} | } | ||||
if (xflag) { | if (xflag) { | ||||
if (uflag) | if (uflag) | ||||
errx(1, "no proxy support for UDP mode"); | errx(1, "no proxy support for UDP mode"); | ||||
if (FreeBSD_sctp) | |||||
errx(1, "no proxy support for SCTP mode"); | |||||
if (lflag) | if (lflag) | ||||
errx(1, "no proxy support for listen"); | errx(1, "no proxy support for listen"); | ||||
if (family == AF_UNIX) | if (family == AF_UNIX) | ||||
errx(1, "no proxy support for unix sockets"); | errx(1, "no proxy support for unix sockets"); | ||||
/* XXX IPv6 transport to proxy would probably work */ | /* XXX IPv6 transport to proxy would probably work */ | ||||
if (family == AF_INET6) | if (family == AF_INET6) | ||||
▲ Show 20 Lines • Show All 1,026 Lines • ▼ Show 20 Lines | #endif | ||||
\t-h This help text\n\ | \t-h This help text\n\ | ||||
\t-I length TCP receive buffer length\n\ | \t-I length TCP receive buffer length\n\ | ||||
\t-i secs\t Delay interval for lines sent, ports scanned\n\ | \t-i secs\t Delay interval for lines sent, ports scanned\n\ | ||||
\t-k Keep inbound sockets open for multiple connects\n\ | \t-k Keep inbound sockets open for multiple connects\n\ | ||||
\t-l Listen mode, for inbound connects\n\ | \t-l Listen mode, for inbound connects\n\ | ||||
\t-N Shutdown the network socket after EOF on stdin\n\ | \t-N Shutdown the network socket after EOF on stdin\n\ | ||||
\t-n Suppress name/port resolutions\n\ | \t-n Suppress name/port resolutions\n\ | ||||
\t--no-tcpopt Disable TCP options\n\ | \t--no-tcpopt Disable TCP options\n\ | ||||
\t--sctp\t SCTP mode\n\ | |||||
\t-O length TCP send buffer length\n\ | \t-O length TCP send buffer length\n\ | ||||
\t-P proxyuser\tUsername for proxy authentication\n\ | \t-P proxyuser\tUsername for proxy authentication\n\ | ||||
\t-p port\t Specify local port for remote connects\n\ | \t-p port\t Specify local port for remote connects\n\ | ||||
\t-r Randomize remote ports\n\ | \t-r Randomize remote ports\n\ | ||||
\t-S Enable the TCP MD5 signature option\n\ | \t-S Enable the TCP MD5 signature option\n\ | ||||
\t-s addr\t Local source address\n\ | \t-s addr\t Local source address\n\ | ||||
\t-T toskeyword\tSet IP Type of Service\n\ | \t-T toskeyword\tSet IP Type of Service\n\ | ||||
\t-t Answer TELNET negotiation\n\ | \t-t Answer TELNET negotiation\n\ | ||||
\t-U Use UNIX domain socket\n\ | \t-U Use UNIX domain socket\n\ | ||||
\t-u UDP mode\n\ | \t-u UDP mode\n\ | ||||
\t-V rtable Specify alternate routing table\n\ | \t-V rtable Specify alternate routing table\n\ | ||||
\t-v Verbose\n\ | \t-v Verbose\n\ | ||||
\t-w secs\t Timeout for connects and final net reads\n\ | \t-w secs\t Timeout for connects and final net reads\n\ | ||||
\t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\ | \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\ | ||||
\t-x addr[:port]\tSpecify proxy address and port\n\ | \t-x addr[:port]\tSpecify proxy address and port\n\ | ||||
\t-z Zero-I/O mode [used for scanning]\n\ | \t-z Zero-I/O mode [used for scanning]\n\ | ||||
Port numbers can be individual or ranges: lo-hi [inclusive]\n"); | Port numbers can be individual or ranges: lo-hi [inclusive]\n"); | ||||
#ifdef IPSEC | #ifdef IPSEC | ||||
fprintf(stderr, "See ipsec_set_policy(3) for -e argument format\n"); | fprintf(stderr, "\tSee ipsec_set_policy(3) for -e argument format\n"); | ||||
#endif | #endif | ||||
exit(1); | exit(1); | ||||
} | } | ||||
#ifdef IPSEC | #ifdef IPSEC | ||||
void | void | ||||
add_ipsec_policy(int s, int af, char *policy) | add_ipsec_policy(int s, int af, char *policy) | ||||
{ | { | ||||
Show All 23 Lines | |||||
usage(int ret) | usage(int ret) | ||||
{ | { | ||||
fprintf(stderr, | fprintf(stderr, | ||||
#ifdef IPSEC | #ifdef IPSEC | ||||
"usage: nc [-46DdEFhklNnrStUuvz] [-e policy] [-I length] [-i interval] [-O length]\n" | "usage: nc [-46DdEFhklNnrStUuvz] [-e policy] [-I length] [-i interval] [-O length]\n" | ||||
#else | #else | ||||
"usage: nc [-46DdFhklNnrStUuvz] [-I length] [-i interval] [-O length]\n" | "usage: nc [-46DdFhklNnrStUuvz] [-I length] [-i interval] [-O length]\n" | ||||
#endif | #endif | ||||
"\t [--no-tcpopt] [--sctp]\n" | |||||
"\t [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n" | "\t [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n" | ||||
"\t [-V rtable] [-w timeout] [-X proxy_protocol]\n" | "\t [-V rtable] [-w timeout] [-X proxy_protocol]\n" | ||||
"\t [-x proxy_address[:port]] [destination] [port]\n"); | "\t [-x proxy_address[:port]] [destination] [port]\n"); | ||||
if (ret) | if (ret) | ||||
exit(1); | exit(1); | ||||
} | } |