aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-04-25 00:46:36 +0000
committerUlrich Drepper <drepper@redhat.com>2003-04-25 00:46:36 +0000
commit29bfc9453e2945b476cec5545f8409fd2a2ba886 (patch)
tree8e6e1845730fa1aa92b264d492082b86d4ac56dd
parent925c3c5c71596c02f7e58a0ffcdcaae44eb065c1 (diff)
downloadglibc-29bfc9453e2945b476cec5545f8409fd2a2ba886.tar
glibc-29bfc9453e2945b476cec5545f8409fd2a2ba886.tar.gz
glibc-29bfc9453e2945b476cec5545f8409fd2a2ba886.tar.bz2
glibc-29bfc9453e2945b476cec5545f8409fd2a2ba886.zip
Update.
* nss/getent.c: Implement alternative host database lookup via getaddrinfo. unbinding it.
-rw-r--r--ChangeLog5
-rw-r--r--nss/getent.c68
2 files changed, 72 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 16f95f9255..584e9b5cf9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2003-04-24 Ulrich Drepper <drepper@redhat.com>
+ * nss/getent.c: Implement alternative host database lookup via
+ getaddrinfo.
+
* include/ifaddrs.h: New file.
* include/netdb.h: Move definitions of AI_V4MAPPED, AI_ALL, and
AI_ADDRCONFIG...
@@ -43,7 +46,7 @@
(__yp_unbind): Add call to free. Adjust all callers.
* nis/ypclnt.c (yp_all): Free the dom_binding object after
- unwinding it.
+ unbinding it.
* grp/initgroups.c (getgrouplist): Don't copy too much into the
user buffer if more groups are found than fit into it.
diff --git a/nss/getent.c b/nss/getent.c
index a9cba96f0c..aed346c540 100644
--- a/nss/getent.c
+++ b/nss/getent.c
@@ -296,6 +296,73 @@ hosts_keys (int number, char *key[])
return result;
}
+/* This is for hosts, but using getaddrinfo */
+static int
+ahosts_keys (int number, char *key[])
+{
+ int result = 0;
+ int i;
+ struct hostent *host;
+
+ if (number == 0)
+ {
+ sethostent (0);
+ while ((host = gethostent ()) != NULL)
+ print_hosts (host);
+ endhostent ();
+ return result;
+ }
+
+ struct addrinfo hint;
+ memset (&hint, '\0', sizeof (hint));
+ hint.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG | AI_CANONNAME;
+ hint.ai_family = AF_UNSPEC;
+
+ for (i = 0; i < number; ++i)
+ {
+ struct addrinfo *res;
+
+ if (getaddrinfo (key[i], NULL, &hint, &res) != 0)
+ result = 2;
+ else
+ {
+ struct addrinfo *runp = res;
+
+ while (runp != NULL)
+ {
+ char sockbuf[20];
+ const char *sockstr;
+ if (runp->ai_socktype == SOCK_STREAM)
+ sockstr = "STREAM";
+ else if (runp->ai_socktype == SOCK_DGRAM)
+ sockstr = "DGRAM";
+ else if (runp->ai_socktype == SOCK_RAW)
+ sockstr = "RAW";
+ else
+ {
+ snprintf (sockbuf, sizeof (sockbuf), "%d",
+ runp->ai_socktype);
+ sockstr = sockbuf;
+ }
+
+ char buf[INET6_ADDRSTRLEN];
+ printf ("%-15s %-6s %s\n",
+ inet_ntop (runp->ai_family,
+ &((struct sockaddr_in *) runp->ai_addr)->sin_addr,
+ buf, sizeof (buf)),
+ sockstr,
+ runp->ai_canonname);
+
+ runp = runp->ai_next;
+ }
+
+ freeaddrinfo (res);
+ }
+ }
+
+ return result;
+}
+
/* This is for netgroup */
static int
netgroup_keys (int number, char *key[])
@@ -688,6 +755,7 @@ struct
} databases[] =
{
#define D(name) { #name, name ## _keys },
+D(ahosts)
D(aliases)
D(ethers)
D(group)