]> granicus.if.org Git - postgresql/commitdiff
Whack getaddrinfo() patch around until it works, more or less, on
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 2 Apr 2003 00:49:28 +0000 (00:49 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 2 Apr 2003 00:49:28 +0000 (00:49 +0000)
machines without IPv6.  Or at least it works on HPUX 10.20 ...

13 files changed:
config/c-library.m4
configure
configure.in
src/backend/libpq/ip.c
src/backend/libpq/pqcomm.c
src/backend/libpq/pqformat.c
src/include/getaddrinfo.h
src/include/libpq/ip.h
src/include/pg_config.h.in
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/fe-misc.c
src/port/getaddrinfo.c
src/template/hpux

index 906a787f0ecd6d542e578d9a14beec97eb101539..4453723bd5bf9a126f64550ed0cce75cec73f425 100644 (file)
@@ -1,5 +1,5 @@
 # Macros that test various C library quirks
-# $Header: /cvsroot/pgsql/config/c-library.m4,v 1.15 2003/01/28 21:57:12 petere Exp $
+# $Header: /cvsroot/pgsql/config/c-library.m4,v 1.16 2003/04/02 00:49:27 tgl Exp $
 
 
 # PGAC_VAR_INT_TIMEZONE
@@ -62,6 +62,16 @@ AC_DEFUN([PGAC_STRUCT_SOCKADDR_UN],
 ])])# PGAC_STRUCT_SOCKADDR_UN
 
 
+# PGAC_STRUCT_ADDRINFO
+# -----------------------
+# If `struct addrinfo' exists, define HAVE_STRUCT_ADDRINFO.
+AC_DEFUN([PGAC_STRUCT_ADDRINFO],
+[AC_CHECK_TYPES([struct addrinfo], [], [],
+[#include <sys/socket.h>
+#include <netdb.h>
+])])# PGAC_STRUCT_ADDRINFO
+
+
 # PGAC_FUNC_POSIX_SIGNALS
 # -----------------------
 # Check to see if the machine has the POSIX signal interface. Define
index 72f9dc3f133202f0cb81cb64e88d17caa2677f33..4bb4d8a46516606a04a9d96f0bd51ca042be3850 100755 (executable)
--- a/configure
+++ b/configure
@@ -9392,6 +9392,66 @@ cat >>confdefs.h <<_ACEOF
 _ACEOF
 
 
+fi
+
+echo "$as_me:$LINENO: checking for struct addrinfo" >&5
+echo $ECHO_N "checking for struct addrinfo... $ECHO_C" >&6
+if test "${ac_cv_type_struct_addrinfo+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+#include <sys/socket.h>
+#include <netdb.h>
+
+
+#ifdef F77_DUMMY_MAIN
+#  ifdef __cplusplus
+     extern "C"
+#  endif
+   int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+if ((struct addrinfo *) 0)
+  return 0;
+if (sizeof (struct addrinfo))
+  return 0;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_type_struct_addrinfo=yes
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+ac_cv_type_struct_addrinfo=no
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_type_struct_addrinfo" >&5
+echo "${ECHO_T}$ac_cv_type_struct_addrinfo" >&6
+if test $ac_cv_type_struct_addrinfo = yes; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_ADDRINFO 1
+_ACEOF
+
+
 fi
 
 
 
 
 
+for ac_func in fseeko gethostname getopt_long getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.  */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char $ac_func ();
+char (*f) ();
+
+#ifdef F77_DUMMY_MAIN
+#  ifdef __cplusplus
+     extern "C"
+#  endif
+   int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+f = $ac_func;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+eval "$as_ac_var=no"
+fi
+rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+else
+  LIBOBJS="$LIBOBJS $ac_func.$ac_objext"
+fi
+done
+
+
+
+# system's version of getaddrinfo(), if any, may be used only if we found
+# a definition for struct addrinfo; see notes in src/include/getaddrinfo.h
+if test x"$ac_cv_type_struct_addrinfo" = xyes ; then
 
-for ac_func in fseeko getaddrinfo gethostname getopt_long getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul
+for ac_func in getaddrinfo
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 echo "$as_me:$LINENO: checking for $ac_func" >&5
@@ -11029,6 +11171,9 @@ fi
 done
 
 
+else
+  LIBOBJS="$LIBOBJS getaddrinfo.$ac_objext"
+fi
 
 # BSD/OS & NetBSD use a custom fseeko/ftello built on fsetpos/fgetpos
 # We override the previous test that said fseeko/ftello didn't exist
index a7d961ecb1466a55da415c0dca45331501183837..ed59aa9025ddf16bbe498045ad8b272d324a6a7a 100644 (file)
@@ -1,5 +1,5 @@
 dnl Process this file with autoconf to produce a configure script.
-dnl $Header: /cvsroot/pgsql/configure.in,v 1.240 2003/03/29 11:31:51 petere Exp $
+dnl $Header: /cvsroot/pgsql/configure.in,v 1.241 2003/04/02 00:49:28 tgl Exp $
 dnl
 dnl Developers, please strive to achieve this order:
 dnl
@@ -746,6 +746,7 @@ AC_C_VOLATILE
 AC_STRUCT_TIMEZONE
 PGAC_UNION_SEMUN
 PGAC_STRUCT_SOCKADDR_UN
+PGAC_STRUCT_ADDRINFO
 
 AC_CHECK_TYPES([struct cmsgcred, struct fcred, struct sockcred], [], [],
 [#include <sys/param.h>
@@ -847,7 +848,15 @@ else
   AC_CHECK_FUNCS([fpclass fp_class fp_class_d class], [break])
 fi
 
-AC_REPLACE_FUNCS([fseeko getaddrinfo gethostname getopt_long getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul])
+AC_REPLACE_FUNCS([fseeko gethostname getopt_long getrusage inet_aton random srandom strcasecmp strdup strerror strtol strtoul])
+
+# system's version of getaddrinfo(), if any, may be used only if we found
+# a definition for struct addrinfo; see notes in src/include/getaddrinfo.h
+if test x"$ac_cv_type_struct_addrinfo" = xyes ; then
+  AC_REPLACE_FUNCS([getaddrinfo])
+else
+  AC_LIBOBJ(getaddrinfo)
+fi
 
 # BSD/OS & NetBSD use a custom fseeko/ftello built on fsetpos/fgetpos
 # We override the previous test that said fseeko/ftello didn't exist
index 3c3b872c1de042228fac61b03b5cc64eb3960e58..a9a7cf1e83b69093ba690e561d278e6d63738a73 100644 (file)
@@ -1,14 +1,14 @@
 /*-------------------------------------------------------------------------
  *
  * ip.c
- *       Handles IPv6
+ *       IPv6-aware network access.
  *
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.3 2003/03/29 11:31:51 petere Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/libpq/ip.c,v 1.4 2003/04/02 00:49:28 tgl Exp $
  *
  * This file and the IPV6 implementation were initially provided by
  * Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
  *-------------------------------------------------------------------------
  */
 
-#ifndef FRONTEND
-#include "postgres.h"
-#else
-#include "postgres_fe.h"
-#endif
+/* This is intended to be used in both frontend and backend, so use c.h */
+#include "c.h"
 
 #include <errno.h>
 #include <unistd.h>
 #include <arpa/inet.h>
 #include <sys/file.h>
 
-#include "libpq/libpq.h"
-#include "miscadmin.h"
+#include "libpq/ip.h"
+
+
+static int   rangeSockAddrAF_INET(const SockAddr *addr,
+                                                                 const SockAddr *netaddr,
+                                                                 const SockAddr *netmask);
 
-#ifdef FRONTEND
-#define elog fprintf
-#define LOG  stderr
+#ifdef HAVE_IPV6
+static int   rangeSockAddrAF_INET6(const SockAddr *addr,
+                                                                  const SockAddr *netaddr,
+                                                                  const SockAddr *netmask);
+static void  convSockAddr6to4(const SockAddr *src, SockAddr *dst);
 #endif
 
-#if defined(HAVE_UNIX_SOCKETS)
+#ifdef HAVE_UNIX_SOCKETS
 static int getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
                                                        struct addrinfo **result);
-#endif   /* HAVE_UNIX_SOCKETS */
+#endif
+
 
 /*
  *     getaddrinfo2 - get address info for Unix, IPv4 and IPv6 sockets
@@ -59,15 +63,11 @@ getaddrinfo2(const char *hostname, const char *servname,
 #ifdef HAVE_UNIX_SOCKETS
        if (hintp != NULL && hintp->ai_family == AF_UNIX)
                return getaddrinfo_unix(servname, hintp, result);
-       else
-       {
-#endif   /* HAVE_UNIX_SOCKETS */
-               /* NULL has special meaning to getaddrinfo */
-               return getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
-                                                  servname, hintp, result);
-#ifdef HAVE_UNIX_SOCKETS
-       }
-#endif   /* HAVE_UNIX_SOCKETS */
+#endif
+
+       /* NULL has special meaning to getaddrinfo */
+       return getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
+                                          servname, hintp, result);
 }
 
 
@@ -98,11 +98,11 @@ freeaddrinfo2(int hint_ai_family, struct addrinfo *ai)
 
 #if defined(HAVE_UNIX_SOCKETS)
 /* -------
- *     getaddrinfo_unix - get unix socket info using IPv6
+ *     getaddrinfo_unix - get unix socket info using IPv6-compatible API
  *
  *     Bug:  only one addrinfo is set even though hintsp is NULL or
  *               ai_socktype is 0
- *               AI_CANNONNAME does not support.
+ *               AI_CANONNAME is not supported.
  * -------
  */
 static int
@@ -128,7 +128,7 @@ getaddrinfo_unix(const char *path, const struct addrinfo *hintsp,
 
        if (hints.ai_family != AF_UNIX)
        {
-               elog(LOG, "hints.ai_family is invalid in getaddrinfo_unix()\n");
+               /* shouldn't have been called */
                return EAI_ADDRFAMILY;
        }
 
@@ -247,8 +247,6 @@ SockAddr_pton(SockAddr *sa, const char *src)
 }
 
 
-
-
 /*
  *     isAF_INETx - check to see if sa is AF_INET or AF_INET6
  */
@@ -267,7 +265,8 @@ isAF_INETx(const int family)
 
 
 int
-rangeSockAddr(const SockAddr *addr, const SockAddr *netaddr, const SockAddr *netmask)
+rangeSockAddr(const SockAddr *addr, const SockAddr *netaddr,
+                         const SockAddr *netmask)
 {
        if (addr->sa.sa_family == AF_INET)
                return rangeSockAddrAF_INET(addr, netaddr, netmask);
@@ -279,7 +278,7 @@ rangeSockAddr(const SockAddr *addr, const SockAddr *netaddr, const SockAddr *net
                return 0;
 }
 
-int
+static int
 rangeSockAddrAF_INET(const SockAddr *addr, const SockAddr *netaddr,
                                         const SockAddr *netmask)
 {
@@ -294,8 +293,10 @@ rangeSockAddrAF_INET(const SockAddr *addr, const SockAddr *netaddr,
                return 0;
 }
 
+
 #ifdef HAVE_IPV6
-int
+
+static int
 rangeSockAddrAF_INET6(const SockAddr *addr, const SockAddr *netaddr,
                                          const SockAddr *netmask)
 {
@@ -324,7 +325,7 @@ rangeSockAddrAF_INET6(const SockAddr *addr, const SockAddr *netaddr,
        return 1;
 }
 
-void
+static void
 convSockAddr6to4(const SockAddr *src, SockAddr *dst)
 {
        char            addr_str[INET6_ADDRSTRLEN];
@@ -337,6 +338,8 @@ convSockAddr6to4(const SockAddr *src, SockAddr *dst)
                + (src->in6.sin6_addr.s6_addr[14] << 8)
                + (src->in6.sin6_addr.s6_addr[13] << 16)
                + (src->in6.sin6_addr.s6_addr[12] << 24);
+
        SockAddr_ntop(src, addr_str, INET6_ADDRSTRLEN, 0);
 }
-#endif
+
+#endif /* HAVE_IPV6 */
index 20954a4ecf17d94b937bd266c1cff919a0cb26e4..cc06347e45d7599fa27b0475566d97971ec3d805 100644 (file)
@@ -29,7 +29,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- *     $Id: pqcomm.c,v 1.148 2003/03/29 11:31:51 petere Exp $
+ *     $Id: pqcomm.c,v 1.149 2003/04/02 00:49:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -204,7 +204,11 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
        struct addrinfo *addrs = NULL;
        struct addrinfo hint;
 
-       Assert(family == AF_INET6 || family == AF_INET || family == AF_UNIX);
+#ifdef HAVE_UNIX_SOCKETS
+       Assert(family == AF_UNIX || isAF_INETx(family));
+#else
+       Assert(isAF_INETx(family));
+#endif
 
        /* Initialize hint structure */
        MemSet(&hint, 0, sizeof(hint));
@@ -229,8 +233,8 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
        ret = getaddrinfo2(hostName, service, &hint, &addrs);
        if (ret || addrs == NULL)
        {
-               elog(LOG, "server socket failure: getaddrinfo2()%s: %s",
-                        (family == AF_INET6) ? " using IPv6" : "", gai_strerror(ret));
+               elog(LOG, "server socket failure: getaddrinfo2(): %s",
+                        gai_strerror(ret));
                if (addrs != NULL)
                        freeaddrinfo2(hint.ai_family, addrs);
                return STATUS_ERROR;
index 5f5acb44435e587caabf4e7e9c109430cccd872b..50f17977d3eb9196c9bae2b754bc17385d4bbb93 100644 (file)
@@ -16,7 +16,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- *     $Id: pqformat.c,v 1.25 2002/09/04 23:31:35 tgl Exp $
+ *     $Id: pqformat.c,v 1.26 2003/04/02 00:49:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 
 #include <errno.h>
 #include <sys/param.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#ifdef HAVE_ENDIAN_H
+#include <endian.h>
+#endif
 
 #include "libpq/libpq.h"
 #include "libpq/pqformat.h"
 #include "mb/pg_wchar.h"
-#ifdef HAVE_ENDIAN_H
-#include <endian.h>
-#endif
 
 
 /* --------------------------------
index 7933f93d7053d846bfdb74340649a742e3ad3742..2b47d613e9967f067f8b83fdddaaccbaee52b905 100644 (file)
@@ -1,12 +1,34 @@
-/* $Header: /cvsroot/pgsql/src/include/getaddrinfo.h,v 1.1 2003/03/29 11:31:51 petere Exp $ */
-
+/*-------------------------------------------------------------------------
+ *
+ * getaddrinfo.h
+ *       Support getaddrinfo() on platforms that don't have it.
+ *
+ *
+ * Note: we use our own routines on platforms that don't HAVE_STRUCT_ADDRINFO,
+ * whether or not the library routine getaddrinfo() can be found.  This
+ * policy is needed because on some platforms a manually installed libbind.a
+ * may provide getaddrinfo(), yet the system headers may not provide the
+ * struct definitions needed to call it.  To avoid conflict with the libbind
+ * definition in such cases, we rename our routines to pg_xxx() via macros.
+ *
+ * This code will also work on platforms where struct addrinfo is defined
+ * in the system headers but no getaddrinfo() can be located.
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ * $Id: getaddrinfo.h,v 1.2 2003/04/02 00:49:28 tgl Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
 #ifndef GETADDRINFO_H
 #define GETADDRINFO_H
 
-#include "c.h"
+#include <sys/socket.h>
 #include <netdb.h>
 
 
+#ifndef HAVE_STRUCT_ADDRINFO
+
 struct addrinfo {
        int     ai_flags;
        int     ai_family;
@@ -18,13 +40,6 @@ struct addrinfo {
        struct addrinfo *ai_next;
 };
 
-
-int getaddrinfo(const char *node, const char *service,
-                               const struct addrinfo *hints, struct addrinfo **res);
-void freeaddrinfo(struct addrinfo *res);
-const char *gai_strerror(int errcode);
-
-
 #define EAI_BADFLAGS   -1
 #define EAI_NONAME             -2
 #define EAI_AGAIN              -3
@@ -40,4 +55,32 @@ const char *gai_strerror(int errcode);
 #define AI_PASSIVE             0x0001
 #define AI_NUMERICHOST 0x0004
 
+#endif /* HAVE_STRUCT_ADDRINFO */
+
+
+#ifndef HAVE_GETADDRINFO
+
+/* Rename private copies per comments above */
+#ifdef getaddrinfo
+#undef getaddrinfo
+#endif
+#define getaddrinfo pg_getaddrinfo
+
+#ifdef freeaddrinfo
+#undef freeaddrinfo
+#endif
+#define freeaddrinfo pg_freeaddrinfo
+
+#ifdef gai_strerror
+#undef gai_strerror
+#endif
+#define gai_strerror pg_gai_strerror
+
+extern int getaddrinfo(const char *node, const char *service,
+                                          const struct addrinfo *hints, struct addrinfo **res);
+extern void freeaddrinfo(struct addrinfo *res);
+extern const char *gai_strerror(int errcode);
+
+#endif /* HAVE_GETADDRINFO */
+
 #endif /* GETADDRINFO_H */
index ac782a03364599126b0b733f581d56e5e51c0fba..7866b81ccbdc8e2e0f0d3e758f9b4efe34d185d3 100644 (file)
@@ -1,28 +1,32 @@
+/*-------------------------------------------------------------------------
+ *
+ * ip.h
+ *       Definitions for IPv6-aware network access.
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ * $Id: ip.h,v 1.3 2003/04/02 00:49:28 tgl Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
 #ifndef IP_H
 #define IP_H
-#include "c.h"
-#include <sys/socket.h>
-#include <netdb.h>
-#include "libpq/pqcomm.h"
-#ifndef HAVE_GETADDRINFO
+
 #include "getaddrinfo.h"
-#endif
+#include "libpq/pqcomm.h"
+
+
+extern int   getaddrinfo2(const char *hostname, const char *servname,
+                                                 const struct addrinfo *hintp,
+                                                 struct addrinfo **result);
+extern void  freeaddrinfo2(int hint_ai_family, struct addrinfo *ai);
 
-int   getaddrinfo2(const char *hostname, const char *servname,
-                                  const struct addrinfo *hintp, struct addrinfo **result);
-void  freeaddrinfo2(int hint_ai_family, struct addrinfo *ai);
+extern char *SockAddr_ntop(const SockAddr *sa, char *dst, size_t cnt,
+                                                  int v4conv);
+extern int   SockAddr_pton(SockAddr *sa, const char *src);
 
-char *SockAddr_ntop(const SockAddr *sa, char *dst, size_t cnt, int v4conv);
-int   SockAddr_pton(SockAddr *sa, const char *src);
-int   isAF_INETx(const int family);
-int   rangeSockAddr(const SockAddr *addr, const SockAddr *netaddr,
-                       const SockAddr *netmask);
-int   rangeSockAddrAF_INET(const SockAddr *addr, const SockAddr *netaddr, 
-                          const SockAddr *netmask);
-#ifdef HAVE_IPV6
-int   rangeSockAddrAF_INET6(const SockAddr *addr, const SockAddr *netaddr, 
-                           const SockAddr *netmask);
-void  convSockAddr6to4(const SockAddr *src, SockAddr *dst);
-#endif
+extern int   isAF_INETx(const int family);
+extern int   rangeSockAddr(const SockAddr *addr, const SockAddr *netaddr,
+                                                  const SockAddr *netmask);
 
 #endif /* IP_H */
index f515c6cff1a26e11c58b6842ae7f21f181744f29..d135e815a93dbb0041560f0e1c59f783540cb387 100644 (file)
@@ -8,7 +8,7 @@
  * or in pg_config.h afterwards.  Of course, if you edit pg_config.h, then your
  * changes will be overwritten the next time you run configure.
  *
- * $Id: pg_config.h.in,v 1.42 2003/03/29 11:31:51 petere Exp $
+ * $Id: pg_config.h.in,v 1.43 2003/04/02 00:49:28 tgl Exp $
  */
 
 #ifndef PG_CONFIG_H
 /* Set to 1 if you have gethostname() */
 #undef HAVE_GETHOSTNAME
 
+/* Set to 1 if you have getpeereid() */
+#undef HAVE_GETPEEREID
+
 /* Set to 1 if struct tm has a tm_zone member */
 #undef HAVE_TM_ZONE
 
 /* Set to 1 if you have struct sockaddr_un */
 #undef HAVE_STRUCT_SOCKADDR_UN
 
+/* Set to 1 if you have struct addrinfo */
+#undef HAVE_STRUCT_ADDRINFO
+
 /* Set to 1 if you have krb5_ticket.enc_part2 */
 #undef HAVE_KRB5_TICKET_ENC_PART2
 
index 141c80e276581848df9d1f1bd3b8ab9404033012..3d938031efed2ca94a4f77394a41539fcc2752ec 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.229 2003/03/29 11:31:51 petere Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.230 2003/04/02 00:49:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -881,9 +881,9 @@ connectDBStart(PGconn *conn)
         * for the *last* alternative, which may not be what users expect
         * :-().
         *
-        * In either case, we never actually fall out of the loop; the
-        * only exits are via "break" or "goto connect_errReturn".  Thus,
-        * there is no exit test in the for().
+        * Notice we never actually fall out of the loop; the only exits are
+        * via "break" or "goto connect_errReturn".  Thus, there is no exit
+        * test in the for().
         */
        for (addr_cur = addrs; ; addr_cur = addr_cur->ai_next)
        {
index ad99e5de15a4c5b73dc2cdd39c47104ddbdcd9de..0f971343ccce35dc34f81d4a54e564f255c6e11e 100644 (file)
@@ -25,7 +25,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.87 2003/03/06 03:16:55 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.88 2003/04/02 00:49:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -35,6 +35,8 @@
 #include <errno.h>
 #include <signal.h>
 #include <time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
 
 #ifdef WIN32
 #include "win32.h"
index aa3d3ab6b876241e0e9ea7a7d5807ceebc53cf7b..972f6b6b39e599f7479154fb56ef3699ba78e6c8 100644 (file)
@@ -1,12 +1,28 @@
-/* $Header: /cvsroot/pgsql/src/port/getaddrinfo.c,v 1.1 2003/03/29 11:31:52 petere Exp $ */
-
+/*-------------------------------------------------------------------------
+ *
+ * getaddrinfo.c
+ *       Support getaddrinfo() on platforms that don't have it.
+ *
+ *
+ * Copyright (c) 2003, PostgreSQL Global Development Group
+ *
+ *
+ * IDENTIFICATION
+ *       $Header: /cvsroot/pgsql/src/port/getaddrinfo.c,v 1.2 2003/04/02 00:49:28 tgl Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/* This is intended to be used in both frontend and backend, so use c.h */
 #include "c.h"
-#include "getaddrinfo.h"
-#include <netdb.h>
+
 #include <sys/socket.h>
+#include <netdb.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
+#include "getaddrinfo.h"
+
 
 int
 getaddrinfo(const char *node, const char *service,
@@ -16,7 +32,8 @@ getaddrinfo(const char *node, const char *service,
        struct addrinfo *ai;
        struct sockaddr_in sin, *psin;
 
-       if (!hints || (hints->ai_family != AF_INET && hints->ai_family != AF_UNSPEC))
+       if (!hints ||
+               (hints->ai_family != AF_INET && hints->ai_family != AF_UNSPEC))
                return EAI_FAMILY;
 
        if (hints->ai_socktype != SOCK_STREAM)
@@ -25,6 +42,10 @@ getaddrinfo(const char *node, const char *service,
        if (!node && !service)
                return EAI_NONAME;
 
+       memset(&sin, 0, sizeof(sin));
+
+       sin.sin_family = AF_INET;
+
        if (node)
        {
                if (node[0] == '\0')
@@ -66,7 +87,7 @@ getaddrinfo(const char *node, const char *service,
        }
 
        if (service)
-               sin.sin_port = htons((unsigned short)atoi(service));
+               sin.sin_port = htons((unsigned short) atoi(service));
 
        ai = malloc(sizeof(*ai));
        if (!ai)
@@ -78,11 +99,11 @@ getaddrinfo(const char *node, const char *service,
                return EAI_MEMORY;
        }
 
-       memcpy(psin, &sin, sizeof(sin));
+       memcpy(psin, &sin, sizeof(*psin));
 
-       ai->ai_family = hints->ai_family;
-       ai->ai_socktype = hints->ai_socktype;
-       ai->ai_protocol = hints->ai_protocol;
+       ai->ai_family = AF_INET;
+       ai->ai_socktype = SOCK_STREAM;
+       ai->ai_protocol = IPPROTO_TCP;
        ai->ai_addrlen = sizeof(*psin);
        ai->ai_addr = (struct sockaddr *) psin;
        ai->ai_canonname = NULL;
@@ -106,9 +127,10 @@ freeaddrinfo(struct addrinfo *res)
 }
 
 
-const char*
+const char *
 gai_strerror(int errcode)
 {
+#ifdef HAVE_HSTRERROR
        int hcode;
 
        switch (errcode)
@@ -129,4 +151,21 @@ gai_strerror(int errcode)
        }
 
        return hstrerror(hcode);
+
+#else /* !HAVE_HSTRERROR */
+
+       switch (errcode)
+       {
+               case EAI_NONAME:
+                       return "Unknown host";
+               case EAI_NODATA:
+                       return "No address associated with name";
+               case EAI_AGAIN:
+                       return "Host name lookup failure";
+               case EAI_FAIL:
+               default:
+                       return "Unknown server error";
+       }
+
+#endif /* HAVE_HSTRERROR */
 }
index 4db8f44eba10f01f41a6ec1ddd3cab3b25c948ed..34a5e8614426748ee1ad2d512d6c7e44af5b56d5 100644 (file)
@@ -1,6 +1,8 @@
 if test "$GCC" = yes ; then
-  CFLAGS=-O2
+  CPPFLAGS="-D_XOPEN_SOURCE_EXTENDED"
+  CFLAGS="-O2"
 else
   CC="$CC -Ae"
-  CFLAGS=+O2
+  CPPFLAGS="-D_XOPEN_SOURCE_EXTENDED"
+  CFLAGS="+O2"
 fi