mirror of
https://github.com/opnsense/src.git
synced 2026-06-08 16:22:46 -04:00
Add a --sctp flag to nc.
The change adds an SCTP mode akin to UDP mode. This is handy for doing smoke testing of SCTP. Use a long option to minimize the risk of option conflicts with OpenBSD. For bonus points, this change unbreaks --no-tcpopt by adding a missing case required by getopt_long(). Reviewed by: delphij, tuexen MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D25610
This commit is contained in:
parent
cd88eaa5b4
commit
d041589227
2 changed files with 22 additions and 2 deletions
|
|
@ -41,6 +41,7 @@
|
|||
.Op Fl I Ar length
|
||||
.Op Fl i Ar interval
|
||||
.Op Fl -no-tcpopt
|
||||
.Op Fl -sctp
|
||||
.Op Fl O Ar length
|
||||
.Op Fl P Ar proxy_username
|
||||
.Op Fl p Ar source_port
|
||||
|
|
@ -187,6 +188,8 @@ hostnames or ports.
|
|||
Disables the use of TCP options on the socket, by setting the boolean
|
||||
TCP_NOOPT
|
||||
socket option.
|
||||
.It Fl -sctp
|
||||
Use SCTP instead of the default option of TCP.
|
||||
.It Fl O Ar length
|
||||
Specifies the size of the TCP send buffer.
|
||||
.It Fl P Ar proxy_username
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ int FreeBSD_Mflag; /* Measure using stats(3) */
|
|||
int Nflag; /* shutdown() network socket */
|
||||
int nflag; /* Don't do name look up */
|
||||
int FreeBSD_Oflag; /* Do not use TCP options */
|
||||
int FreeBSD_sctp; /* Use SCTP */
|
||||
char *Pflag; /* Proxy username */
|
||||
char *pflag; /* Localport flag */
|
||||
int rflag; /* Random ports flag */
|
||||
|
|
@ -160,6 +161,7 @@ main(int argc, char *argv[])
|
|||
char unix_dg_tmp_socket_buf[UNIX_DG_TMP_SOCKET_SIZE];
|
||||
struct option longopts[] = {
|
||||
{ "no-tcpopt", no_argument, &FreeBSD_Oflag, 1 },
|
||||
{ "sctp", no_argument, &FreeBSD_sctp, 1 },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
|
|
@ -324,6 +326,9 @@ main(int argc, char *argv[])
|
|||
if (Tflag < 0 || Tflag > 255 || errstr || errno)
|
||||
errx(1, "illegal tos value %s", optarg);
|
||||
break;
|
||||
case 0:
|
||||
/* Long option. */
|
||||
break;
|
||||
default:
|
||||
usage(1);
|
||||
}
|
||||
|
|
@ -354,6 +359,12 @@ main(int argc, char *argv[])
|
|||
errx(1, "cannot use -z and -l");
|
||||
if (!lflag && kflag)
|
||||
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 */
|
||||
if ((family == AF_UNIX) && uflag && !lflag) {
|
||||
|
|
@ -373,7 +384,8 @@ main(int argc, char *argv[])
|
|||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_family = family;
|
||||
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)
|
||||
hints.ai_flags |= AI_NUMERICHOST;
|
||||
}
|
||||
|
|
@ -382,6 +394,9 @@ main(int argc, char *argv[])
|
|||
if (uflag)
|
||||
errx(1, "no proxy support for UDP mode");
|
||||
|
||||
if (FreeBSD_sctp)
|
||||
errx(1, "no proxy support for SCTP mode");
|
||||
|
||||
if (lflag)
|
||||
errx(1, "no proxy support for listen");
|
||||
|
||||
|
|
@ -1424,6 +1439,7 @@ help(void)
|
|||
\t-N Shutdown the network socket after EOF on stdin\n\
|
||||
\t-n Suppress name/port resolutions\n\
|
||||
\t--no-tcpopt Disable TCP options\n\
|
||||
\t--sctp\t SCTP mode\n\
|
||||
\t-O length TCP send buffer length\n\
|
||||
\t-P proxyuser\tUsername for proxy authentication\n\
|
||||
\t-p port\t Specify local port for remote connects\n\
|
||||
|
|
@ -1442,7 +1458,7 @@ help(void)
|
|||
\t-z Zero-I/O mode [used for scanning]\n\
|
||||
Port numbers can be individual or ranges: lo-hi [inclusive]\n");
|
||||
#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
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -1482,6 +1498,7 @@ usage(int ret)
|
|||
#else
|
||||
"usage: nc [-46DdFhklNnrStUuvz] [-I length] [-i interval] [-O length]\n"
|
||||
#endif
|
||||
"\t [--no-tcpopt] [--sctp]\n"
|
||||
"\t [-P proxy_username] [-p source_port] [-s source] [-T ToS]\n"
|
||||
"\t [-V rtable] [-w timeout] [-X proxy_protocol]\n"
|
||||
"\t [-x proxy_address[:port]] [destination] [port]\n");
|
||||
|
|
|
|||
Loading…
Reference in a new issue