diff options
author | claudio <> | 2009-06-05 00:18:10 +0000 |
---|---|---|
committer | claudio <> | 2009-06-05 00:18:10 +0000 |
commit | 9786c8dfdc5c1f13ffb7a2dce02b769c67704bef (patch) | |
tree | 907ea4a5e63ea363b17cf1ac82e2f1e9374af7f5 | |
parent | 437d0850ff5e9cf554cfb2790235e5c0b30f94b3 (diff) | |
download | openbsd-9786c8dfdc5c1f13ffb7a2dce02b769c67704bef.tar.gz openbsd-9786c8dfdc5c1f13ffb7a2dce02b769c67704bef.tar.bz2 openbsd-9786c8dfdc5c1f13ffb7a2dce02b769c67704bef.zip |
The networking swissarmy knife needs to work on alternate domains as well.
Again -V can be used to specify the domain.
-rw-r--r-- | src/usr.bin/nc/nc.1 | 7 | ||||
-rw-r--r-- | src/usr.bin/nc/netcat.c | 28 |
2 files changed, 29 insertions, 6 deletions
diff --git a/src/usr.bin/nc/nc.1 b/src/usr.bin/nc/nc.1 index e8dfeea077..c8bb9b071d 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.48 2008/09/19 13:24:41 sobrado Exp $ | 1 | .\" $OpenBSD: nc.1,v 1.49 2009/06/05 00:18:10 claudio 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: September 19 2008 $ | 28 | .Dd $Mdocdate: June 5 2009 $ |
29 | .Dt NC 1 | 29 | .Dt NC 1 |
30 | .Os | 30 | .Os |
31 | .Sh NAME | 31 | .Sh NAME |
@@ -42,6 +42,7 @@ | |||
42 | .Op Fl p Ar source_port | 42 | .Op Fl p Ar source_port |
43 | .Op Fl s Ar source_ip_address | 43 | .Op Fl s Ar source_ip_address |
44 | .Op Fl T Ar ToS | 44 | .Op Fl T Ar ToS |
45 | .Op Fl V Ar rdomain | ||
45 | .Op Fl w Ar timeout | 46 | .Op Fl w Ar timeout |
46 | .Op Fl X Ar proxy_protocol | 47 | .Op Fl X Ar proxy_protocol |
47 | .Oo Xo | 48 | .Oo Xo |
@@ -176,6 +177,8 @@ to script telnet sessions. | |||
176 | Specifies to use Unix Domain Sockets. | 177 | Specifies to use Unix Domain Sockets. |
177 | .It Fl u | 178 | .It Fl u |
178 | Use UDP instead of the default option of TCP. | 179 | Use UDP instead of the default option of TCP. |
180 | .It Fl V Ar rdomain | ||
181 | Set the routing domain, the default is 0. | ||
179 | .It Fl v | 182 | .It Fl v |
180 | Have | 183 | Have |
181 | .Nm | 184 | .Nm |
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index e465073506..6700f89cfe 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.92 2008/09/19 13:24:41 sobrado Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.93 2009/06/05 00:18:10 claudio Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
4 | * | 4 | * |
@@ -84,6 +84,7 @@ int Iflag; /* TCP receive buffer size */ | |||
84 | int Oflag; /* TCP send buffer size */ | 84 | int Oflag; /* TCP send buffer size */ |
85 | int Sflag; /* TCP MD5 signature option */ | 85 | int Sflag; /* TCP MD5 signature option */ |
86 | int Tflag = -1; /* IP Type of Service */ | 86 | int Tflag = -1; /* IP Type of Service */ |
87 | u_int rdomain; | ||
87 | 88 | ||
88 | int timeout = -1; | 89 | int timeout = -1; |
89 | int family = AF_UNSPEC; | 90 | int family = AF_UNSPEC; |
@@ -125,7 +126,7 @@ main(int argc, char *argv[]) | |||
125 | sv = NULL; | 126 | sv = NULL; |
126 | 127 | ||
127 | while ((ch = getopt(argc, argv, | 128 | while ((ch = getopt(argc, argv, |
128 | "46DdhI:i:jklnO:P:p:rSs:tT:Uuvw:X:x:z")) != -1) { | 129 | "46DdhI:i:jklnO:P:p:rSs:tT:UuV:vw:X:x:z")) != -1) { |
129 | switch (ch) { | 130 | switch (ch) { |
130 | case '4': | 131 | case '4': |
131 | family = AF_INET; | 132 | family = AF_INET; |
@@ -187,6 +188,12 @@ main(int argc, char *argv[]) | |||
187 | case 'u': | 188 | case 'u': |
188 | uflag = 1; | 189 | uflag = 1; |
189 | break; | 190 | break; |
191 | case 'V': | ||
192 | rdomain = (unsigned int)strtonum(optarg, 0, | ||
193 | RT_TABLEID_MAX, &errstr); | ||
194 | if (errstr) | ||
195 | errx(1, "rdomain %s: %s", errstr, optarg); | ||
196 | break; | ||
190 | case 'v': | 197 | case 'v': |
191 | vflag = 1; | 198 | vflag = 1; |
192 | break; | 199 | break; |
@@ -498,6 +505,12 @@ remote_connect(const char *host, const char *port, struct addrinfo hints) | |||
498 | res0->ai_protocol)) < 0) | 505 | res0->ai_protocol)) < 0) |
499 | continue; | 506 | continue; |
500 | 507 | ||
508 | if (rdomain) { | ||
509 | if (setsockopt(s, IPPROTO_IP, SO_RDOMAIN, &rdomain, | ||
510 | sizeof(rdomain)) == -1) | ||
511 | err(1, "setsockopt SO_RDOMAIN"); | ||
512 | } | ||
513 | |||
501 | /* Bind to a local port or source address if specified. */ | 514 | /* Bind to a local port or source address if specified. */ |
502 | if (sflag || pflag) { | 515 | if (sflag || pflag) { |
503 | struct addrinfo ahints, *ares; | 516 | struct addrinfo ahints, *ares; |
@@ -566,6 +579,12 @@ local_listen(char *host, char *port, struct addrinfo hints) | |||
566 | res0->ai_protocol)) < 0) | 579 | res0->ai_protocol)) < 0) |
567 | continue; | 580 | continue; |
568 | 581 | ||
582 | if (rdomain) { | ||
583 | if (setsockopt(s, IPPROTO_IP, SO_RDOMAIN, &rdomain, | ||
584 | sizeof(rdomain)) == -1) | ||
585 | err(1, "setsockopt SO_RDOMAIN"); | ||
586 | } | ||
587 | |||
569 | ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); | 588 | ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x)); |
570 | if (ret == -1) | 589 | if (ret == -1) |
571 | err(1, NULL); | 590 | err(1, NULL); |
@@ -851,6 +870,7 @@ help(void) | |||
851 | \t-t Answer TELNET negotiation\n\ | 870 | \t-t Answer TELNET negotiation\n\ |
852 | \t-U Use UNIX domain socket\n\ | 871 | \t-U Use UNIX domain socket\n\ |
853 | \t-u UDP mode\n\ | 872 | \t-u UDP mode\n\ |
873 | \t-V rdomain Specify alternate routing domain\n\ | ||
854 | \t-v Verbose\n\ | 874 | \t-v Verbose\n\ |
855 | \t-w secs\t Timeout for connects and final net reads\n\ | 875 | \t-w secs\t Timeout for connects and final net reads\n\ |
856 | \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\ | 876 | \t-X proto Proxy protocol: \"4\", \"5\" (SOCKS) or \"connect\"\n\ |
@@ -866,8 +886,8 @@ usage(int ret) | |||
866 | fprintf(stderr, | 886 | fprintf(stderr, |
867 | "usage: nc [-46DdhklnrStUuvz] [-I length] [-i interval] [-O length]\n" | 887 | "usage: nc [-46DdhklnrStUuvz] [-I length] [-i interval] [-O length]\n" |
868 | "\t [-P proxy_username] [-p source_port] [-s source_ip_address] [-T ToS]\n" | 888 | "\t [-P proxy_username] [-p source_port] [-s source_ip_address] [-T ToS]\n" |
869 | "\t [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [hostname]\n" | 889 | "\t [-V rdomain] [-w timeout] [-X proxy_protocol]\n" |
870 | "\t [port]\n"); | 890 | "\t [-x proxy_address[:port]] [hostname] [port]\n"); |
871 | if (ret) | 891 | if (ret) |
872 | exit(1); | 892 | exit(1); |
873 | } | 893 | } |