On Thu, 2006-07-20 at 10:17 +0200, Yoann Vandoorselaere wrote:
> On Wed, 2006-07-19 at 11:43 -0400, Derek R. Price wrote:
> > Yoann Vandoorselaere wrote:
> > > My suggestion is that unless we can get a full featured replacement of
> > > the getaddrinfo function within GnuLib (and thus replace any non
> > > conforming system implementation), we should not attempt to redefine any
> > > of the flags if the function is available on the system.
> >
> > Though it would be nice to see a full-featured replacement, for now
> > leaving the definitions of AI_* flags which aren't implemented by the
> > replacement does sound simplest. How's the attached patch look?
>
> It sound good, although I'd like to see some minimalist support for
> AI_PASSIVE, which is used by a lot of application. Attached is a trivial
> patch that work for me.
The check for flags other than AI_CANNONNAME also need to be removed for
this patch to work. Attached is an updated diff.
--
Yoann Vandoorselaere | Responsable R&D / CTO | PreludeIDS Technologies
Tel: +33 (0)8 70 70 21 58 Fax: +33(0)4 78 42 21 58
http://www.prelude-ids.com
Index: lib/getaddrinfo.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/getaddrinfo.c,v
retrieving revision 1.13
diff -u -p -r1.13 getaddrinfo.c
--- lib/getaddrinfo.c 7 Jul 2006 07:37:16 -0000 1.13
+++ lib/getaddrinfo.c 20 Jul 2006 08:29:41 -0000
@@ -140,10 +140,6 @@ getaddrinfo (const char *restrict nodena
return getaddrinfo_ptr (nodename, servname, hints, res);
#endif
- if (hints && (hints->ai_flags & ~AI_CANONNAME))
- /* FIXME: Support more flags. */
- return EAI_BADFLAGS;
-
if (hints && !validate_family (hints->ai_family))
return EAI_FAMILY;
@@ -152,10 +148,17 @@ getaddrinfo (const char *restrict nodena
/* FIXME: Support other socktype. */
return EAI_SOCKTYPE; /* FIXME: Better return code? */
- if (!nodename)
- /* FIXME: Support server bind mode. */
- return EAI_NONAME;
-
+ if (!nodename) {
+ 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)
{
struct servent *se = NULL;
Index: lib/getaddrinfo.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/getaddrinfo.h,v
retrieving revision 1.17
diff -u -p -r1.17 getaddrinfo.h
--- lib/getaddrinfo.h 19 Jul 2006 21:59:10 -0000 1.17
+++ lib/getaddrinfo.h 20 Jul 2006 08:29:41 -0000
@@ -48,12 +48,16 @@ struct addrinfo
#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 @@ struct addrinfo
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. */