diff options
author | haesbaert <> | 2011-09-17 14:10:05 +0000 |
---|---|---|
committer | haesbaert <> | 2011-09-17 14:10:05 +0000 |
commit | 338a262ca79ae9a01c09ccaea32717c943d757bf (patch) | |
tree | 9bef3d73231dd68443d5a20e51b0c62a238e62e5 | |
parent | 1814786ce700b8ec3d2d804be90b9f18eec360a9 (diff) | |
download | openbsd-338a262ca79ae9a01c09ccaea32717c943d757bf.tar.gz openbsd-338a262ca79ae9a01c09ccaea32717c943d757bf.tar.bz2 openbsd-338a262ca79ae9a01c09ccaea32717c943d757bf.zip |
Standarize the ToS option across nc/ping/traceroute so that they'll
accept the same values as pf.conf. It accepts decimal, hexadecimal and
the dscp/tos keywords. The ping option was ripped of in SMALL.
ok mcbride@ sthen@
-rw-r--r-- | src/usr.bin/nc/nc.1 | 29 | ||||
-rw-r--r-- | src/usr.bin/nc/netcat.c | 76 |
2 files changed, 77 insertions, 28 deletions
diff --git a/src/usr.bin/nc/nc.1 b/src/usr.bin/nc/nc.1 index f9bd5b153e..6a1538cb45 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.57 2011/01/09 22:16:46 jeremy Exp $ | 1 | .\" $OpenBSD: nc.1,v 1.58 2011/09/17 14:10:05 haesbaert 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: January 9 2011 $ | 28 | .Dd $Mdocdate: September 17 2011 $ |
29 | .Dt NC 1 | 29 | .Dt NC 1 |
30 | .Os | 30 | .Os |
31 | .Sh NAME | 31 | .Sh NAME |
@@ -41,7 +41,7 @@ | |||
41 | .Op Fl P Ar proxy_username | 41 | .Op Fl P Ar proxy_username |
42 | .Op Fl p Ar source_port | 42 | .Op Fl p Ar source_port |
43 | .Op Fl s Ar source | 43 | .Op Fl s Ar source |
44 | .Op Fl T Ar ToS | 44 | .Op Fl T Ar toskeyword |
45 | .Op Fl V Ar rtable | 45 | .Op Fl V Ar rtable |
46 | .Op Fl w Ar timeout | 46 | .Op Fl w Ar timeout |
47 | .Op Fl X Ar proxy_protocol | 47 | .Op Fl X Ar proxy_protocol |
@@ -164,14 +164,21 @@ to create and use so that datagrams can be received. | |||
164 | It is an error to use this option in conjunction with the | 164 | It is an error to use this option in conjunction with the |
165 | .Fl l | 165 | .Fl l |
166 | option. | 166 | option. |
167 | .It Fl T Ar ToS | 167 | .It Fl T Ar toskeyword |
168 | Specifies IP Type of Service (ToS) for the connection. | 168 | Change IPv4 TOS value. |
169 | Valid values are the tokens | 169 | .Ar toskeyword |
170 | .Dq lowdelay , | 170 | may be one of |
171 | .Dq throughput , | 171 | .Ar critical , |
172 | .Dq reliability , | 172 | .Ar inetcontrol , |
173 | or an 8-bit hexadecimal value preceded by | 173 | .Ar lowdelay , |
174 | .Dq 0x . | 174 | .Ar netcontrol , |
175 | .Ar throughput , | ||
176 | .Ar reliability , | ||
177 | or one of the DiffServ Code Points: | ||
178 | .Ar ef , | ||
179 | .Ar af11 ... af43 , | ||
180 | .Ar cs0 ... cs7 ; | ||
181 | or a number in either hex or decimal. | ||
175 | .It Fl t | 182 | .It Fl t |
176 | Causes | 183 | Causes |
177 | .Nm | 184 | .Nm |
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index a5f5745f3a..952bfb7dda 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.101 2011/06/21 17:31:07 mikeb Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.102 2011/09/17 14:10:05 haesbaert Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
4 | * | 4 | * |
@@ -105,7 +105,7 @@ int unix_bind(char *); | |||
105 | int unix_connect(char *); | 105 | int unix_connect(char *); |
106 | int unix_listen(char *); | 106 | int unix_listen(char *); |
107 | void set_common_sockopts(int); | 107 | void set_common_sockopts(int); |
108 | int parse_iptos(char *); | 108 | int map_tos(char *, int *); |
109 | void usage(int); | 109 | void usage(int); |
110 | 110 | ||
111 | int | 111 | int |
@@ -234,7 +234,18 @@ main(int argc, char *argv[]) | |||
234 | Sflag = 1; | 234 | Sflag = 1; |
235 | break; | 235 | break; |
236 | case 'T': | 236 | case 'T': |
237 | Tflag = parse_iptos(optarg); | 237 | errstr = NULL; |
238 | errno = 0; | ||
239 | if (map_tos(optarg, &Tflag)) | ||
240 | break; | ||
241 | if (strlen(optarg) > 1 && optarg[0] == '0' && | ||
242 | optarg[1] == 'x') | ||
243 | Tflag = (int)strtol(optarg, NULL, 16); | ||
244 | else | ||
245 | Tflag = (int)strtonum(optarg, 0, 255, | ||
246 | &errstr); | ||
247 | if (Tflag < 0 || Tflag > 255 || errstr || errno) | ||
248 | errx(1, "illegal tos value %s", optarg); | ||
238 | break; | 249 | break; |
239 | default: | 250 | default: |
240 | usage(1); | 251 | usage(1); |
@@ -874,20 +885,51 @@ set_common_sockopts(int s) | |||
874 | } | 885 | } |
875 | 886 | ||
876 | int | 887 | int |
877 | parse_iptos(char *s) | 888 | map_tos(char *s, int *val) |
878 | { | 889 | { |
879 | int tos = -1; | 890 | /* DiffServ Codepoints and other TOS mappings */ |
880 | 891 | const struct toskeywords { | |
881 | if (strcmp(s, "lowdelay") == 0) | 892 | const char *keyword; |
882 | return (IPTOS_LOWDELAY); | 893 | int val; |
883 | if (strcmp(s, "throughput") == 0) | 894 | } *t, toskeywords[] = { |
884 | return (IPTOS_THROUGHPUT); | 895 | { "af11", IPTOS_DSCP_AF11 }, |
885 | if (strcmp(s, "reliability") == 0) | 896 | { "af12", IPTOS_DSCP_AF12 }, |
886 | return (IPTOS_RELIABILITY); | 897 | { "af13", IPTOS_DSCP_AF13 }, |
887 | 898 | { "af21", IPTOS_DSCP_AF21 }, | |
888 | if (sscanf(s, "0x%x", &tos) != 1 || tos < 0 || tos > 0xff) | 899 | { "af22", IPTOS_DSCP_AF22 }, |
889 | errx(1, "invalid IP Type of Service"); | 900 | { "af23", IPTOS_DSCP_AF23 }, |
890 | return (tos); | 901 | { "af31", IPTOS_DSCP_AF31 }, |
902 | { "af32", IPTOS_DSCP_AF32 }, | ||
903 | { "af33", IPTOS_DSCP_AF33 }, | ||
904 | { "af41", IPTOS_DSCP_AF41 }, | ||
905 | { "af42", IPTOS_DSCP_AF42 }, | ||
906 | { "af43", IPTOS_DSCP_AF43 }, | ||
907 | { "critical", IPTOS_PREC_CRITIC_ECP }, | ||
908 | { "cs0", IPTOS_DSCP_CS0 }, | ||
909 | { "cs1", IPTOS_DSCP_CS1 }, | ||
910 | { "cs2", IPTOS_DSCP_CS2 }, | ||
911 | { "cs3", IPTOS_DSCP_CS3 }, | ||
912 | { "cs4", IPTOS_DSCP_CS4 }, | ||
913 | { "cs5", IPTOS_DSCP_CS5 }, | ||
914 | { "cs6", IPTOS_DSCP_CS6 }, | ||
915 | { "cs7", IPTOS_DSCP_CS7 }, | ||
916 | { "ef", IPTOS_DSCP_EF }, | ||
917 | { "inetcontrol", IPTOS_PREC_INTERNETCONTROL }, | ||
918 | { "lowdelay", IPTOS_LOWDELAY }, | ||
919 | { "netcontrol", IPTOS_PREC_NETCONTROL }, | ||
920 | { "reliability", IPTOS_RELIABILITY }, | ||
921 | { "throughput", IPTOS_THROUGHPUT }, | ||
922 | { NULL, -1 }, | ||
923 | }; | ||
924 | |||
925 | for (t = toskeywords; t->keyword != NULL; t++) { | ||
926 | if (strcmp(s, t->keyword) == 0) { | ||
927 | *val = t->val; | ||
928 | return (1); | ||
929 | } | ||
930 | } | ||
931 | |||
932 | return (0); | ||
891 | } | 933 | } |
892 | 934 | ||
893 | void | 935 | void |
@@ -911,7 +953,7 @@ help(void) | |||
911 | \t-r Randomize remote ports\n\ | 953 | \t-r Randomize remote ports\n\ |
912 | \t-S Enable the TCP MD5 signature option\n\ | 954 | \t-S Enable the TCP MD5 signature option\n\ |
913 | \t-s addr\t Local source address\n\ | 955 | \t-s addr\t Local source address\n\ |
914 | \t-T ToS\t Set IP Type of Service\n\ | 956 | \t-T toskeyword\tSet IP Type of Service\n\ |
915 | \t-t Answer TELNET negotiation\n\ | 957 | \t-t Answer TELNET negotiation\n\ |
916 | \t-U Use UNIX domain socket\n\ | 958 | \t-U Use UNIX domain socket\n\ |
917 | \t-u UDP mode\n\ | 959 | \t-u UDP mode\n\ |