From 9f39e938a6c42b8427291c7208db4a5413610352 Mon Sep 17 00:00:00 2001 From: dlg Date: Tue, 19 Aug 2014 03:28:53 +0000 Subject: [PATCH] add -4 and -6 flags for saying if you want to force ipv4 or ipv6 respectively. tweaks from jmc@ ok djm@ --- usr.bin/tcpbench/tcpbench.1 | 16 ++++++++++++---- usr.bin/tcpbench/tcpbench.c | 14 +++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/usr.bin/tcpbench/tcpbench.1 b/usr.bin/tcpbench/tcpbench.1 index 757cd133064..b1aa5612361 100644 --- a/usr.bin/tcpbench/tcpbench.1 +++ b/usr.bin/tcpbench/tcpbench.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tcpbench.1,v 1.19 2014/02/26 20:56:11 claudio Exp $ +.\" $OpenBSD: tcpbench.1,v 1.20 2014/08/19 03:28:53 dlg Exp $ .\" .\" Copyright (c) 2008 Damien Miller .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: February 26 2014 $ +.Dd $Mdocdate: August 19 2014 $ .Dt TCPBENCH 1 .Os .Sh NAME @@ -24,7 +24,7 @@ .Nm .Fl l .Nm -.Op Fl uv +.Op Fl 46uv .Op Fl B Ar buf .Op Fl b Ar addr .Op Fl k Ar kvars @@ -39,7 +39,7 @@ .Nm .Bk -words .Fl s -.Op Fl uv +.Op Fl 46uv .Op Fl B Ar buf .Op Fl k Ar kvars .Op Fl p Ar port @@ -75,6 +75,14 @@ option. .Pp The options are as follows: .Bl -tag -width Ds +.It Fl 4 +Forces +.Nm +to use IPv4 addresses only. +.It Fl 6 +Forces +.Nm +to use IPv6 addresses only. .It Fl B Ar buf Specify the size of the internal read/write buffer used by .Nm . diff --git a/usr.bin/tcpbench/tcpbench.c b/usr.bin/tcpbench/tcpbench.c index 43f59012ad1..24c42d69050 100644 --- a/usr.bin/tcpbench/tcpbench.c +++ b/usr.bin/tcpbench/tcpbench.c @@ -180,10 +180,10 @@ usage(void) { fprintf(stderr, "usage: tcpbench -l\n" - " tcpbench [-uv] [-B buf] [-b addr] [-k kvars] [-n connections]\n" + " tcpbench [-46uv] [-B buf] [-b addr] [-k kvars] [-n connections]\n" " [-p port] [-r interval] [-S space] [-T toskeyword]\n" " [-t secs] [-V rtable] hostname\n" - " tcpbench -s [-uv] [-B buf] [-k kvars] [-p port]\n" + " tcpbench -s [-46uv] [-B buf] [-k kvars] [-p port]\n" " [-r interval] [-S space] [-T toskeyword] [-V rtable]\n"); exit(1); } @@ -997,6 +997,7 @@ main(int argc, char **argv) const char *errstr; struct rlimit rl; int ch, herr, nconn; + int family = PF_UNSPEC; struct nlist nl[] = { { "_tcbtable" }, { "" } }; const char *host = NULL, *port = DEFAULT_PORT, *srcbind = NULL; struct event ev_sigint, ev_sigterm, ev_sighup, ev_progtimer; @@ -1015,8 +1016,14 @@ main(int argc, char **argv) aib = NULL; secs = 0; - while ((ch = getopt(argc, argv, "b:B:hlk:n:p:r:sS:t:T:uvV:")) != -1) { + while ((ch = getopt(argc, argv, "46b:B:hlk:n:p:r:sS:t:T:uvV:")) != -1) { switch (ch) { + case '4': + family = PF_INET; + break; + case '6': + family = PF_INET6; + break; case 'b': srcbind = optarg; break; @@ -1124,6 +1131,7 @@ main(int argc, char **argv) } bzero(&hints, sizeof(hints)); + hints.ai_family = family; if (UDP_MODE) { hints.ai_socktype = SOCK_DGRAM; hints.ai_protocol = IPPROTO_UDP; -- 2.20.1