This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][BZ #16077] Get canonical name in getaddrinfo from hosts file for AF_INET
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Wed, 23 Oct 2013 15:12:53 +0200
- Subject: Re: [PATCH][BZ #16077] Get canonical name in getaddrinfo from hosts file for AF_INET
- Authentication-results: sourceware.org; auth=none
- References: <20131023100431 dot GG7401 at spoyarek dot pnq dot redhat dot com>
On Wed, Oct 23, 2013 at 03:34:31PM +0530, Siddhesh Poyarekar wrote:
> Hi,
>
> AF_INET lookup in hosts file uses _nss_files_gethostbyname2_r, which
> is not capable of returning a canonical name if it has found one.
> This change adds _nss_files_gethostbyname3_r, which wraps around
> _nss_files_gethostbyname2_r and then returns result.h_name as the
> canonical name.
>
How this will be used? Will there be a followup patches? A single function
that is not called internally and has no documentation is not very useful.
> The bug report has a test case that helps verify this patch. Tested
> on x86_64 and also verified that it doesn't break any current tests.
> OK to commit?
>
> Siddhesh
>
> [BZ #16077]
> * nss/Versions (libnss_files): Add
> _nss_files_gethostbyname3_r.
> * nss/nss_files/files-hosts.c (_nss_files_gethostbyname3_r):
> New function.
>
> diff --git a/nss/Versions b/nss/Versions
> index d13d570..f8ababc 100644
> --- a/nss/Versions
> +++ b/nss/Versions
> @@ -40,6 +40,7 @@ libnss_files {
> _nss_files_endhostent;
> _nss_files_gethostbyaddr_r;
> _nss_files_gethostbyname2_r;
> + _nss_files_gethostbyname3_r;
> _nss_files_gethostbyname4_r;
> _nss_files_gethostbyname_r;
> _nss_files_gethostent_r;
> diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c
> index 6db2535..23d8fa2 100644
> --- a/nss/nss_files/files-hosts.c
> +++ b/nss/nss_files/files-hosts.c
> @@ -365,6 +365,23 @@ DB_LOOKUP (hostbyaddr, ,,,
> }, const void *addr, socklen_t len, int af)
> #undef EXTRA_ARGS_VALUE
>
> +enum nss_status
> +_nss_files_gethostbyname3_r (const char *name, int af, struct hostent *result,
> + char *buffer, size_t buflen, int *errnop,
> + int *herrnop, int32_t *ttlp, char **canonp)
> +{
> + enum nss_status status = _nss_files_gethostbyname2_r (name, af, result,
> + buffer, buflen,
> + errnop, herrnop);
> +
> + /* For a successful lookup, the first name in /etc/hosts is the canonical
> + host name. */
> + if (result && status == NSS_STATUS_SUCCESS)
> + *canonp = result->h_name;
> +
> + return status;
> +}
> +
>
> enum nss_status
> _nss_files_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,