From patchwork Wed May 4 12:52:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 618439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3r0Hyb2pK3z9t50 for ; Wed, 4 May 2016 22:53:11 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=RO1k2BQR; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= OW3xyxSTXn2PgW36NpncqqbNz6KqgOcwPqQVUGUphh5d8+BiHHVEvAGbMctWP3A0 ucK2P1ys437P+cxilcka1EAoV7zEu6pA6gQ/bIZ8D9R1gTeiQHgqP5MxCSApqZYG nK3QyvM2tvv17jfYm54Q+SscR7F+M6EcXxDbiDaDgrU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=gyg9WA w5QQk5mtD4ydsfvd3ops4=; b=RO1k2BQR5GtKdaUnSC/oPxzBR/PWvCNyGKUk5I yT0lvCzBEEUau2b87EYigVbov9yc4ER2rQgLJQwqAStTv7Y1XVGhhJHvfC/l58tV 4M6h7WOE+kB+RTH5o8NhdoBMd44ggNI/XylJ0E1SNzKZTeBDlOaC4jHzHhTcuB5X lqwg4= Received: (qmail 34877 invoked by alias); 4 May 2016 12:52:15 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 34830 invoked by uid 89); 4 May 2016 12:52:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=1989, Hx-languages-length:4036 X-HELO: mx1.redhat.com Date: Wed, 04 May 2016 14:52:06 +0200 To: libc-alpha@sourceware.org Subject: [PATCH COMMITTED] getnameinfo: Reduce line length and add missing comments User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20160504125206.0D4944100A9ED@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) 2016-05-04 Florian Weimer * inet/getnameinfo.c (gni_host_inet_name): Use temporaries to avoid long lines. (gni_host_inet_numeric): Likewise. Reduce scope of local variables. (gni_host_inet, gni_host_local): Add comment. (gni_host): Add comment. Use temporary to avoid long lines. diff --git a/inet/getnameinfo.c b/inet/getnameinfo.c index ce05dda..c649c49 100644 --- a/inet/getnameinfo.c +++ b/inet/getnameinfo.c @@ -198,10 +198,9 @@ gni_host_inet_name (struct scratch_buffer *tmpbuf, struct hostent *h = NULL; if (sa->sa_family == AF_INET6) { - while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in6 *) sa)->sin6_addr), - sizeof(struct in6_addr), - AF_INET6, &th, - tmpbuf->data, tmpbuf->length, + const struct sockaddr_in6 *sin6p = (const struct sockaddr_in6 *) sa; + while (__gethostbyaddr_r (&sin6p->sin6_addr, sizeof(struct in6_addr), + AF_INET6, &th, tmpbuf->data, tmpbuf->length, &h, &herrno)) if (herrno == NETDB_INTERNAL && errno == ERANGE) { @@ -216,10 +215,9 @@ gni_host_inet_name (struct scratch_buffer *tmpbuf, } else { - while (__gethostbyaddr_r ((const void *) &(((const struct sockaddr_in *)sa)->sin_addr), - sizeof(struct in_addr), - AF_INET, &th, - tmpbuf->data, tmpbuf->length, + const struct sockaddr_in *sinp = (const struct sockaddr_in *) sa; + while (__gethostbyaddr_r (&sinp->sin_addr, sizeof(struct in_addr), + AF_INET, &th, tmpbuf->data, tmpbuf->length, &h, &herrno)) if (herrno == NETDB_INTERNAL && errno == ERANGE) { @@ -308,14 +306,10 @@ gni_host_inet_numeric (struct scratch_buffer *tmpbuf, const char *c; if (sa->sa_family == AF_INET6) { - const struct sockaddr_in6 *sin6p; - uint32_t scopeid; - - sin6p = (const struct sockaddr_in6 *) sa; - + const struct sockaddr_in6 *sin6p = (const struct sockaddr_in6 *) sa; c = inet_ntop (AF_INET6, (const void *) &sin6p->sin6_addr, host, hostlen); - scopeid = sin6p->sin6_scope_id; + uint32_t scopeid = sin6p->sin6_scope_id; if (scopeid != 0) { /* Buffer is >= IFNAMSIZ+1. */ @@ -356,14 +350,16 @@ gni_host_inet_numeric (struct scratch_buffer *tmpbuf, } } else - c = inet_ntop (AF_INET, - (const void *) &(((const struct sockaddr_in *) sa)->sin_addr), - host, hostlen); + { + const struct sockaddr_in *sinp = (const struct sockaddr_in *) sa; + c = inet_ntop (AF_INET, &sinp->sin_addr, host, hostlen); + } if (c == NULL) return EAI_OVERFLOW; return 0; } +/* Convert AF_INET or AF_INET6 socket address, host part. */ static int gni_host_inet (struct scratch_buffer *tmpbuf, const struct sockaddr *sa, socklen_t addrlen, @@ -384,6 +380,7 @@ gni_host_inet (struct scratch_buffer *tmpbuf, (tmpbuf, sa, addrlen, host, hostlen, flags); } +/* Convert AF_LOCAL socket address, host part. */ static int gni_host_local (struct scratch_buffer *tmpbuf, const struct sockaddr *sa, socklen_t addrlen, @@ -408,6 +405,7 @@ gni_host_local (struct scratch_buffer *tmpbuf, return 0; } +/* Convert the host part of an AF_LOCAK socket address. */ static int gni_host (struct scratch_buffer *tmpbuf, const struct sockaddr *sa, socklen_t addrlen, @@ -439,11 +437,12 @@ gni_serv_inet (struct scratch_buffer *tmpbuf, && sizeof (((struct sockaddr_in) {}).sin_port) == sizeof (in_port_t) && sizeof (((struct sockaddr_in6) {}).sin6_port) == sizeof (in_port_t), "AF_INET and AF_INET6 port consistency"); + const struct sockaddr_in *sinp = (const struct sockaddr_in *) sa; if (!(flags & NI_NUMERICSERV)) { struct servent *s, ts; int e; - while ((e = __getservbyport_r (((const struct sockaddr_in *) sa)->sin_port, + while ((e = __getservbyport_r (sinp->sin_port, ((flags & NI_DGRAM) ? "udp" : "tcp"), &ts, tmpbuf->data, tmpbuf->length, &s))) @@ -463,9 +462,7 @@ gni_serv_inet (struct scratch_buffer *tmpbuf, } /* Fall through to numeric conversion. */ } - if (__snprintf (serv, servlen, "%d", - ntohs (((const struct sockaddr_in *) sa)->sin_port)) - + 1 > servlen) + if (__snprintf (serv, servlen, "%d", ntohs (sinp->sin_port)) + 1 > servlen) return EAI_OVERFLOW; return 0; }