From: Thomas Pornin Date: Sat, 12 Nov 2016 15:49:27 +0000 (+0100) Subject: Moved address-to-string translation code to blocks that depend on the 'verbose' flag. X-Git-Tag: v0.4~57 X-Git-Url: https://bearssl.org/gitweb//home/git/?a=commitdiff_plain;h=f3ac21cb00646600475b02ecd2c592ee36e417da;p=BearSSL Moved address-to-string translation code to blocks that depend on the 'verbose' flag. --- diff --git a/tools/client.c b/tools/client.c index 7acfebf..8fc3cd8 100644 --- a/tools/client.c +++ b/tools/client.c @@ -57,27 +57,29 @@ host_connect(const char *host, const char *port, int verbose) } fd = -1; for (p = si; p != NULL; p = p->ai_next) { - struct sockaddr *sa; - void *addr; - char tmp[INET6_ADDRSTRLEN + 50]; + if (verbose) { + struct sockaddr *sa; + void *addr; + char tmp[INET6_ADDRSTRLEN + 50]; - sa = (struct sockaddr *)p->ai_addr; - if (sa->sa_family == AF_INET) { - addr = &((struct sockaddr_in *)sa)->sin_addr; - } else if (sa->sa_family == AF_INET6) { - addr = &((struct sockaddr_in6 *)sa)->sin6_addr; - } else { - addr = NULL; - } - if (addr != NULL) { - if (!inet_ntop(p->ai_family, addr, tmp, sizeof tmp)) { - strcpy(tmp, ""); + sa = (struct sockaddr *)p->ai_addr; + if (sa->sa_family == AF_INET) { + addr = &((struct sockaddr_in *)sa)->sin_addr; + } else if (sa->sa_family == AF_INET6) { + addr = &((struct sockaddr_in6 *)sa)->sin6_addr; + } else { + addr = NULL; + } + if (addr != NULL) { + if (!inet_ntop(p->ai_family, addr, + tmp, sizeof tmp)) + { + strcpy(tmp, ""); + } + } else { + sprintf(tmp, "", + (int)sa->sa_family); } - } else { - sprintf(tmp, "", - (int)sa->sa_family); - } - if (verbose) { fprintf(stderr, "connecting to: %s\n", tmp); } fd = socket(p->ai_family, p->ai_socktype, p->ai_protocol); diff --git a/tools/server.c b/tools/server.c index 983fbe6..9424bf5 100644 --- a/tools/server.c +++ b/tools/server.c @@ -62,7 +62,6 @@ host_bind(const char *host, const char *port, int verbose) struct sockaddr_in6 sa6; size_t sa_len; void *addr; - char tmp[INET6_ADDRSTRLEN + 50]; int opt; sa = (struct sockaddr *)p->ai_addr; @@ -86,15 +85,19 @@ host_bind(const char *host, const char *port, int verbose) addr = NULL; sa_len = p->ai_addrlen; } - if (addr != NULL) { - if (!inet_ntop(p->ai_family, addr, tmp, sizeof tmp)) { - strcpy(tmp, ""); - } - } else { - sprintf(tmp, "", - (int)sa->sa_family); - } if (verbose) { + char tmp[INET6_ADDRSTRLEN + 50]; + + if (addr != NULL) { + if (!inet_ntop(p->ai_family, addr, + tmp, sizeof tmp)) + { + strcpy(tmp, ""); + } + } else { + sprintf(tmp, "", + (int)sa->sa_family); + } fprintf(stderr, "binding to: %s\n", tmp); } fd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);