From patchwork Thu Jan 31 18:00:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1034408 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-99648-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="EMRxE2ID"; dkim-atps=neutral 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 43r7Lx1FXpz9s4V for ; Fri, 1 Feb 2019 05:00:40 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=GgbTa6F4nhMhjRjtCCfKGhei50sS4 VDX634GLrg9bBb25DzScbChgM33NYL+loKIgedCDz201swiOL/alCNsloQ05bIWv ycfyBCX4VwHojlDibvnWzBwTlLIghCk49W2GZQO31JRB4Ol8/xcmNCdOu+svtKeo FX2zBVBSU59c0s= 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:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=m0F0u7IibevKqiGJZr//kOKzDjc=; b=EMR xE2IDlouGugbmDaeyKuEr4f8FHBfhq8MToeVebfAumOPlsd2tWI+tkkC/lzO8lP0 Ur/KH6sg7nUPNU+7ugJfU5CS3WL43NwvF6p+hLUh7KWlWdSLfXPC2WKilf50hNHn tepolCdMvrgseQAoeR9suYVycdJJHs6R7XnK7m10= Received: (qmail 1763 invoked by alias); 31 Jan 2019 18:00:34 -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 1582 invoked by uid 89); 31 Jan 2019 18:00:24 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] nss: getent: Print IPv6 scope ID for ahosts/ahostsv6 if available Date: Thu, 31 Jan 2019 19:00:11 +0100 Message-ID: <875zu4d7x0.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 2019-01-31 Florian Weimer * nss/getent.c (ahosts_keys_int): Include IPv6 scope ID in output. diff --git a/nss/getent.c b/nss/getent.c index f25de8f1fc..1159ba2636 100644 --- a/nss/getent.c +++ b/nss/getent.c @@ -393,14 +393,24 @@ ahosts_keys_int (int af, int xflags, int number, char *key[]) sockstr = sockbuf; } + char scope_buf[3 * sizeof (unsigned long long int) + 2]; + struct sockaddr_in6 *addr6 + = (struct sockaddr_in6 *) runp->ai_addr; + if (runp->ai_family != AF_INET6 || addr6->sin6_scope_id == 0) + /* No scope ID present. */ + scope_buf[0] = '\0'; + else + snprintf (scope_buf, sizeof (scope_buf), "%%%llu", + (unsigned long long int) addr6->sin6_scope_id); + char buf[INET6_ADDRSTRLEN]; - printf ("%-15s %-6s %s\n", + printf ("%-15s%s %-6s %s\n", inet_ntop (runp->ai_family, runp->ai_family == AF_INET ? (void *) &((struct sockaddr_in *) runp->ai_addr)->sin_addr - : (void *) &((struct sockaddr_in6 *) runp->ai_addr)->sin6_addr, + : &addr6->sin6_addr, buf, sizeof (buf)), - sockstr, + scope_buf, sockstr, runp->ai_canonname ?: ""); runp = runp->ai_next;