summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2009-09-08 11:43:52 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2009-09-08 11:43:52 +0000
commita902b1e4dfffce389fe333e257157a11077fbdcf (patch)
tree542f762e162d2c015c8d5995762b941e66ce2d3c /usr.bin
parentd3083d83679eec9f2d45310450bb546c635ffa2f (diff)
There is no need for two getaddrinfo implementations for client and server.
Merge them and make the client code look more like the server one. OK henning@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tcpbench/tcpbench.c35
1 files changed, 12 insertions, 23 deletions
diff --git a/usr.bin/tcpbench/tcpbench.c b/usr.bin/tcpbench/tcpbench.c
index 2ed5ce45a10..648eeccfde1 100644
--- a/usr.bin/tcpbench/tcpbench.c
+++ b/usr.bin/tcpbench/tcpbench.c
@@ -738,9 +738,9 @@ serverloop(kvm_t *kvmh, u_long ktcbtab, struct addrinfo *aitop)
}
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 pollfd *pfd;
char tmp[128], *buf;
@@ -757,16 +757,6 @@ clientloop(kvm_t *kvmh, u_long ktcbtab, const char *host, const char *port, int
err(1, "clientloop psc calloc");
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) {
saddr_ntop(ai->ai_addr, ai->ai_addrlen, tmp,
sizeof(tmp));
@@ -802,7 +792,6 @@ clientloop(kvm_t *kvmh, u_long ktcbtab, const char *host, const char *port, int
}
break;
}
- freeaddrinfo(aitop);
if (sock == -1)
errx(1, "No host found");
@@ -818,6 +807,7 @@ clientloop(kvm_t *kvmh, u_long ktcbtab, const char *host, const char *port, int
mainstats.nconns++;
scnt++;
}
+ freeaddrinfo(aitop);
if (vflag && scnt > 1)
fprintf(stderr, "%u connections established\n", scnt);
@@ -964,16 +954,15 @@ main(int argc, char **argv)
if (!sflag)
host = argv[0];
- if (sflag) {
- bzero(&hints, sizeof(hints));
- hints.ai_socktype = SOCK_STREAM;
+ bzero(&hints, sizeof(hints));
+ hints.ai_socktype = SOCK_STREAM;
+ if (sflag)
hints.ai_flags = AI_PASSIVE;
- if ((herr = getaddrinfo(host, port, &hints, &aitop)) != 0) {
- if (herr == EAI_SYSTEM)
- err(1, "getaddrinfo");
- else
- errx(1, "s getaddrinfo: %s", gai_strerror(herr));
- }
+ if ((herr = getaddrinfo(host, port, &hints, &aitop)) != 0) {
+ if (herr == EAI_SYSTEM)
+ err(1, "getaddrinfo");
+ else
+ errx(1, "getaddrinfo: %s", gai_strerror(herr));
}
if (kflag) {
@@ -1004,7 +993,7 @@ main(int argc, char **argv)
if (sflag)
serverloop(kvmh, nl[0].n_value, aitop);
else
- clientloop(kvmh, nl[0].n_value, host, port, nconn);
+ clientloop(kvmh, nl[0].n_value, aitop, nconn);
return 0;
}