This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] nss: getent: Print IPv6 scope ID for ahosts/ahostsv6 if available
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: libc-alpha at sourceware dot org
- Date: Fri, 1 Feb 2019 09:54:53 -0200
- Subject: Re: [PATCH] nss: getent: Print IPv6 scope ID for ahosts/ahostsv6 if available
- References: <875zu4d7x0.fsf@oldenburg2.str.redhat.com>
On 31/01/2019 16:00, Florian Weimer wrote:
> 2019-01-31 Florian Weimer <fweimer@redhat.com>
>
> * 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);
sin6_scope_id is defines as uint32_t regardless, why not use PRIu32?
> +
> 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;
>