diff options
author | simokawa <simokawa@FreeBSD.org> | 2003-07-25 21:07:10 +0800 |
---|---|---|
committer | simokawa <simokawa@FreeBSD.org> | 2003-07-25 21:07:10 +0800 |
commit | 00c676572b7accdf48cae88f465b32a5835d42c5 (patch) | |
tree | c298dcd024e4febc4092c9ad6582f5a82ed32397 | |
parent | 2882151c58f00281c35a0dc48e9f1e8820439d0f (diff) | |
download | freebsd-ports-gnome-00c676572b7accdf48cae88f465b32a5835d42c5.tar.gz freebsd-ports-gnome-00c676572b7accdf48cae88f465b32a5835d42c5.tar.zst freebsd-ports-gnome-00c676572b7accdf48cae88f465b32a5835d42c5.zip |
Add support for ipv6.
-rw-r--r-- | benchmarks/tcpblast/Makefile | 4 | ||||
-rw-r--r-- | benchmarks/tcpblast/src/tcpblast.c | 84 |
2 files changed, 50 insertions, 38 deletions
diff --git a/benchmarks/tcpblast/Makefile b/benchmarks/tcpblast/Makefile index b96efe83418e..e6b4d0c92e4c 100644 --- a/benchmarks/tcpblast/Makefile +++ b/benchmarks/tcpblast/Makefile @@ -7,8 +7,8 @@ # port's source files are in src dir in portball PORTNAME= tcpblast -PORTVERSION= 1.0 -CATEGORIES= benchmarks net +PORTVERSION= 1.1 +CATEGORIES= benchmarks net ipv6 DISTFILES= # none MAINTAINER= ports@FreeBSD.org diff --git a/benchmarks/tcpblast/src/tcpblast.c b/benchmarks/tcpblast/src/tcpblast.c index c538b0a3c852..6cfcb621f87d 100644 --- a/benchmarks/tcpblast/src/tcpblast.c +++ b/benchmarks/tcpblast/src/tcpblast.c @@ -17,6 +17,8 @@ #include <unistd.h> #include <stdlib.h> #include <string.h> +#include <getopt.h> +#include <errno.h> #define BLKSIZE 1024 @@ -35,53 +37,63 @@ int f; int main(argc, argv) int argc; char **argv; { + struct addrinfo hints, *res, *res0; + char *cause = NULL; + int ch, proto, error; register int i; - if (argc!=3) - { - fprintf(stderr, "usage: tcpblast destination nblkocks\n"); - fprintf(stderr, "blocksize: %d bytes\n", BLKSIZE); - exit(1); + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + while ((ch = getopt(argc, argv, "46")) != -1) { + switch (ch) { + case '4': + hints.ai_family = PF_INET; + break; + case '6': + hints.ai_family = PF_INET6; + break; + } } - - nblocks = atoi(argv[2]); - if (nblocks<=1 || nblocks>=10000) - { - fprintf(stderr, "tcpblast: 1 < nblocks <= 10000 \n"); + argc -= optind; + argv += optind; + if (argc != 2) { + fprintf(stderr, + "usage: tcpblast [-4] [-6] destination nblkocks\n" + "blocksize: %d bytes %d\n", BLKSIZE, argc); exit(1); } - bzero((char *)&sock_in, sizeof (sock_in)); - sock_in.sin_family = AF_INET; - f = socket(AF_INET, SOCK_STREAM, 0); - if (f < 0) { - perror("tcpblast: socket"); - exit(3); - } - if (bind(f, (struct sockaddr*) &sock_in, sizeof (sock_in)) < 0) { - perror("tcpblast: bind"); + nblocks = atoi(argv[1]); + if (nblocks<=1 || nblocks>=10000) { + fprintf(stderr, "tcpblast: 1 < nblocks <= 10000 \n"); exit(1); } - host = gethostbyname(argv[1]); - if (host) { - sock_in.sin_family = host->h_addrtype; - bcopy(host->h_addr, &sock_in.sin_addr, host->h_length); - } else { - sock_in.sin_family = AF_INET; - sock_in.sin_addr.s_addr = inet_addr(argv[1]); - if (sock_in.sin_addr.s_addr == -1) { - fprintf(stderr, "tcpblast: %s unknown host\n", argv[1]); - exit(1); + error = getaddrinfo(argv[0], "discard", &hints, &res0); + if (error) + errx(1, "%s", gai_strerror(error)); + f = -1; + cause = "no addresses"; + errno = EADDRNOTAVAIL; + for (res = res0; res; res = res->ai_next) { + f = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if (f < 0) { + cause = "socket"; + continue; } + if (connect(f, res->ai_addr, res->ai_addrlen) < 0) { + cause = "connect"; + close(f); + f = -1; + continue; + } + break; } - sock_in.sin_port = htons(9); - - if (connect(f, (struct sockaddr*) &sock_in, sizeof(sock_in)) <0) - { - perror("tcpblast connect:"); - exit(1); - } + if (f < 0) + err(1, cause); + freeaddrinfo(res); if (gettimeofday(&ti, &tiz) < 0) { |