public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug network/16077] New: Get canonical name from /etc/hosts for AF_INET
@ 2013-10-23  9:30 siddhesh at redhat dot com
  2013-10-23 14:23 ` [Bug network/16077] " siddhesh at redhat dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: siddhesh at redhat dot com @ 2013-10-23  9:30 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16077

            Bug ID: 16077
           Summary: Get canonical name from /etc/hosts for AF_INET
           Product: glibc
           Version: 2.18
            Status: NEW
          Severity: normal
          Priority: P2
         Component: network
          Assignee: siddhesh at redhat dot com
          Reporter: siddhesh at redhat dot com

Currently, getaddrinfo does not return the actual ai_canonname when an AF_INET
lookup is satisfied from /etc/hosts.  Instead, the requested name is simply
copied back.

How Reproducible:

Always

Steps to reproduce:

1. Add the following entry to /etc/hosts

10.10.10.1 foo.test.com foo

2. Build and run the following program:


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

int main(int argc, char *argv[])
{
  int rc, i;
  struct addrinfo hints, *res;

  for(i=1; i < argc; i++)
    {
      memset(&hints,0,sizeof(hints));
      memset(&res,0,sizeof(res));

      hints.ai_family = AF_INET;
      hints.ai_socktype = SOCK_STREAM;
      hints.ai_protocol = IPPROTO_TCP;
      hints.ai_flags = AI_CANONNAME;

      rc = getaddrinfo("foo", NULL, &hints, &res);
      if (rc==0 && res && res->ai_canonname)
        printf("res->ai_canonname=%s\n",res->ai_canonname);
      else
        {
          printf("res=%p\n", res);
          if (res)
            printf("res->ai_canonname=%p\n",res->ai_canonname);
        }
    }
}

Actual Result:

res->ai_canonname=foo

Expected Result:

res->ai_canonname=foo.test.com

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug network/16077] Get canonical name from /etc/hosts for AF_INET
  2013-10-23  9:30 [Bug network/16077] New: Get canonical name from /etc/hosts for AF_INET siddhesh at redhat dot com
@ 2013-10-23 14:23 ` siddhesh at redhat dot com
  2013-11-28 11:53 ` siddhesh at redhat dot com
  2014-06-13 12:31 ` fweimer at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: siddhesh at redhat dot com @ 2013-10-23 14:23 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16077

--- Comment #2 from Siddhesh Poyarekar <siddhesh at redhat dot com> ---
(In reply to Rich Felker from comment #1)
> How do you define "canonical" for entries from the hosts file? The first
> hostname on the matching line? For DNS, "canonical" is defined clearly by

Yes, because the hosts man page defines a hosts entry as:

  IP_address canonical_hostname [aliases...]

I understand that it's not a standard definition, but I don't think there's any
such standard definition for a hosts file entry anyway.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug network/16077] Get canonical name from /etc/hosts for AF_INET
  2013-10-23  9:30 [Bug network/16077] New: Get canonical name from /etc/hosts for AF_INET siddhesh at redhat dot com
  2013-10-23 14:23 ` [Bug network/16077] " siddhesh at redhat dot com
@ 2013-11-28 11:53 ` siddhesh at redhat dot com
  2014-06-13 12:31 ` fweimer at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: siddhesh at redhat dot com @ 2013-11-28 11:53 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16077

Siddhesh Poyarekar <siddhesh at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Siddhesh Poyarekar <siddhesh at redhat dot com> ---
Fixed in master:

commit 5a4c6d53f50b264d60cf6453576ca2810c7890b7
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date:   Thu Nov 28 17:18:12 2013 +0530

    Get canonical name in getaddrinfo from hosts file for AF_INET (fixes 16077)

    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.

 ChangeLog                   |  12 ++++
 NEWS                        |   4 +-
 nss/Versions                |   1 +
 nss/nss_files/files-hosts.c | 507
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------
 4 files changed, 272 insertions(+), 252 deletions(-)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug network/16077] Get canonical name from /etc/hosts for AF_INET
  2013-10-23  9:30 [Bug network/16077] New: Get canonical name from /etc/hosts for AF_INET siddhesh at redhat dot com
  2013-10-23 14:23 ` [Bug network/16077] " siddhesh at redhat dot com
  2013-11-28 11:53 ` siddhesh at redhat dot com
@ 2014-06-13 12:31 ` fweimer at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: fweimer at redhat dot com @ 2014-06-13 12:31 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=16077

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Flags|                            |security-

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-06-13 12:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-23  9:30 [Bug network/16077] New: Get canonical name from /etc/hosts for AF_INET siddhesh at redhat dot com
2013-10-23 14:23 ` [Bug network/16077] " siddhesh at redhat dot com
2013-11-28 11:53 ` siddhesh at redhat dot com
2014-06-13 12:31 ` fweimer at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).