From 44c7c549be71e27b4b98e0ce4952d84859d6c88c Mon Sep 17 00:00:00 2001 From: jca Date: Mon, 26 Oct 2015 00:33:03 +0000 Subject: [PATCH] Set low-delay traffic class for IPv6 connections as well While here, there is no option to pass a different tos, and no other use of the "tos" variable out of tn(), so move the "tos" variable in tn() and assign it the right value from the start. ok millert@ --- usr.bin/telnet/commands.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c index 18533121a0a..e2d1052f9c4 100644 --- a/usr.bin/telnet/commands.c +++ b/usr.bin/telnet/commands.c @@ -1,4 +1,4 @@ -/* $OpenBSD: commands.c,v 1.73 2015/10/25 14:42:02 jca Exp $ */ +/* $OpenBSD: commands.c,v 1.74 2015/10/26 00:33:03 jca Exp $ */ /* $NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $ */ /* @@ -54,8 +54,6 @@ #define PATH_SKEY "/usr/bin/skey" #endif -int tos = -1; - char *hostname; typedef struct { @@ -1850,7 +1848,7 @@ tn(int argc, char *argv[]) struct addrinfo hints, *res, *res0; char *cmd, *hostp = 0, *portp = 0, *user = 0, *aliasp = 0; int error, retry; - const int niflags = NI_NUMERICHOST; + const int niflags = NI_NUMERICHOST, tos = IPTOS_LOWDELAY; if (connected) { printf("?Already connected to %s\r\n", hostname); @@ -1973,13 +1971,18 @@ tn(int argc, char *argv[]) } freeaddrinfo(ares); } - if (res->ai_family == AF_INET) { - if (tos < 0) - tos = IPTOS_LOWDELAY; /* Low Delay bit */ - if (tos - && (setsockopt(net, IPPROTO_IP, IP_TOS, &tos, sizeof(int)) < 0) - && (errno != ENOPROTOOPT)) - perror("telnet: setsockopt (IP_TOS) (ignored)"); + + switch (res->ai_family) { + case AF_INET: + if (setsockopt(net, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0 + && errno != ENOPROTOOPT) + perror("telnet: setsockopt (IP_TOS) (ignored)"); + break; + case AF_INET6: + if (setsockopt(net, IPPROTO_IPV6, IPV6_TCLASS, &tos, + sizeof(tos)) < 0 && errno != ENOPROTOOPT) + perror("telnet: setsockopt (IPV6_TCLASS) (ignored)"); + break; } if (debug) { -- 2.20.1