This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [ping2][PATCH][BZ #16077] Get canonical name in getaddrinfo from hosts file for AF_INET


----- Original Message -----
> From: "Siddhesh Poyarekar" <siddhesh@redhat.com>
> To: libc-alpha@sourceware.org
> Sent: Monday, November 25, 2013 10:55:45 AM
> Subject: [ping2][PATCH][BZ #16077] Get canonical name in getaddrinfo from hosts file for AF_INET

Hi!

> > > @@ -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;

Another one to the gethostbyname*_r mess.

Maybe it's time to merge all those into _nss_files_gethostbyname5_r() providing all the functionality of the previous functions and just provide a pack of backwards compatibility functions.

> > > 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,

Looks good. But I think it would to get a little bit nearer to what I wrote above and...

 * Rename gethostbyname2 to gethostbyname3 and accept a NULL canonp.
 * Create a gethostbyname2 that would just call gethostbyname3(..., NULL)

Does that sound reasonable?

By the way I'm using my own testing tool that is part of a name resolution library I recently announced in this very list, but unfortunately it doesn't yet support _nss_*_gethostbyname4 and it doesn't yet show the canonical name. It allows you to test specific _nss_*_getaddrinfo* functions.

The library:

https://sourceware.org/git/?p=netresolve.git;a=blob;f=README;hb=HEAD

Command-line tool usage for this purpose:

NETRESOLVE_BACKENDS=nss:files NETRESOLVE_NSS_API=getaddrinfo ./netresolve localhost
NETRESOLVE_BACKENDS=nss:files NETRESOLVE_NSS_API=getaddrinfo2 ./netresolve localhost
NETRESOLVE_BACKENDS=nss:files NETRESOLVE_NSS_API=getaddrinfo3 ./netresolve localhost

Cheers,

Pavel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]