bug-gnulib
[Top][All Lists]
Advanced

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

Re: getaddrinfo, netdb, canon-host


From: Simon Josefsson
Subject: Re: getaddrinfo, netdb, canon-host
Date: Mon, 20 Oct 2008 09:56:50 +0200
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/22.2 (gnu/linux)

I have pushed the following change.  The canon-host module needs to be
fixed, I'll send a patch separately.

/Simon

>From dbf8ca54bfdeaef894c8d0912df6e05b4c1a7302 Mon Sep 17 00:00:00 2001
From: Simon Josefsson <address@hidden>
Date: Mon, 20 Oct 2008 09:53:42 +0200
Subject: [PATCH] Move getaddrinfo.h declarations to netdb.h.
 * lib/getaddrinfo.h: Remove file.
 * modules/getaddrinfo: Reflect move from getaddrinfo.h to netdb.h.
 * m4/getaddrinfo.m4: Call gl_HEADER_NETDB.  Don't check for netdb.h.
 * lib/netdb.in.h: Add declarations from getaddrinfo.h.
 * m4/netdb_h.m4: Initialize GNULIB_GETADDRINFO to 0.
 * modules/netdb: Substitute GNULIB_GETADDRINFO.
 * lib/getaddrinfo.c: Include netdb.h instead of getaddrinfo.h.
 * tests/test-getaddrinfo.c: Likewise.
 * lib/gai_strerror.c: Likewise.  Also drop HAVE_NETDB_H check.
 * NEWS: Mention change.

---
 ChangeLog                |   13 ++++
 NEWS                     |    3 +
 lib/gai_strerror.c       |    7 +--
 lib/getaddrinfo.c        |    2 +-
 lib/getaddrinfo.h        |  163 ----------------------------------------------
 lib/netdb.in.h           |  132 +++++++++++++++++++++++++++++++++++++
 m4/getaddrinfo.m4        |   11 ++--
 m4/netdb_h.m4            |    2 +-
 modules/getaddrinfo      |    5 +-
 modules/netdb            |    1 +
 tests/test-getaddrinfo.c |    2 +-
 11 files changed, 162 insertions(+), 179 deletions(-)
 delete mode 100644 lib/getaddrinfo.h

diff --git a/ChangeLog b/ChangeLog
index fb40762..808510e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2008-10-20  Simon Josefsson  <address@hidden>
+
+       * lib/getaddrinfo.h: Remove file.
+       * modules/getaddrinfo: Reflect move from getaddrinfo.h to netdb.h.
+       * m4/getaddrinfo.m4: Call gl_HEADER_NETDB.  Don't check for netdb.h.
+       * lib/netdb.in.h: Add declarations from getaddrinfo.h.
+       * m4/netdb_h.m4: Initialize GNULIB_GETADDRINFO to 0.
+       * modules/netdb: Substitute GNULIB_GETADDRINFO.
+       * lib/getaddrinfo.c: Include netdb.h instead of getaddrinfo.h.
+       * tests/test-getaddrinfo.c: Likewise.
+       * lib/gai_strerror.c: Likewise.  Also drop HAVE_NETDB_H check.
+       * NEWS: Mention change.
+
 2008-10-19  Bruno Haible  <address@hidden>
 
        * m4/posix_spawn.m4 (gl_POSIX_SPAWN_WORKS): Remove unneeded code.
diff --git a/NEWS b/NEWS
index f4b7d62..8e8931e 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2008-10-20  getaddrinfo     The include file is changed from "getaddrinfo.h"
+                            to <netdb.h>.
+
 2008-10-19  isnanf          The include file is changed from "isnanf.h" to
                             <math.h>.
             isnand          The include file is changed from "isnand.h" to
diff --git a/lib/gai_strerror.c b/lib/gai_strerror.c
index aa733d6..60042e8 100644
--- a/lib/gai_strerror.c
+++ b/lib/gai_strerror.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006 Free Software Foundation, 
Inc.
+/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2008 Free Software 
Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Philip Blundell <address@hidden>, 1997.
 
@@ -18,13 +18,10 @@
 
 #ifndef _LIBC
 # include <config.h>
-# include "getaddrinfo.h"
 #endif
 
 #include <stdio.h>
-#ifdef HAVE_NETDB_H
-# include <netdb.h>
-#endif
+#include <netdb.h>
 
 #ifdef _LIBC
 # include <libintl.h>
diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c
index e4ed821..6a36bf0 100644
--- a/lib/getaddrinfo.c
+++ b/lib/getaddrinfo.c
@@ -19,7 +19,7 @@
 
 #include <config.h>
 
-#include "getaddrinfo.h"
+#include <netdb.h>
 
 #if HAVE_NETINET_IN_H
 # include <netinet/in.h>
diff --git a/lib/getaddrinfo.h b/lib/getaddrinfo.h
deleted file mode 100644
index 0e9aec1..0000000
--- a/lib/getaddrinfo.h
+++ /dev/null
@@ -1,163 +0,0 @@
-/* Get address information.
-   Copyright (C) 1996-2002, 2003, 2004, 2005, 2006, 2008
-                 Free Software Foundation, Inc.
-   Contributed by Simon Josefsson <address@hidden>.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef GETADDRINFO_H
-#define GETADDRINFO_H
-
-/* sys/socket.h in i386-unknown-freebsd4.10 and
-   powerpc-apple-darwin5.5 require sys/types.h, so include it first.
-   Then we'll also get 'socklen_t' and 'struct sockaddr' which are
-   used below. */
-#include <sys/types.h>
-/* Get all getaddrinfo related declarations, if available.  */
-#include <sys/socket.h>
-#ifdef HAVE_NETDB_H
-# include <netdb.h>
-#endif
-
-#ifndef HAVE_STRUCT_ADDRINFO
-
-/* Structure to contain information about address of a service provider.  */
-struct addrinfo
-{
-  int ai_flags;                        /* Input flags.  */
-  int ai_family;               /* Protocol family for socket.  */
-  int ai_socktype;             /* Socket type.  */
-  int ai_protocol;             /* Protocol for socket.  */
-  socklen_t ai_addrlen;                /* Length of socket address.  */
-  struct sockaddr *ai_addr;    /* Socket address for socket.  */
-  char *ai_canonname;          /* Canonical name for service location.  */
-  struct addrinfo *ai_next;    /* Pointer to next in list.  */
-};
-#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,
-   cause conflicts on systems with a getaddrinfo() function which does not
-   define them.
-
-   If they are restored, be sure to protect the definitions with #ifndef.  */
-#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.  */
-#define AI_ADDRCONFIG  0x0020  /* Use configuration of this host to choose
-                                  returned address type..  */
-#endif /* 0 */
-
-/* Error values for `getaddrinfo' function.  */
-#ifndef EAI_BADFLAGS
-# define EAI_BADFLAGS    -1    /* Invalid value for `ai_flags' field.  */
-# define EAI_NONAME      -2    /* NAME or SERVICE is unknown.  */
-# define EAI_AGAIN       -3    /* Temporary failure in name resolution.  */
-# define EAI_FAIL        -4    /* Non-recoverable failure in name res.  */
-# define EAI_NODATA      -5    /* No address associated with NAME.  */
-# define EAI_FAMILY      -6    /* `ai_family' not supported.  */
-# define EAI_SOCKTYPE    -7    /* `ai_socktype' not supported.  */
-# 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.  */
-#endif
-#ifndef EAI_ADDRFAMILY
-/* Not defined on mingw32. */
-# define EAI_ADDRFAMILY  -9    /* Address family for NAME not supported.  */
-#endif
-#ifndef EAI_SYSTEM
-/* Not defined on mingw32. */
-# define EAI_SYSTEM      -11   /* System error returned in `errno'.  */
-#endif
-
-#ifdef __USE_GNU
-# ifndef EAI_INPROGRESS
-#  define EAI_INPROGRESS       -100    /* Processing request in progress.  */
-#  define EAI_CANCELED         -101    /* Request canceled.  */
-#  define EAI_NOTCANCELED      -102    /* Request not canceled.  */
-#  define EAI_ALLDONE          -103    /* All requests done.  */
-#  define EAI_INTR             -104    /* Interrupted by a signal.  */
-#  define EAI_IDN_ENCODE       -105    /* IDN encoding failed.  */
-# endif
-#endif
-
-#if !HAVE_DECL_GETADDRINFO
-/* Translate name of a service location and/or a service name to set of
-   socket addresses.
-   For more details, see the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
-extern int getaddrinfo (const char *restrict nodename,
-                       const char *restrict servname,
-                       const struct addrinfo *restrict hints,
-                       struct addrinfo **restrict res);
-#endif
-
-#if !HAVE_DECL_FREEADDRINFO
-/* Free `addrinfo' structure AI including associated storage.
-   For more details, see the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
-extern void freeaddrinfo (struct addrinfo *ai);
-#endif
-
-#if !HAVE_DECL_GAI_STRERROR
-/* Convert error return from getaddrinfo() to a string.
-   For more details, see the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/gai_strerror.html>.  */
-extern const char *gai_strerror (int ecode);
-#endif
-
-#if !HAVE_DECL_GETNAMEINFO
-/* Convert socket address to printable node and service names.
-   For more details, see the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/getnameinfo.html>.  */
-extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
-                      char *restrict node, socklen_t nodelen,
-                      char *restrict service, socklen_t servicelen,
-                      int flags);
-
-#endif
-
-/* Possible flags for getnameinfo.  */
-#ifndef NI_NUMERICHOST
-# define NI_NUMERICHOST 1
-#endif
-#ifndef NI_NUMERICSERV
-# define NI_NUMERICSERV 2
-#endif
-
-#endif /* GETADDRINFO_H */
diff --git a/lib/netdb.in.h b/lib/netdb.in.h
index f4c2551..e8121aa 100644
--- a/lib/netdb.in.h
+++ b/lib/netdb.in.h
@@ -47,6 +47,138 @@
 
 /* Declarations for a platform that lacks <netdb.h>.  */
 
+#if @GNULIB_GETADDRINFO@
+
+# ifndef HAVE_STRUCT_ADDRINFO
+
+/* Structure to contain information about address of a service provider.  */
+struct addrinfo
+{
+  int ai_flags;                        /* Input flags.  */
+  int ai_family;               /* Protocol family for socket.  */
+  int ai_socktype;             /* Socket type.  */
+  int ai_protocol;             /* Protocol for socket.  */
+  socklen_t ai_addrlen;                /* Length of socket address.  */
+  struct sockaddr *ai_addr;    /* Socket address for socket.  */
+  char *ai_canonname;          /* Canonical name for service location.  */
+  struct addrinfo *ai_next;    /* Pointer to next in list.  */
+};
+# 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,
+   cause conflicts on systems with a getaddrinfo() function which does not
+   define them.
+
+   If they are restored, be sure to protect the definitions with #ifndef.  */
+#  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.  */
+#  define AI_ADDRCONFIG        0x0020  /* Use configuration of this host to 
choose
+                                  returned address type..  */
+# endif /* 0 */
+
+/* Error values for `getaddrinfo' function.  */
+# ifndef EAI_BADFLAGS
+#  define EAI_BADFLAGS   -1    /* Invalid value for `ai_flags' field.  */
+#  define EAI_NONAME     -2    /* NAME or SERVICE is unknown.  */
+#  define EAI_AGAIN      -3    /* Temporary failure in name resolution.  */
+#  define EAI_FAIL       -4    /* Non-recoverable failure in name res.  */
+#  define EAI_NODATA     -5    /* No address associated with NAME.  */
+#  define EAI_FAMILY     -6    /* `ai_family' not supported.  */
+#  define EAI_SOCKTYPE   -7    /* `ai_socktype' not supported.  */
+#  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.  */
+# endif
+# ifndef EAI_ADDRFAMILY
+/* Not defined on mingw32. */
+#  define EAI_ADDRFAMILY  -9   /* Address family for NAME not supported.  */
+# endif
+# ifndef EAI_SYSTEM
+/* Not defined on mingw32. */
+#  define EAI_SYSTEM     -11   /* System error returned in `errno'.  */
+# endif
+
+# ifdef __USE_GNU
+#  ifndef EAI_INPROGRESS
+#   define EAI_INPROGRESS      -100    /* Processing request in progress.  */
+#   define EAI_CANCELED                -101    /* Request canceled.  */
+#   define EAI_NOTCANCELED     -102    /* Request not canceled.  */
+#   define EAI_ALLDONE         -103    /* All requests done.  */
+#   define EAI_INTR            -104    /* Interrupted by a signal.  */
+#   define EAI_IDN_ENCODE      -105    /* IDN encoding failed.  */
+#  endif
+# endif
+
+# if !HAVE_DECL_GETADDRINFO
+/* Translate name of a service location and/or a service name to set of
+   socket addresses.
+   For more details, see the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
+extern int getaddrinfo (const char *restrict nodename,
+                       const char *restrict servname,
+                       const struct addrinfo *restrict hints,
+                       struct addrinfo **restrict res);
+# endif
+
+# if !HAVE_DECL_FREEADDRINFO
+/* Free `addrinfo' structure AI including associated storage.
+   For more details, see the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
+extern void freeaddrinfo (struct addrinfo *ai);
+# endif
+
+# if !HAVE_DECL_GAI_STRERROR
+/* Convert error return from getaddrinfo() to a string.
+   For more details, see the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/gai_strerror.html>.  */
+extern const char *gai_strerror (int ecode);
+# endif
+
+# if !HAVE_DECL_GETNAMEINFO
+/* Convert socket address to printable node and service names.
+   For more details, see the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/getnameinfo.html>.  */
+extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
+                      char *restrict node, socklen_t nodelen,
+                      char *restrict service, socklen_t servicelen,
+                      int flags);
+# endif
+
+/* Possible flags for getnameinfo.  */
+# ifndef NI_NUMERICHOST
+#  define NI_NUMERICHOST 1
+# endif
+# ifndef NI_NUMERICSERV
+#  define NI_NUMERICSERV 2
+# endif
+
+#endif /* @GNULIB_GETADDRINFO@ */
+
 #endif /* HAVE_NETDB_H */
 
 #endif /* _GL_NETDB_H */
diff --git a/m4/getaddrinfo.m4 b/m4/getaddrinfo.m4
index 52135ba..c184c6f 100644
--- a/m4/getaddrinfo.m4
+++ b/m4/getaddrinfo.m4
@@ -1,5 +1,5 @@
-# getaddrinfo.m4 serial 15
-dnl Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+# getaddrinfo.m4 serial 16
+dnl Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -7,10 +7,9 @@ dnl with or without modifications, as long as this notice is 
preserved.
 AC_DEFUN([gl_GETADDRINFO],
 [
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
+  AC_REQUIRE([gl_HEADER_NETDB])dnl for HAVE_NETDB_H
   AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo])
 
-  AC_CHECK_HEADERS_ONCE(netdb.h)
-
   AC_SEARCH_LIBS(getaddrinfo, [nsl socket])
   AC_CACHE_CHECK([for getaddrinfo], [gl_cv_func_getaddrinfo], [
     AC_TRY_LINK([
@@ -72,7 +71,7 @@ AC_DEFUN([gl_GETADDRINFO],
   gl_PREREQ_GETADDRINFO
 ])
 
-# Prerequisites of lib/getaddrinfo.h and lib/getaddrinfo.c.
+# Prerequisites of lib/getaddrinfo.c.
 AC_DEFUN([gl_PREREQ_GETADDRINFO], [
   AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
   AC_SEARCH_LIBS(gethostbyname, [inet nsl])
@@ -104,7 +103,7 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO], [
   dnl have sa_len so the result is correct anyway.
   AC_CHECK_MEMBERS([struct sockaddr.sa_len], , , [#include <sys/socket.h>])
 
-  AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h)
+  AC_CHECK_HEADERS_ONCE(netinet/in.h)
   AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[
   /* sys/types.h is not needed according to POSIX, but the
      sys/socket.h in i386-unknown-freebsd4.10 and
diff --git a/m4/netdb_h.m4 b/m4/netdb_h.m4
index 8e8ff4a..ecb57b4 100644
--- a/m4/netdb_h.m4
+++ b/m4/netdb_h.m4
@@ -28,5 +28,5 @@ AC_DEFUN([gl_NETDB_MODULE_INDICATOR],
 
 AC_DEFUN([gl_NETDB_H_DEFAULTS],
 [
-  :
+  GNULIB_GETADDRINFO=0; AC_SUBST([GNULIB_GETADDRINFO])
 ])
diff --git a/modules/getaddrinfo b/modules/getaddrinfo
index 84a9a96..1abd4e5 100644
--- a/modules/getaddrinfo
+++ b/modules/getaddrinfo
@@ -2,7 +2,6 @@ Description:
 getaddrinfo() function: Get address information.
 
 Files:
-lib/getaddrinfo.h
 lib/getaddrinfo.c
 lib/gai_strerror.c
 m4/getaddrinfo.m4
@@ -15,14 +14,16 @@ snprintf
 socklen
 stdbool
 sys_socket
+netdb
 
 configure.ac:
 gl_GETADDRINFO
+gl_NETDB_MODULE_INDICATOR([getaddrinfo])
 
 Makefile.am:
 
 Include:
-"getaddrinfo.h"
+<netdb.h>
 
 License:
 LGPLv2+
diff --git a/modules/netdb b/modules/netdb
index 3c2e9b4..5165b56 100644
--- a/modules/netdb
+++ b/modules/netdb
@@ -24,6 +24,7 @@ netdb.h: netdb.in.h
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''NEXT_NETDB_H''@|$(NEXT_NETDB_H)|g' \
              -e 's|@''HAVE_NETDB_H''@|$(HAVE_NETDB_H)|g' \
+             -e 's|@''GNULIB_GETADDRINFO''@|$(GNULIB_GETADDRINFO)|g' \
              < $(srcdir)/netdb.in.h; \
        } > address@hidden
        mv address@hidden $@
diff --git a/tests/test-getaddrinfo.c b/tests/test-getaddrinfo.c
index bfdb9cf..a887cb1 100644
--- a/tests/test-getaddrinfo.c
+++ b/tests/test-getaddrinfo.c
@@ -18,7 +18,7 @@
 /* Written by Simon Josefsson.  */
 
 #include <config.h>
-#include "getaddrinfo.h"
+#include <netdb.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <stdio.h>
-- 
1.5.6.5





reply via email to

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