1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
--- apps/nc/netcat.c.orig Sat Aug 17 03:21:05 2024
+++ apps/nc/netcat.c Sat Aug 17 03:28:50 2024
@@ -93,9 +93,13 @@ int zflag; /* Port Scan Flag */
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
int usetls; /* use TLS */
const char *Cflag; /* Public cert file */
@@ -268,12 +272,14 @@ main(int argc, char *argv[])
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;
@@ -320,9 +326,11 @@ main(int argc, char *argv[])
case 'o':
oflag = optarg;
break;
+#ifdef TCP_MD5SIG
case 'S':
Sflag = 1;
break;
+#endif
case 'T':
errstr = NULL;
errno = 0;
@@ -346,9 +354,11 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
+#ifdef SO_RTABLE
if (rtableid >= 0)
if (setrtable(rtableid) == -1)
err(1, "setrtable");
+#endif
/* Cruft to make sure options are clean, and used properly. */
if (argc == 1 && family == AF_UNIX) {
@@ -923,7 +933,10 @@ remote_connect(const char *host, const char *port, str
char *ipaddr)
{
struct addrinfo *res, *res0;
- int s = -1, error, herr, on = 1, save_errno;
+ int s = -1, error, herr, save_errno;
+#ifdef SO_BINDANY
+ int on = 1;
+#endif
if ((error = getaddrinfo(host, port, &hints, &res0)))
errx(1, "getaddrinfo for host \"%s\" port %s: %s", host,
@@ -938,8 +951,10 @@ remote_connect(const char *host, const char *port, str
if (sflag || pflag) {
struct addrinfo ahints, *ares;
+#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));
ahints.ai_family = res->ai_family;
ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
@@ -1031,7 +1046,10 @@ int
local_listen(const char *host, const char *port, struct addrinfo hints)
{
struct addrinfo *res, *res0;
- int s = -1, ret, x = 1, save_errno;
+ int s = -1, save_errno;
+#ifdef SO_REUSEPORT
+ int ret, x = 1;
+#endif
int error;
/* Allow nodename to be null. */
@@ -1052,9 +1070,11 @@ local_listen(const char *host, const char *port, struc
res->ai_protocol)) == -1)
continue;
+#ifdef SO_REUSEPORT
ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
if (ret == -1)
err(1, NULL);
+#endif
set_common_sockopts(s, res->ai_family);
@@ -1559,11 +1579,13 @@ set_common_sockopts(int s, int af)
{
int x = 1;
+#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)
@@ -1574,9 +1596,16 @@ set_common_sockopts(int s, int af)
IP_TOS, &Tflag, sizeof(Tflag)) == -1)
err(1, "set IP ToS");
+#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;
+ err(1, "set IPv6 traffic class not supported");
+ }
+#endif
}
if (Iflag) {
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
@@ -1600,13 +1629,17 @@ set_common_sockopts(int s, int af)
}
if (minttl != -1) {
+#ifdef IP_MINTTL
if (af == AF_INET && setsockopt(s, IPPROTO_IP,
IP_MINTTL, &minttl, sizeof(minttl)))
err(1, "set IP min TTL");
+#endif
- else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
+#ifdef IPV6_MINHOPCOUNT
+ if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
IPV6_MINHOPCOUNT, &minttl, sizeof(minttl)))
err(1, "set IPv6 min hop count");
+#endif
}
}
@@ -1831,15 +1864,19 @@ help(void)
\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-s sourceaddr Local source address\n\
+ \t-r Randomize remote ports\n"
+#ifdef TCP_MD5SIG
+ "\t-S Enable the TCP MD5 signature option\n"
+#endif
+ "\t-s sourceaddr Local source address\n\
\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-v Verbose\n\
+ \t-u UDP mode\n"
+#ifdef SO_RTABLE
+ "\t-V rtable Specify alternate routing table\n"
+#endif
+ "\t-v Verbose\n\
\t-W recvlimit Terminate after receiving a number of packets\n\
\t-w timeout Timeout for connects and final net reads\n\
\t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\
|