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]

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


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.

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,


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