diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/usr.bin/nc/nc.1 | 11 | ||||
-rw-r--r-- | src/usr.bin/nc/netcat.c | 50 |
2 files changed, 52 insertions, 9 deletions
diff --git a/src/usr.bin/nc/nc.1 b/src/usr.bin/nc/nc.1 index ee57a64a6b..384442b603 100644 --- a/src/usr.bin/nc/nc.1 +++ b/src/usr.bin/nc/nc.1 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: nc.1,v 1.72 2016/06/02 04:26:32 beck Exp $ | 1 | .\" $OpenBSD: nc.1,v 1.73 2016/06/28 17:35:14 jca Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1996 David Sacerdote | 3 | .\" Copyright (c) 1996 David Sacerdote |
4 | .\" All rights reserved. | 4 | .\" All rights reserved. |
@@ -25,7 +25,7 @@ | |||
25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | .\" | 27 | .\" |
28 | .Dd $Mdocdate: June 2 2016 $ | 28 | .Dd $Mdocdate: June 28 2016 $ |
29 | .Dt NC 1 | 29 | .Dt NC 1 |
30 | .Os | 30 | .Os |
31 | .Sh NAME | 31 | .Sh NAME |
@@ -40,6 +40,8 @@ | |||
40 | .Op Fl I Ar length | 40 | .Op Fl I Ar length |
41 | .Op Fl i Ar interval | 41 | .Op Fl i Ar interval |
42 | .Op Fl K Ar keyfile | 42 | .Op Fl K Ar keyfile |
43 | .Op Fl M Ar ttl | ||
44 | .Op Fl m Ar minttl | ||
43 | .Op Fl O Ar length | 45 | .Op Fl O Ar length |
44 | .Op Fl P Ar proxy_username | 46 | .Op Fl P Ar proxy_username |
45 | .Op Fl p Ar source_port | 47 | .Op Fl p Ar source_port |
@@ -171,6 +173,11 @@ options. | |||
171 | Additionally, any timeouts specified with the | 173 | Additionally, any timeouts specified with the |
172 | .Fl w | 174 | .Fl w |
173 | option are ignored. | 175 | option are ignored. |
176 | .It Fl M Ar ttl | ||
177 | Set the TTL / Hop Limit of outgoing packets. | ||
178 | .It Fl m Ar minttl | ||
179 | Ask the kernel to drop incoming packets whose TTL / Hop Limit is under | ||
180 | .Ar minttl . | ||
174 | .It Fl N | 181 | .It Fl N |
175 | .Xr shutdown 2 | 182 | .Xr shutdown 2 |
176 | the network socket after EOF on the input. | 183 | the network socket after EOF on the input. |
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index 99fea29b03..cc5d58f25e 100644 --- a/src/usr.bin/nc/netcat.c +++ b/src/usr.bin/nc/netcat.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: netcat.c,v 1.155 2016/06/28 00:01:10 deraadt Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.156 2016/06/28 17:35:14 jca Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
4 | * Copyright (c) 2015 Bob Beck. All rights reserved. | 4 | * Copyright (c) 2015 Bob Beck. All rights reserved. |
@@ -115,6 +115,8 @@ int timeout = -1; | |||
115 | int family = AF_UNSPEC; | 115 | int family = AF_UNSPEC; |
116 | char *portlist[PORT_MAX+1]; | 116 | char *portlist[PORT_MAX+1]; |
117 | char *unix_dg_tmp_socket; | 117 | char *unix_dg_tmp_socket; |
118 | int ttl = -1; | ||
119 | int minttl = -1; | ||
118 | 120 | ||
119 | void atelnet(int, unsigned char *, unsigned int); | 121 | void atelnet(int, unsigned char *, unsigned int); |
120 | void build_ports(char *); | 122 | void build_ports(char *); |
@@ -166,7 +168,7 @@ main(int argc, char *argv[]) | |||
166 | signal(SIGPIPE, SIG_IGN); | 168 | signal(SIGPIPE, SIG_IGN); |
167 | 169 | ||
168 | while ((ch = getopt(argc, argv, | 170 | while ((ch = getopt(argc, argv, |
169 | "46C:cDde:FH:hI:i:K:klNnO:P:p:R:rSs:T:tUuV:vw:X:x:z")) != -1) { | 171 | "46C:cDde:FH:hI:i:K:klM:m:NnO:P:p:R:rSs:T:tUuV:vw:X:x:z")) != -1) { |
170 | switch (ch) { | 172 | switch (ch) { |
171 | case '4': | 173 | case '4': |
172 | family = AF_INET; | 174 | family = AF_INET; |
@@ -222,6 +224,16 @@ main(int argc, char *argv[]) | |||
222 | case 'l': | 224 | case 'l': |
223 | lflag = 1; | 225 | lflag = 1; |
224 | break; | 226 | break; |
227 | case 'M': | ||
228 | ttl = strtonum(optarg, 0, 255, &errstr); | ||
229 | if (errstr) | ||
230 | errx(1, "ttl is %s", errstr); | ||
231 | break; | ||
232 | case 'm': | ||
233 | minttl = strtonum(optarg, 0, 255, &errstr); | ||
234 | if (errstr) | ||
235 | errx(1, "minttl is %s", errstr); | ||
236 | break; | ||
225 | case 'N': | 237 | case 'N': |
226 | Nflag = 1; | 238 | Nflag = 1; |
227 | break; | 239 | break; |
@@ -1423,6 +1435,29 @@ set_common_sockopts(int s, int af) | |||
1423 | &Oflag, sizeof(Oflag)) == -1) | 1435 | &Oflag, sizeof(Oflag)) == -1) |
1424 | err(1, "set TCP send buffer size"); | 1436 | err(1, "set TCP send buffer size"); |
1425 | } | 1437 | } |
1438 | if (ttl != -1 || minttl != -1) { | ||
1439 | int proto, in_ttl_opt, out_ttl_opt; | ||
1440 | switch (af) { | ||
1441 | case AF_INET: | ||
1442 | proto = IPPROTO_IP; | ||
1443 | in_ttl_opt = IP_MINTTL; | ||
1444 | out_ttl_opt = IP_TTL; | ||
1445 | break; | ||
1446 | case AF_INET6: | ||
1447 | proto = IPPROTO_IPV6; | ||
1448 | in_ttl_opt = IPV6_MINHOPCOUNT; | ||
1449 | out_ttl_opt = IPV6_UNICAST_HOPS; | ||
1450 | break; | ||
1451 | default: | ||
1452 | errx(1, "unknown address family: %d", af); | ||
1453 | } | ||
1454 | if (minttl != -1 && setsockopt(s, proto, in_ttl_opt, | ||
1455 | &minttl, sizeof(minttl))) | ||
1456 | err(1, "setsockopt minttl"); | ||
1457 | if (ttl != -1 && setsockopt(s, proto, out_ttl_opt, | ||
1458 | &ttl, sizeof(ttl))) | ||
1459 | err(1, "setsockopt ttl"); | ||
1460 | } | ||
1426 | } | 1461 | } |
1427 | 1462 | ||
1428 | int | 1463 | int |
@@ -1570,6 +1605,8 @@ help(void) | |||
1570 | \t-K keyfile Private key file\n\ | 1605 | \t-K keyfile Private key file\n\ |
1571 | \t-k Keep inbound sockets open for multiple connects\n\ | 1606 | \t-k Keep inbound sockets open for multiple connects\n\ |
1572 | \t-l Listen mode, for inbound connects\n\ | 1607 | \t-l Listen mode, for inbound connects\n\ |
1608 | \t-M ttl Outgoing TTL / Hop Limit\n\ | ||
1609 | \t-m minttl Minimum incoming TTL / Hop Limit\n\ | ||
1573 | \t-N Shutdown the network socket after EOF on stdin\n\ | 1610 | \t-N Shutdown the network socket after EOF on stdin\n\ |
1574 | \t-n Suppress name/port resolutions\n\ | 1611 | \t-n Suppress name/port resolutions\n\ |
1575 | \t-O length TCP send buffer length\n\ | 1612 | \t-O length TCP send buffer length\n\ |
@@ -1599,11 +1636,10 @@ usage(int ret) | |||
1599 | fprintf(stderr, | 1636 | fprintf(stderr, |
1600 | "usage: nc [-46cDdFhklNnrStUuvz] [-C certfile] [-e name] " | 1637 | "usage: nc [-46cDdFhklNnrStUuvz] [-C certfile] [-e name] " |
1601 | "[-H hash] [-I length]\n" | 1638 | "[-H hash] [-I length]\n" |
1602 | "\t [-i interval] [-K keyfile] [-O length] [-P proxy_username]\n" | 1639 | "\t [-i interval] [-K keyfile] [-M ttl] [-m minttl] [-O length]\n" |
1603 | "\t [-p source_port] [-R CAfile] [-s source] " | 1640 | "\t [-P proxy_username] [-p source_port] [-R CAfile] [-s source]\n" |
1604 | "[-T keyword] [-V rtable]\n" | 1641 | "\t [-T keyword] [-V rtable] [-w timeout] [-X proxy_protocol]\n" |
1605 | "\t [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]]\n" | 1642 | "\t [-x proxy_address[:port]] [destination] [port]\n"); |
1606 | "\t [destination] [port]\n"); | ||
1607 | if (ret) | 1643 | if (ret) |
1608 | exit(1); | 1644 | exit(1); |
1609 | } | 1645 | } |