changeset 7002:df869687851e

2006-07-22 Yoann Vandoorselaere <yoann.v@prelude-ids.com> and Simon Josefsson <jas@extundo.com> * getaddrinfo.h (AI_PASSIVE): Make sure it is defined. * getaddrinfo.c (getaddrinfo): Support AI_PASSIVE.
author Simon Josefsson <simon@josefsson.org>
date Sat, 22 Jul 2006 10:13:57 +0000
parents 10ff66a705c1
children 2f98ed9e3c9e
files lib/ChangeLog lib/getaddrinfo.c lib/getaddrinfo.h
diffstat 3 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,10 @@
+2006-07-22  Yoann Vandoorselaere <yoann.v@prelude-ids.com>
+	and Simon Josefsson <jas@extundo.com>
+
+	* getaddrinfo.h (AI_PASSIVE): Make sure it is defined.
+
+	* getaddrinfo.c (getaddrinfo): Support AI_PASSIVE.
+
 2006-07-21  Eric Blake  <ebb9@byu.net>
 
 	* stdlib-safer.h: New file from coreutils, required by
--- a/lib/getaddrinfo.c
+++ b/lib/getaddrinfo.c
@@ -140,7 +140,7 @@
     return getaddrinfo_ptr (nodename, servname, hints, res);
 #endif
 
-  if (hints && (hints->ai_flags & ~AI_CANONNAME))
+  if (hints && (hints->ai_flags & ~(AI_CANONNAME|AI_PASSIVE)))
     /* FIXME: Support more flags. */
     return EAI_BADFLAGS;
 
@@ -153,8 +153,16 @@
     return EAI_SOCKTYPE; /* FIXME: Better return code? */
 
   if (!nodename)
-    /* FIXME: Support server bind mode. */
-    return EAI_NONAME;
+    {
+      if (!(hints->ai_flags & AI_PASSIVE))
+	return EAI_NONAME;
+
+#ifdef HAVE_IPV6
+      nodename = (hint->ai_family == AF_INET6) ? "::" : "0.0.0.0";
+#else
+      nodename = "0.0.0.0";
+#endif
+    }
 
   if (servname)
     {
--- a/lib/getaddrinfo.h
+++ b/lib/getaddrinfo.h
@@ -48,12 +48,16 @@
 #endif
 
 /* Possible values for `ai_flags' field in `addrinfo' structure.  */
+#ifndef AI_PASSIVE
+# define AI_PASSIVE	0x0001	/* Socket address is intended for `bind'.  */
+#endif
 #ifndef AI_CANONNAME
 # define AI_CANONNAME	0x0002	/* Request for canonical name.  */
 #endif
 #ifndef AI_NUMERICSERV
 # define AI_NUMERICSERV	0x0400	/* Don't use name resolution.  */
 #endif
+
 #if 0
 /* The commented out definitions below are not yet implemented in the
    GNULIB getaddrinfo() replacement, so are not yet needed and may, in fact,
@@ -61,7 +65,6 @@
    define them.
 
    If they are restored, be sure to protect the definitions with #ifndef.  */
-#define AI_PASSIVE	0x0001	/* Socket address is intended for `bind'.  */
 #define AI_NUMERICHOST	0x0004	/* Don't use name resolution.  */
 #define AI_V4MAPPED	0x0008	/* IPv4 mapped addresses are acceptable.  */
 #define AI_ALL		0x0010	/* Return IPv4 mapped and IPv6 addresses.  */