summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordtucker <>2005-10-25 03:51:06 +0000
committerdtucker <>2005-10-25 03:51:06 +0000
commit217071930a238940c034c11686f3195c117a4404 (patch)
tree9197b3fe9c348ece06fcd2f323e84a8fd42e78a2
parent2f8369815e35a8eedb488c0052bcff027fe7391c (diff)
downloadopenbsd-217071930a238940c034c11686f3195c117a4404.tar.gz
openbsd-217071930a238940c034c11686f3195c117a4404.tar.bz2
openbsd-217071930a238940c034c11686f3195c117a4404.zip
Add a -T option to nc to allow setting of IP type-of-service bits on
connections. Man page corrections jmc@, code corrections and ok djm@
-rw-r--r--src/usr.bin/nc/nc.111
-rw-r--r--src/usr.bin/nc/netcat.c36
2 files changed, 43 insertions, 4 deletions
diff --git a/src/usr.bin/nc/nc.1 b/src/usr.bin/nc/nc.1
index 773de16135..85e18a53f7 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.40 2005/07/17 19:18:47 jmc Exp $ 1.\" $OpenBSD: nc.1,v 1.41 2005/10/25 03:51:06 dtucker Exp $
2.\" 2.\"
3.\" Copyright (c) 1996 David Sacerdote 3.\" Copyright (c) 1996 David Sacerdote
4.\" All rights reserved. 4.\" All rights reserved.
@@ -38,6 +38,7 @@
38.Op Fl i Ar interval 38.Op Fl i Ar interval
39.Op Fl p Ar source_port 39.Op Fl p Ar source_port
40.Op Fl s Ar source_ip_address 40.Op Fl s Ar source_ip_address
41.Op Fl T Ar ToS
41.Op Fl w Ar timeout 42.Op Fl w Ar timeout
42.Op Fl X Ar proxy_protocol 43.Op Fl X Ar proxy_protocol
43.Oo Xo 44.Oo Xo
@@ -145,6 +146,14 @@ Specifies the IP of the interface which is used to send the packets.
145It is an error to use this option in conjunction with the 146It is an error to use this option in conjunction with the
146.Fl l 147.Fl l
147option. 148option.
149.It Fl T Ar ToS
150Specifies IP Type of Service (ToS) for the connection.
151Valid values are the tokens
152.Dq lowdelay ,
153.Dq throughput ,
154.Dq reliability ,
155or an 8-bit hexadecimal value preceded by
156.Dq 0x .
148.It Fl t 157.It Fl t
149Causes 158Causes
150.Nm 159.Nm
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c
index c298ade67f..fde125641c 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.82 2005/07/24 09:33:56 marius Exp $ */ 1/* $OpenBSD: netcat.c,v 1.83 2005/10/25 03:51:06 dtucker Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> 3 * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
4 * 4 *
@@ -37,7 +37,9 @@
37#include <sys/un.h> 37#include <sys/un.h>
38 38
39#include <netinet/in.h> 39#include <netinet/in.h>
40#include <netinet/in_systm.h>
40#include <netinet/tcp.h> 41#include <netinet/tcp.h>
42#include <netinet/ip.h>
41#include <arpa/telnet.h> 43#include <arpa/telnet.h>
42 44
43#include <err.h> 45#include <err.h>
@@ -77,6 +79,7 @@ int xflag; /* Socks proxy */
77int zflag; /* Port Scan Flag */ 79int zflag; /* Port Scan Flag */
78int Dflag; /* sodebug */ 80int Dflag; /* sodebug */
79int Sflag; /* TCP MD5 signature option */ 81int Sflag; /* TCP MD5 signature option */
82int Tflag = -1; /* IP Type of Service */
80 83
81int timeout = -1; 84int timeout = -1;
82int family = AF_UNSPEC; 85int family = AF_UNSPEC;
@@ -94,6 +97,7 @@ int udptest(int);
94int unix_connect(char *); 97int unix_connect(char *);
95int unix_listen(char *); 98int unix_listen(char *);
96int set_common_sockopts(int); 99int set_common_sockopts(int);
100int parse_iptos(char *);
97void usage(int); 101void usage(int);
98 102
99int 103int
@@ -118,7 +122,7 @@ main(int argc, char *argv[])
118 sv = NULL; 122 sv = NULL;
119 123
120 while ((ch = getopt(argc, argv, 124 while ((ch = getopt(argc, argv,
121 "46Ddhi:jklnp:rSs:tUuvw:X:x:z")) != -1) { 125 "46Ddhi:jklnp:rSs:tT:Uuvw:X:x:z")) != -1) {
122 switch (ch) { 126 switch (ch) {
123 case '4': 127 case '4':
124 family = AF_INET; 128 family = AF_INET;
@@ -202,6 +206,9 @@ main(int argc, char *argv[])
202 case 'S': 206 case 'S':
203 Sflag = 1; 207 Sflag = 1;
204 break; 208 break;
209 case 'T':
210 Tflag = parse_iptos(optarg);
211 break;
205 default: 212 default:
206 usage(1); 213 usage(1);
207 } 214 }
@@ -772,6 +779,28 @@ set_common_sockopts(int s)
772 &x, sizeof(x)) == -1) 779 &x, sizeof(x)) == -1)
773 err(1, NULL); 780 err(1, NULL);
774 } 781 }
782 if (Tflag != -1) {
783 if (setsockopt(s, IPPROTO_IP, IP_TOS,
784 &Tflag, sizeof(Tflag)) == -1)
785 err(1, "set IP ToS");
786 }
787}
788
789int
790parse_iptos(char *s)
791{
792 int tos = -1;
793
794 if (strcmp(s, "lowdelay") == 0)
795 return (IPTOS_LOWDELAY);
796 if (strcmp(s, "throughput") == 0)
797 return (IPTOS_THROUGHPUT);
798 if (strcmp(s, "reliability") == 0)
799 return (IPTOS_RELIABILITY);
800
801 if (sscanf(s, "0x%x", &tos) != 1 || tos < 0 || tos > 0xff)
802 errx(1, "invalid IP Type of Service");
803 return (tos);
775} 804}
776 805
777void 806void
@@ -792,6 +821,7 @@ help(void)
792 \t-r Randomize remote ports\n\ 821 \t-r Randomize remote ports\n\
793 \t-S Enable the TCP MD5 signature option\n\ 822 \t-S Enable the TCP MD5 signature option\n\
794 \t-s addr\t Local source address\n\ 823 \t-s addr\t Local source address\n\
824 \t-T ToS\t Set IP Type of Service\n\
795 \t-t Answer TELNET negotiation\n\ 825 \t-t Answer TELNET negotiation\n\
796 \t-U Use UNIX domain socket\n\ 826 \t-U Use UNIX domain socket\n\
797 \t-u UDP mode\n\ 827 \t-u UDP mode\n\
@@ -808,7 +838,7 @@ void
808usage(int ret) 838usage(int ret)
809{ 839{
810 fprintf(stderr, "usage: nc [-46DdhklnrStUuvz] [-i interval] [-p source_port]\n"); 840 fprintf(stderr, "usage: nc [-46DdhklnrStUuvz] [-i interval] [-p source_port]\n");
811 fprintf(stderr, "\t [-s source_ip_address] [-w timeout] [-X proxy_version]\n"); 841 fprintf(stderr, "\t [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_version]\n");
812 fprintf(stderr, "\t [-x proxy_address[:port]] [hostname] [port[s]]\n"); 842 fprintf(stderr, "\t [-x proxy_address[:port]] [hostname] [port[s]]\n");
813 if (ret) 843 if (ret)
814 exit(1); 844 exit(1);