diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/usr.bin/nc/netcat.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/usr.bin/nc/netcat.c b/src/usr.bin/nc/netcat.c index 7a523ccaba..ce7fde4525 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.126 2014/10/30 16:08:31 tedu Exp $ */ | 1 | /* $OpenBSD: netcat.c,v 1.127 2015/02/14 22:40:22 jca Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> | 3 | * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> |
4 | * | 4 | * |
@@ -113,7 +113,7 @@ int udptest(int); | |||
113 | int unix_bind(char *); | 113 | int unix_bind(char *); |
114 | int unix_connect(char *); | 114 | int unix_connect(char *); |
115 | int unix_listen(char *); | 115 | int unix_listen(char *); |
116 | void set_common_sockopts(int); | 116 | void set_common_sockopts(int, int); |
117 | int map_tos(char *, int *); | 117 | int map_tos(char *, int *); |
118 | void report_connect(const struct sockaddr *, socklen_t); | 118 | void report_connect(const struct sockaddr *, socklen_t); |
119 | void usage(int); | 119 | void usage(int); |
@@ -619,7 +619,7 @@ remote_connect(const char *host, const char *port, struct addrinfo hints) | |||
619 | freeaddrinfo(ares); | 619 | freeaddrinfo(ares); |
620 | } | 620 | } |
621 | 621 | ||
622 | set_common_sockopts(s); | 622 | set_common_sockopts(s, res0->ai_family); |
623 | 623 | ||
624 | if (timeout_connect(s, res0->ai_addr, res0->ai_addrlen) == 0) | 624 | if (timeout_connect(s, res0->ai_addr, res0->ai_addrlen) == 0) |
625 | break; | 625 | break; |
@@ -712,7 +712,7 @@ local_listen(char *host, char *port, struct addrinfo hints) | |||
712 | if (ret == -1) | 712 | if (ret == -1) |
713 | err(1, NULL); | 713 | err(1, NULL); |
714 | 714 | ||
715 | set_common_sockopts(s); | 715 | set_common_sockopts(s, res0->ai_family); |
716 | 716 | ||
717 | if (bind(s, (struct sockaddr *)res0->ai_addr, | 717 | if (bind(s, (struct sockaddr *)res0->ai_addr, |
718 | res0->ai_addrlen) == 0) | 718 | res0->ai_addrlen) == 0) |
@@ -1128,7 +1128,7 @@ udptest(int s) | |||
1128 | } | 1128 | } |
1129 | 1129 | ||
1130 | void | 1130 | void |
1131 | set_common_sockopts(int s) | 1131 | set_common_sockopts(int s, int af) |
1132 | { | 1132 | { |
1133 | int x = 1; | 1133 | int x = 1; |
1134 | 1134 | ||
@@ -1143,8 +1143,17 @@ set_common_sockopts(int s) | |||
1143 | err(1, NULL); | 1143 | err(1, NULL); |
1144 | } | 1144 | } |
1145 | if (Tflag != -1) { | 1145 | if (Tflag != -1) { |
1146 | if (setsockopt(s, IPPROTO_IP, IP_TOS, | 1146 | int proto, option; |
1147 | &Tflag, sizeof(Tflag)) == -1) | 1147 | |
1148 | if (af == AF_INET6) { | ||
1149 | proto = IPPROTO_IPV6; | ||
1150 | option = IPV6_TCLASS; | ||
1151 | } else { | ||
1152 | proto = IPPROTO_IP; | ||
1153 | option = IP_TOS; | ||
1154 | } | ||
1155 | |||
1156 | if (setsockopt(s, proto, option, &Tflag, sizeof(Tflag)) == -1) | ||
1148 | err(1, "set IP ToS"); | 1157 | err(1, "set IP ToS"); |
1149 | } | 1158 | } |
1150 | if (Iflag) { | 1159 | if (Iflag) { |