aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/libpq/ip.c69
-rw-r--r--src/backend/libpq/pqcomm.c12
-rw-r--r--src/backend/libpq/pqformat.c10
-rw-r--r--src/include/getaddrinfo.h63
-rw-r--r--src/include/libpq/ip.h46
-rw-r--r--src/include/pg_config.h.in8
-rw-r--r--src/interfaces/libpq/fe-connect.c8
-rw-r--r--src/interfaces/libpq/fe-misc.c4
-rw-r--r--src/port/getaddrinfo.c61
-rw-r--r--src/template/hpux6
10 files changed, 196 insertions, 91 deletions
diff --git a/src/backend/libpq/ip.c b/src/backend/libpq/ip.c
index 3c3b872c1de..a9a7cf1e83b 100644
--- a/src/backend/libpq/ip.c
+++ b/src/backend/libpq/ip.c
@@ -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
@@ -17,11 +17,8 @@
*-------------------------------------------------------------------------
*/
-#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>
@@ -36,18 +33,25 @@
#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 */
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 20954a4ecf1..cc06347e45d 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -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;
diff --git a/src/backend/libpq/pqformat.c b/src/backend/libpq/pqformat.c
index 5f5acb44435..50f17977d3e 100644
--- a/src/backend/libpq/pqformat.c
+++ b/src/backend/libpq/pqformat.c
@@ -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 $
*
*-------------------------------------------------------------------------
*/
@@ -49,13 +49,15 @@
#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
/* --------------------------------
diff --git a/src/include/getaddrinfo.h b/src/include/getaddrinfo.h
index 7933f93d705..2b47d613e99 100644
--- a/src/include/getaddrinfo.h
+++ b/src/include/getaddrinfo.h
@@ -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 */
diff --git a/src/include/libpq/ip.h b/src/include/libpq/ip.h
index ac782a03364..7866b81ccbd 100644
--- a/src/include/libpq/ip.h
+++ b/src/include/libpq/ip.h
@@ -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 */
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index f515c6cff1a..d135e815a93 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -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
@@ -465,6 +465,9 @@
/* 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
@@ -589,6 +592,9 @@
/* 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
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 141c80e2765..3d938031efe 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -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)
{
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index ad99e5de15a..0f971343ccc 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -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"
diff --git a/src/port/getaddrinfo.c b/src/port/getaddrinfo.c
index aa3d3ab6b87..972f6b6b39e 100644
--- a/src/port/getaddrinfo.c
+++ b/src/port/getaddrinfo.c
@@ -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 */
}
diff --git a/src/template/hpux b/src/template/hpux
index 4db8f44eba1..34a5e861442 100644
--- a/src/template/hpux
+++ b/src/template/hpux
@@ -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