refine netcat patch
This commit is contained in:
parent
13b7ac8ada
commit
ec4c98718d
@ -1,17 +1,6 @@
|
|||||||
--- apps/nc/netcat.c.orig Wed Jun 29 21:28:27 2016
|
--- apps/nc/netcat.c.orig Wed Jun 29 21:28:27 2016
|
||||||
+++ apps/nc/netcat.c Thu Jun 30 05:32:31 2016
|
+++ apps/nc/netcat.c Thu Jun 30 08:16:42 2016
|
||||||
@@ -57,6 +57,10 @@
|
@@ -65,7 +65,9 @@
|
||||||
#include <tls.h>
|
|
||||||
#include "atomicio.h"
|
|
||||||
|
|
||||||
+#ifndef IPV6_TCLASS
|
|
||||||
+#define IPV6_TCLASS -1
|
|
||||||
+#endif
|
|
||||||
+
|
|
||||||
#define PORT_MAX 65535
|
|
||||||
#define UNIX_DG_TMP_SOCKET_SIZE 19
|
|
||||||
|
|
||||||
@@ -65,7 +69,9 @@
|
|
||||||
#define POLL_NETIN 2
|
#define POLL_NETIN 2
|
||||||
#define POLL_STDOUT 3
|
#define POLL_STDOUT 3
|
||||||
#define BUFSIZE 16384
|
#define BUFSIZE 16384
|
||||||
@ -21,7 +10,7 @@
|
|||||||
|
|
||||||
#define TLS_LEGACY (1 << 1)
|
#define TLS_LEGACY (1 << 1)
|
||||||
#define TLS_NOVERIFY (1 << 2)
|
#define TLS_NOVERIFY (1 << 2)
|
||||||
@@ -92,9 +98,13 @@
|
@@ -92,9 +94,13 @@
|
||||||
int Dflag; /* sodebug */
|
int Dflag; /* sodebug */
|
||||||
int Iflag; /* TCP receive buffer size */
|
int Iflag; /* TCP receive buffer size */
|
||||||
int Oflag; /* TCP send buffer size */
|
int Oflag; /* TCP send buffer size */
|
||||||
@ -35,7 +24,7 @@
|
|||||||
|
|
||||||
int usetls; /* use TLS */
|
int usetls; /* use TLS */
|
||||||
char *Cflag; /* Public cert file */
|
char *Cflag; /* Public cert file */
|
||||||
@@ -152,7 +162,7 @@
|
@@ -152,7 +158,7 @@
|
||||||
struct servent *sv;
|
struct servent *sv;
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
struct sockaddr_storage cliaddr;
|
struct sockaddr_storage cliaddr;
|
||||||
@ -44,7 +33,7 @@
|
|||||||
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];
|
||||||
@@ -262,12 +272,14 @@
|
@@ -262,12 +268,14 @@
|
||||||
case 'u':
|
case 'u':
|
||||||
uflag = 1;
|
uflag = 1;
|
||||||
break;
|
break;
|
||||||
@ -59,7 +48,7 @@
|
|||||||
case 'v':
|
case 'v':
|
||||||
vflag = 1;
|
vflag = 1;
|
||||||
break;
|
break;
|
||||||
@@ -300,9 +312,11 @@
|
@@ -300,9 +308,11 @@
|
||||||
errx(1, "TCP send window %s: %s",
|
errx(1, "TCP send window %s: %s",
|
||||||
errstr, optarg);
|
errstr, optarg);
|
||||||
break;
|
break;
|
||||||
@ -71,7 +60,7 @@
|
|||||||
case 'T':
|
case 'T':
|
||||||
errstr = NULL;
|
errstr = NULL;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
@@ -326,9 +340,11 @@
|
@@ -326,9 +336,11 @@
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
@ -83,7 +72,7 @@
|
|||||||
|
|
||||||
if (family == AF_UNIX) {
|
if (family == AF_UNIX) {
|
||||||
if (pledge("stdio rpath wpath cpath tmppath unix", NULL) == -1)
|
if (pledge("stdio rpath wpath cpath tmppath unix", NULL) == -1)
|
||||||
@@ -480,7 +496,10 @@
|
@@ -480,7 +492,10 @@
|
||||||
errx(1, "-H and -T noverify may not be used"
|
errx(1, "-H and -T noverify may not be used"
|
||||||
"together");
|
"together");
|
||||||
tls_config_insecure_noverifycert(tls_cfg);
|
tls_config_insecure_noverifycert(tls_cfg);
|
||||||
@ -95,7 +84,7 @@
|
|||||||
}
|
}
|
||||||
if (lflag) {
|
if (lflag) {
|
||||||
struct tls *tls_cctx = NULL;
|
struct tls *tls_cctx = NULL;
|
||||||
@@ -832,7 +851,10 @@
|
@@ -832,7 +847,10 @@
|
||||||
remote_connect(const char *host, const char *port, struct addrinfo hints)
|
remote_connect(const char *host, const char *port, struct addrinfo hints)
|
||||||
{
|
{
|
||||||
struct addrinfo *res, *res0;
|
struct addrinfo *res, *res0;
|
||||||
@ -107,7 +96,7 @@
|
|||||||
|
|
||||||
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));
|
||||||
@@ -847,8 +869,10 @@
|
@@ -847,8 +865,10 @@
|
||||||
if (sflag || pflag) {
|
if (sflag || pflag) {
|
||||||
struct addrinfo ahints, *ares;
|
struct addrinfo ahints, *ares;
|
||||||
|
|
||||||
@ -118,7 +107,7 @@
|
|||||||
memset(&ahints, 0, sizeof(struct addrinfo));
|
memset(&ahints, 0, sizeof(struct addrinfo));
|
||||||
ahints.ai_family = res0->ai_family;
|
ahints.ai_family = res0->ai_family;
|
||||||
ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
|
ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
|
||||||
@@ -919,7 +943,10 @@
|
@@ -919,7 +939,10 @@
|
||||||
local_listen(char *host, char *port, struct addrinfo hints)
|
local_listen(char *host, char *port, struct addrinfo hints)
|
||||||
{
|
{
|
||||||
struct addrinfo *res, *res0;
|
struct addrinfo *res, *res0;
|
||||||
@ -130,7 +119,7 @@
|
|||||||
int error;
|
int error;
|
||||||
|
|
||||||
/* Allow nodename to be null. */
|
/* Allow nodename to be null. */
|
||||||
@@ -941,9 +968,11 @@
|
@@ -941,9 +964,11 @@
|
||||||
res0->ai_protocol)) < 0)
|
res0->ai_protocol)) < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -142,7 +131,7 @@
|
|||||||
|
|
||||||
set_common_sockopts(s, res0->ai_family);
|
set_common_sockopts(s, res0->ai_family);
|
||||||
|
|
||||||
@@ -1401,29 +1430,26 @@
|
@@ -1401,29 +1426,28 @@
|
||||||
{
|
{
|
||||||
int x = 1;
|
int x = 1;
|
||||||
|
|
||||||
@ -174,13 +163,15 @@
|
|||||||
+ IP_TOS, &Tflag, sizeof(Tflag)) == -1)
|
+ IP_TOS, &Tflag, sizeof(Tflag)) == -1)
|
||||||
err(1, "set IP ToS");
|
err(1, "set IP ToS");
|
||||||
+
|
+
|
||||||
+ else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
|
+#ifdef IPV6_TCLASS
|
||||||
|
+ if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
|
||||||
+ IPV6_TCLASS, &Tflag, sizeof(Tflag)) == -1)
|
+ IPV6_TCLASS, &Tflag, sizeof(Tflag)) == -1)
|
||||||
+ err(1, "set IPv6 Traffic Class");
|
+ err(1, "set IPv6 traffic class");
|
||||||
|
+#endif
|
||||||
}
|
}
|
||||||
if (Iflag) {
|
if (Iflag) {
|
||||||
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
|
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
|
||||||
@@ -1435,29 +1461,28 @@
|
@@ -1435,29 +1459,30 @@
|
||||||
&Oflag, sizeof(Oflag)) == -1)
|
&Oflag, sizeof(Oflag)) == -1)
|
||||||
err(1, "set TCP send buffer size");
|
err(1, "set TCP send buffer size");
|
||||||
}
|
}
|
||||||
@ -209,23 +200,25 @@
|
|||||||
+
|
+
|
||||||
+ if (ttl != -1) {
|
+ if (ttl != -1) {
|
||||||
+ if (af == AF_INET && setsockopt(s, IPPROTO_IP,
|
+ if (af == AF_INET && setsockopt(s, IPPROTO_IP,
|
||||||
+ IP_TTL, &ttl, sizeof(ttl)))
|
+ IP_TTL, &ttl, sizeof(ttl)))
|
||||||
+ err(1, "setsockopt IP_TTL");
|
+ err(1, "set IP TTL");
|
||||||
+
|
+
|
||||||
+ else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
|
+ if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
|
||||||
+ IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)))
|
+ IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)))
|
||||||
+ err(1, "setsockopt IPV6_UNICAST_HOPS");
|
+ err(1, "set IPv6 unicast hops");
|
||||||
}
|
}
|
||||||
+
|
+
|
||||||
+ if (minttl != -1) {
|
+ if (minttl != -1) {
|
||||||
|
+#ifdef IP_MINTTL
|
||||||
+ if (af == AF_INET && setsockopt(s, IPPROTO_IP,
|
+ if (af == AF_INET && setsockopt(s, IPPROTO_IP,
|
||||||
+ IP_MINTTL, &minttl, sizeof(minttl)))
|
+ IP_MINTTL, &minttl, sizeof(minttl)) == -1)
|
||||||
+ err(1, "setsockopt IP_MINTTL");
|
+ err(1, "set IP min TTL");
|
||||||
|
+#endif
|
||||||
+
|
+
|
||||||
+#ifdef IPV6_MINHOPCOUNT
|
+#ifdef IPV6_MINHOPCOUNT
|
||||||
+ else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
|
+ if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
|
||||||
+ IPV6_MINHOPCOUNT, &minttl, sizeof(minttl)))
|
+ IPV6_MINHOPCOUNT, &minttl, sizeof(minttl)) == -1)
|
||||||
+ err(1, "setsockopt IPV6_MINHOPCOUNT");
|
+ err(1, "set IPv6 min hop count");
|
||||||
+#endif
|
+#endif
|
||||||
+ }
|
+ }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user