version 1.12, 2009/08/29 04:10:49 |
version 1.13, 2009/09/08 11:43:51 |
|
|
} |
} |
|
|
static void __dead |
static void __dead |
clientloop(kvm_t *kvmh, u_long ktcbtab, const char *host, const char *port, int nconn) |
clientloop(kvm_t *kvmh, u_long ktcbtab, struct addrinfo *aitop, int nconn) |
{ |
{ |
struct addrinfo *aitop, *ai, hints; |
struct addrinfo *ai; |
struct statctx *psc; |
struct statctx *psc; |
struct pollfd *pfd; |
struct pollfd *pfd; |
char tmp[128], *buf; |
char tmp[128], *buf; |
|
|
err(1, "clientloop psc calloc"); |
err(1, "clientloop psc calloc"); |
|
|
for (i = 0; i < nconn; i++) { |
for (i = 0; i < nconn; i++) { |
bzero(&hints, sizeof(hints)); |
|
hints.ai_socktype = SOCK_STREAM; |
|
hints.ai_flags = 0; |
|
if ((herr = getaddrinfo(host, port, &hints, &aitop)) != 0) { |
|
if (herr == EAI_SYSTEM) |
|
err(1, "getaddrinfo"); |
|
else |
|
errx(1, "c getaddrinfo: %s", gai_strerror(herr)); |
|
} |
|
|
|
for (sock = -1, ai = aitop; ai != NULL; ai = ai->ai_next) { |
for (sock = -1, ai = aitop; ai != NULL; ai = ai->ai_next) { |
saddr_ntop(ai->ai_addr, ai->ai_addrlen, tmp, |
saddr_ntop(ai->ai_addr, ai->ai_addrlen, tmp, |
sizeof(tmp)); |
sizeof(tmp)); |
|
|
} |
} |
break; |
break; |
} |
} |
freeaddrinfo(aitop); |
|
if (sock == -1) |
if (sock == -1) |
errx(1, "No host found"); |
errx(1, "No host found"); |
|
|
|
|
mainstats.nconns++; |
mainstats.nconns++; |
scnt++; |
scnt++; |
} |
} |
|
freeaddrinfo(aitop); |
|
|
if (vflag && scnt > 1) |
if (vflag && scnt > 1) |
fprintf(stderr, "%u connections established\n", scnt); |
fprintf(stderr, "%u connections established\n", scnt); |
|
|
if (!sflag) |
if (!sflag) |
host = argv[0]; |
host = argv[0]; |
|
|
if (sflag) { |
bzero(&hints, sizeof(hints)); |
bzero(&hints, sizeof(hints)); |
hints.ai_socktype = SOCK_STREAM; |
hints.ai_socktype = SOCK_STREAM; |
if (sflag) |
hints.ai_flags = AI_PASSIVE; |
hints.ai_flags = AI_PASSIVE; |
if ((herr = getaddrinfo(host, port, &hints, &aitop)) != 0) { |
if ((herr = getaddrinfo(host, port, &hints, &aitop)) != 0) { |
if (herr == EAI_SYSTEM) |
if (herr == EAI_SYSTEM) |
err(1, "getaddrinfo"); |
err(1, "getaddrinfo"); |
else |
else |
errx(1, "s getaddrinfo: %s", gai_strerror(herr)); |
errx(1, "getaddrinfo: %s", gai_strerror(herr)); |
} |
|
} |
} |
|
|
if (kflag) { |
if (kflag) { |
|
|
if (sflag) |
if (sflag) |
serverloop(kvmh, nl[0].n_value, aitop); |
serverloop(kvmh, nl[0].n_value, aitop); |
else |
else |
clientloop(kvmh, nl[0].n_value, host, port, nconn); |
clientloop(kvmh, nl[0].n_value, aitop, nconn); |
|
|
return 0; |
return 0; |
} |
} |