partial sync of regress/netcat.c with upstream

Support for nc -T on IPv6 addresses.

ok sthen@
This commit is contained in:
jca 2015-02-14 22:40:22 +00:00 committed by Damien Miller
parent 4c60724405
commit e18435fec1
1 changed files with 16 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: netcat.c,v 1.126 2014/10/30 16:08:31 tedu Exp $ */ /* $OpenBSD: netcat.c,v 1.127 2015/02/14 22:40:22 jca Exp $ */
/* /*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org> * Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
* *
@ -133,7 +133,7 @@ int udptest(int);
int unix_bind(char *); int unix_bind(char *);
int unix_connect(char *); int unix_connect(char *);
int unix_listen(char *); int unix_listen(char *);
void set_common_sockopts(int); void set_common_sockopts(int, int);
int map_tos(char *, int *); int map_tos(char *, int *);
void report_connect(const struct sockaddr *, socklen_t); void report_connect(const struct sockaddr *, socklen_t);
void usage(int); void usage(int);
@ -648,7 +648,7 @@ remote_connect(const char *host, const char *port, struct addrinfo hints)
freeaddrinfo(ares); freeaddrinfo(ares);
} }
set_common_sockopts(s); set_common_sockopts(s, res0->ai_family);
if (timeout_connect(s, res0->ai_addr, res0->ai_addrlen) == 0) if (timeout_connect(s, res0->ai_addr, res0->ai_addrlen) == 0)
break; break;
@ -748,7 +748,7 @@ local_listen(char *host, char *port, struct addrinfo hints)
if (ret == -1) if (ret == -1)
err(1, "setsockopt SO_REUSEADDR"); err(1, "setsockopt SO_REUSEADDR");
#endif #endif
set_common_sockopts(s); set_common_sockopts(s, res0->ai_family);
if (bind(s, (struct sockaddr *)res0->ai_addr, if (bind(s, (struct sockaddr *)res0->ai_addr,
res0->ai_addrlen) == 0) res0->ai_addrlen) == 0)
@ -1168,7 +1168,7 @@ udptest(int s)
} }
void void
set_common_sockopts(int s) set_common_sockopts(int s, int af)
{ {
int x = 1; int x = 1;
@ -1186,8 +1186,17 @@ set_common_sockopts(int s)
} }
#ifdef IP_TOS #ifdef IP_TOS
if (Tflag != -1) { if (Tflag != -1) {
if (setsockopt(s, IPPROTO_IP, IP_TOS, int proto, option;
&Tflag, sizeof(Tflag)) == -1)
if (af == AF_INET6) {
proto = IPPROTO_IPV6;
option = IPV6_TCLASS;
} else {
proto = IPPROTO_IP;
option = IP_TOS;
}
if (setsockopt(s, proto, option, &Tflag, sizeof(Tflag)) == -1)
err(1, "set IP ToS"); err(1, "set IP ToS");
} }
#endif #endif