diff options
| author | dtucker <> | 2005-10-25 03:51:06 +0000 |
|---|---|---|
| committer | dtucker <> | 2005-10-25 03:51:06 +0000 |
| commit | 217071930a238940c034c11686f3195c117a4404 (patch) | |
| tree | 9197b3fe9c348ece06fcd2f323e84a8fd42e78a2 /src | |
| parent | 2f8369815e35a8eedb488c0052bcff027fe7391c (diff) | |
| download | openbsd-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@
Diffstat (limited to '')
| -rw-r--r-- | src/usr.bin/nc/nc.1 | 11 | ||||
| -rw-r--r-- | src/usr.bin/nc/netcat.c | 36 |
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. | |||
| 145 | It is an error to use this option in conjunction with the | 146 | It is an error to use this option in conjunction with the |
| 146 | .Fl l | 147 | .Fl l |
| 147 | option. | 148 | option. |
| 149 | .It Fl T Ar ToS | ||
| 150 | Specifies IP Type of Service (ToS) for the connection. | ||
| 151 | Valid values are the tokens | ||
| 152 | .Dq lowdelay , | ||
| 153 | .Dq throughput , | ||
| 154 | .Dq reliability , | ||
| 155 | or an 8-bit hexadecimal value preceded by | ||
| 156 | .Dq 0x . | ||
| 148 | .It Fl t | 157 | .It Fl t |
| 149 | Causes | 158 | Causes |
| 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 */ | |||
| 77 | int zflag; /* Port Scan Flag */ | 79 | int zflag; /* Port Scan Flag */ |
| 78 | int Dflag; /* sodebug */ | 80 | int Dflag; /* sodebug */ |
| 79 | int Sflag; /* TCP MD5 signature option */ | 81 | int Sflag; /* TCP MD5 signature option */ |
| 82 | int Tflag = -1; /* IP Type of Service */ | ||
| 80 | 83 | ||
| 81 | int timeout = -1; | 84 | int timeout = -1; |
| 82 | int family = AF_UNSPEC; | 85 | int family = AF_UNSPEC; |
| @@ -94,6 +97,7 @@ int udptest(int); | |||
| 94 | int unix_connect(char *); | 97 | int unix_connect(char *); |
| 95 | int unix_listen(char *); | 98 | int unix_listen(char *); |
| 96 | int set_common_sockopts(int); | 99 | int set_common_sockopts(int); |
| 100 | int parse_iptos(char *); | ||
| 97 | void usage(int); | 101 | void usage(int); |
| 98 | 102 | ||
| 99 | int | 103 | int |
| @@ -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 | |||
| 789 | int | ||
| 790 | parse_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 | ||
| 777 | void | 806 | void |
| @@ -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 | |||
| 808 | usage(int ret) | 838 | usage(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); |
