summaryrefslogtreecommitdiff
path: root/src/usr.bin/nc/netcat.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/usr.bin/nc/netcat.c36
1 files changed, 33 insertions, 3 deletions
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);