libressl-portable/patches/netcat.c.patch

180 lines
4.4 KiB
Diff
Raw Normal View History

2018-11-07 20:00:29 -06:00
--- apps/nc/netcat.c.orig 2018-11-07 17:01:38.000000000 -0600
+++ apps/nc/netcat.c 2018-11-07 17:37:57.000000000 -0600
@@ -92,9 +92,13 @@
2015-09-13 11:56:41 -05:00
int Dflag; /* sodebug */
int Iflag; /* TCP receive buffer size */
int Oflag; /* TCP send buffer size */
+#ifdef TCP_MD5SIG
int Sflag; /* TCP MD5 signature option */
+#endif
int Tflag = -1; /* IP Type of Service */
+#ifdef SO_RTABLE
int rtableid = -1;
+#endif
2018-11-07 20:00:29 -06:00
2015-09-13 11:56:41 -05:00
int usetls; /* use TLS */
char *Cflag; /* Public cert file */
@@ -266,12 +270,14 @@
2015-09-13 11:56:41 -05:00
case 'u':
uflag = 1;
break;
+#ifdef SO_RTABLE
case 'V':
rtableid = (int)strtonum(optarg, 0,
RT_TABLEID_MAX, &errstr);
if (errstr)
errx(1, "rtable %s: %s", errstr, optarg);
break;
+#endif
case 'v':
vflag = 1;
break;
@@ -318,9 +324,11 @@
2016-11-06 02:27:21 -06:00
case 'o':
oflag = optarg;
2015-09-13 11:56:41 -05:00
break;
+#ifdef TCP_MD5SIG
case 'S':
Sflag = 1;
break;
+#endif
case 'T':
errstr = NULL;
errno = 0;
@@ -344,9 +352,11 @@
2015-10-23 16:17:45 -07:00
argc -= optind;
argv += optind;
2018-11-07 20:00:29 -06:00
2015-10-23 16:17:45 -07:00
+#ifdef SO_RTABLE
2015-11-22 04:55:22 -06:00
if (rtableid >= 0)
if (setrtable(rtableid) == -1)
err(1, "setrtable");
2015-10-23 16:17:45 -07:00
+#endif
2018-11-07 20:00:29 -06:00
/* Cruft to make sure options are clean, and used properly. */
if (argv[0] && !argv[1] && family == AF_UNIX) {
@@ -909,7 +919,10 @@
2015-09-13 11:56:41 -05:00
remote_connect(const char *host, const char *port, struct addrinfo hints)
{
struct addrinfo *res, *res0;
2016-09-04 05:42:23 -05:00
- int s = -1, error, on = 1, save_errno;
+ int s = -1, error, save_errno;
2015-09-13 11:56:41 -05:00
+#ifdef SO_BINDANY
+ int on = 1;
+#endif
2018-11-07 20:00:29 -06:00
2016-09-04 05:42:23 -05:00
if ((error = getaddrinfo(host, port, &hints, &res0)))
2017-03-25 12:03:37 -05:00
errx(1, "getaddrinfo for host \"%s\" port %s: %s", host,
@@ -924,8 +937,10 @@
2015-09-13 11:56:41 -05:00
if (sflag || pflag) {
struct addrinfo ahints, *ares;
2018-11-07 20:00:29 -06:00
2015-09-13 11:56:41 -05:00
+#ifdef SO_BINDANY
/* try SO_BINDANY, but don't insist */
setsockopt(s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on));
+#endif
memset(&ahints, 0, sizeof(struct addrinfo));
2016-09-04 05:42:23 -05:00
ahints.ai_family = res->ai_family;
2015-09-13 11:56:41 -05:00
ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
@@ -996,7 +1011,10 @@
local_listen(const char *host, const char *port, struct addrinfo hints)
2015-09-13 19:06:29 -05:00
{
struct addrinfo *res, *res0;
2016-09-04 05:42:23 -05:00
- int s = -1, ret, x = 1, save_errno;
+ int s = -1, save_errno;
2015-09-13 19:06:29 -05:00
+#ifdef SO_REUSEPORT
2015-09-13 19:15:34 -05:00
+ int ret, x = 1;
2015-09-13 19:06:29 -05:00
+#endif
int error;
2018-11-07 20:00:29 -06:00
2015-09-13 19:06:29 -05:00
/* Allow nodename to be null. */
@@ -1017,9 +1035,11 @@
2016-09-04 05:42:23 -05:00
res->ai_protocol)) < 0)
2015-09-13 11:56:41 -05:00
continue;
2018-11-07 20:00:29 -06:00
2015-09-13 18:57:29 -05:00
+#ifdef SO_REUSEPORT
2015-09-13 11:56:41 -05:00
ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
if (ret == -1)
2015-09-13 18:57:29 -05:00
err(1, NULL);
+#endif
2018-11-07 20:00:29 -06:00
2016-09-04 05:42:23 -05:00
set_common_sockopts(s, res->ai_family);
2018-11-07 20:00:29 -06:00
@@ -1475,11 +1495,13 @@
2015-09-13 11:56:41 -05:00
{
int x = 1;
2018-11-07 20:00:29 -06:00
2015-09-13 11:56:41 -05:00
+#ifdef TCP_MD5SIG
if (Sflag) {
if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
&x, sizeof(x)) == -1)
err(1, NULL);
}
+#endif
if (Dflag) {
if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
&x, sizeof(x)) == -1)
@@ -1490,9 +1512,16 @@
2017-06-03 20:13:25 -05:00
IP_TOS, &Tflag, sizeof(Tflag)) == -1)
err(1, "set IP ToS");
2018-11-07 20:00:29 -06:00
2017-06-03 20:13:25 -05:00
+#ifdef IPV6_TCLASS
else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
IPV6_TCLASS, &Tflag, sizeof(Tflag)) == -1)
err(1, "set IPv6 traffic class");
+#else
+ else if (af == AF_INET6) {
+ errno = ENOPROTOOPT;
2017-06-03 20:13:25 -05:00
+ err(1, "set IPv6 traffic class not supported");
+ }
+#endif
}
if (Iflag) {
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
@@ -1516,13 +1545,17 @@
2016-06-30 05:49:38 -05:00
}
2018-11-07 20:00:29 -06:00
2016-06-30 20:00:29 -05:00
if (minttl != -1) {
2016-06-30 08:18:03 -05:00
+#ifdef IP_MINTTL
2016-06-30 20:00:29 -05:00
if (af == AF_INET && setsockopt(s, IPPROTO_IP,
IP_MINTTL, &minttl, sizeof(minttl)))
err(1, "set IP min TTL");
2016-06-30 08:18:03 -05:00
+#endif
2018-11-07 20:00:29 -06:00
2016-06-30 20:00:29 -05:00
- else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
2016-06-30 05:49:38 -05:00
+#ifdef IPV6_MINHOPCOUNT
2016-06-30 08:18:03 -05:00
+ if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
2016-06-30 20:00:29 -05:00
IPV6_MINHOPCOUNT, &minttl, sizeof(minttl)))
err(1, "set IPv6 min hop count");
2016-06-30 05:49:38 -05:00
+#endif
2016-06-30 20:00:29 -05:00
}
2016-06-30 05:49:38 -05:00
}
2018-11-07 20:00:29 -06:00
@@ -1748,14 +1781,22 @@
2015-09-13 11:56:41 -05:00
\t-P proxyuser\tUsername for proxy authentication\n\
\t-p port\t Specify local port for remote connects\n\
\t-R CAfile CA bundle\n\
- \t-r Randomize remote ports\n\
- \t-S Enable the TCP MD5 signature option\n\
+ \t-r Randomize remote ports\n"
+#ifdef TCP_MD5SIG
2017-02-07 18:38:03 +09:00
+ "\
+ \t-S Enable the TCP MD5 signature option\n"
2015-09-13 11:56:41 -05:00
+#endif
2017-02-07 18:38:03 +09:00
+ "\
\t-s source Local source address\n\
2015-09-13 11:56:41 -05:00
\t-T keyword TOS value or TLS options\n\
\t-t Answer TELNET negotiation\n\
\t-U Use UNIX domain socket\n\
- \t-u UDP mode\n\
- \t-V rtable Specify alternate routing table\n\
+ \t-u UDP mode\n"
+#ifdef SO_RTABLE
2017-02-07 18:38:03 +09:00
+ "\
+ \t-V rtable Specify alternate routing table\n"
2015-09-13 11:56:41 -05:00
+#endif
2017-02-07 18:38:03 +09:00
+ "\
\t-v Verbose\n\
2017-06-03 20:13:25 -05:00
\t-W recvlimit Terminate after receiving a number of packets\n\
2015-09-13 11:56:41 -05:00
\t-w timeout Timeout for connects and final net reads\n\