bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tests/test-getaddrinfo.c: compile failures on freebsd 6


From: Jim Meyering
Subject: Re: tests/test-getaddrinfo.c: compile failures on freebsd 6
Date: Sat, 03 May 2008 11:58:28 +0200

Simon Josefsson <address@hidden> wrote:
> Jim Meyering <address@hidden> writes:
>> Here's a fix for the first:
>>
>>     test-getaddrinfo.c: In function 'simple':
>>     test-getaddrinfo.c:67: error: 'EAI_NODATA' undeclared (first use in this 
>> function)
>>     test-getaddrinfo.c:67: error: (Each undeclared identifier is
>>     reported only once

Hi Simon,

> getaddrinfo.h should declare that symbol if missing.  Can you see why
> that doesn't happen?  Does the system have EAI_BADFLAGS but not
> EAI_NODATA?
>
>> +#ifndef EAI_NODATA
>> +# define EAI_NODATA 0
>> +#endif
>
> That is the wrong value for this error, since 0 is reserved for
> successful returns.

However, now that I've learned more about it, I see there's a
better way.  EAI_NONAME seems to be preferred: EAI_NODATA isn't
even mentioned in the POSIX specs I looked at.

netdb.h does define EAI_BADFLAGS, but not EAI_NODATA:

  #define EAI_BADFLAGS     3      /* invalid value for ai_flags */
  #define EAI_FAIL         4      /* non-recoverable failure in name resolution 
*/
  #define EAI_FAMILY       5      /* ai_family not supported */
  #define EAI_MEMORY       6      /* memory allocation failure */
  #if 0
  /* obsoleted */
  #define EAI_NODATA       7      /* no address associated with hostname */
  #endif
  #define EAI_NONAME       8      /* hostname nor servname provided, or not 
known */
  ...

EAI_NODATA is no longer even mentioned in RFC3493.
Since at least FreeBSD has removed it in favour of EAI_NONAME,
how about defining it to EAI_NONAME if it is not defined?

The first patch, below, is better:
[The following one avoids the other compilation error I reported.
 With these, it builds and passes tests on FreeBSD 6. ]

        handle undefined EAI_NODATA better
        * lib/getaddrinfo.h [!defined EAI_NODATA && defined EAI_NONAME]
        (EAI_NODATA): Define.
        * tests/test-getaddrinfo.c (EAI_NODATA): Don't define here.
        This also reverts c9a6a9bb007294bb8878d685f3e9336b3a5be1ed.

        test-getaddrinfo.c: include <netinet/in.h>
        * tests/test-getaddrinfo.c: This is required for the new use
        of "struct sockaddr_in", at least on FreeBSD 6.

diff --git a/lib/getaddrinfo.h b/lib/getaddrinfo.h
index b4ef242..0e9aec1 100644
--- a/lib/getaddrinfo.h
+++ b/lib/getaddrinfo.h
@@ -84,6 +84,14 @@ struct addrinfo
 # define EAI_SERVICE     -8    /* SERVICE not supported for `ai_socktype'.  */
 # define EAI_MEMORY      -10   /* Memory allocation failure.  */
 #endif
+
+/* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
+   FreeBSD, which does define EAI_BADFLAGS) have removed the definition
+   in favor of EAI_NONAME.  */
+#if !defined EAI_NODATA && defined EAI_NONAME
+# define EAI_NODATA EAI_NONAME
+#endif
+
 #ifndef EAI_OVERFLOW
 /* Not defined on mingw32. */
 # define EAI_OVERFLOW    -12   /* Argument buffer overflow.  */
diff --git a/tests/test-getaddrinfo.c b/tests/test-getaddrinfo.c
index 801bae8..8d487cb 100644
--- a/tests/test-getaddrinfo.c
+++ b/tests/test-getaddrinfo.c
@@ -32,10 +32,6 @@
 # define EAI_SERVICE 0
 #endif

-#ifndef EAI_NODATA
-# define EAI_NODATA 0
-#endif
-
 int simple (char *host, char *service)
 {
   char buf[BUFSIZ];


diff --git a/tests/test-getaddrinfo.c b/tests/test-getaddrinfo.c
index 8d487cb..530f8dc 100644
--- a/tests/test-getaddrinfo.c
+++ b/tests/test-getaddrinfo.c
@@ -20,6 +20,7 @@
 #include <config.h>
 #include "getaddrinfo.h"
 #include <arpa/inet.h>
+#include <netinet/in.h>
 #include <stdio.h>
 #include <string.h>

--
1.5.5.1.117.ga349




reply via email to

[Prev in Thread] Current Thread [Next in Thread]