summaryrefslogtreecommitdiff
path: root/src/usr.bin/nc/netcat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr.bin/nc/netcat.c')
-rw-r--r--src/usr.bin/nc/netcat.c76
1 files changed, 59 insertions, 17 deletions
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 *);
105int unix_connect(char *); 105int unix_connect(char *);
106int unix_listen(char *); 106int unix_listen(char *);
107void set_common_sockopts(int); 107void set_common_sockopts(int);
108int parse_iptos(char *); 108int map_tos(char *, int *);
109void usage(int); 109void usage(int);
110 110
111int 111int
@@ -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
876int 887int
877parse_iptos(char *s) 888map_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
893void 935void
@@ -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\