/* * tcpblast - test and estimate TCP thruput * * Daniel Karrenberg * * I released tcpblast into the public domain, so it is OK to * redistribute it. I am also fine with attaching the same public * license that is used for OpenBSD itself. Your choice. * * Daniel */ #include #include #include #include #include #include #include #include #include #include #include #include #include #define BLKSIZE 1024 struct sockaddr_in sock_in; struct servent *sp; struct hostent *host; long starts, startms, stops, stopms, expms; struct timeval ti; struct timezone tiz; char greet[BLKSIZE] = "Hi!"; int nblocks; int f; int main(argc, argv) int argc; char **argv; { struct addrinfo hints, *res, *res0; char *cause = NULL; int ch, error; register int i; 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; } } 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); } nblocks = atoi(argv[1]); if (nblocks<=1 || nblocks>=10000) { fprintf(stderr, "tcpblast: 1 < nblocks < 10000 \n"); 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; } if (f < 0) err(1, cause); freeaddrinfo(res); if (gettimeofday(&ti, &tiz) < 0) { perror("tcpblast time:"); exit(1); } starts = ti.tv_sec; startms = ti.tv_usec / 1000L; for (i=0; i