summaryrefslogtreecommitdiff
path: root/src/usr.bin/nc/netcat.c
diff options
context:
space:
mode:
authorjca <>2016-06-28 17:35:14 +0000
committerjca <>2016-06-28 17:35:14 +0000
commitaa239d08d6dc87fdd121f62e3130aa5d5357cfff (patch)
tree73f19bc916ea3e0c14048b016c16e6bb3831c93f /src/usr.bin/nc/netcat.c
parent489edfaf43be1bb7fb8cd79e07e04dd5ef93f81e (diff)
downloadopenbsd-aa239d08d6dc87fdd121f62e3130aa5d5357cfff.tar.gz
openbsd-aa239d08d6dc87fdd121f62e3130aa5d5357cfff.tar.bz2
openbsd-aa239d08d6dc87fdd121f62e3130aa5d5357cfff.zip
Add -M and -m options to specify the outgoing and incoming minimum TTL
Req by and ok blumh@
Diffstat (limited to '')
-rw-r--r--src/usr.bin/nc/netcat.c50
1 files changed, 43 insertions, 7 deletions
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;
115int family = AF_UNSPEC; 115int family = AF_UNSPEC;
116char *portlist[PORT_MAX+1]; 116char *portlist[PORT_MAX+1];
117char *unix_dg_tmp_socket; 117char *unix_dg_tmp_socket;
118int ttl = -1;
119int minttl = -1;
118 120
119void atelnet(int, unsigned char *, unsigned int); 121void atelnet(int, unsigned char *, unsigned int);
120void build_ports(char *); 122void 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
1428int 1463int
@@ -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}