IPv6 cleanups.

Kurt Roeckx
Andrew Dunstan
This commit is contained in:
Bruce Momjian
2003-06-12 07:36:51 +00:00
parent e5549a272d
commit b4cea00a1f
20 changed files with 905 additions and 586 deletions

View File

@ -16,7 +16,7 @@
*
* Copyright (c) 2003, PostgreSQL Global Development Group
*
* $Id: getaddrinfo.h,v 1.2 2003/04/02 00:49:28 tgl Exp $
* $Id: getaddrinfo.h,v 1.3 2003/06/12 07:36:51 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -40,23 +40,30 @@ struct addrinfo {
struct addrinfo *ai_next;
};
#define EAI_BADFLAGS -1
#define EAI_BADFLAGS -1
#define EAI_NONAME -2
#define EAI_AGAIN -3
#define EAI_FAIL -4
#define EAI_NODATA -5
#define EAI_FAMILY -6
#define EAI_SOCKTYPE -7
#define EAI_SOCKTYPE -7
#define EAI_SERVICE -8
#define EAI_ADDRFAMILY -9
#define EAI_MEMORY -10
#define EAI_SYSTEM -11
#define AI_PASSIVE 0x0001
#define AI_NUMERICHOST 0x0004
#define NI_NUMERICHOST 1
#define NI_NUMERICSERV 2
#endif /* HAVE_STRUCT_ADDRINFO */
#ifndef NI_MAXHOST
#define NI_MAXHOST 1025
#define NI_MAXSERV 32
#endif
#ifndef HAVE_GETADDRINFO
@ -76,10 +83,18 @@ struct addrinfo {
#endif
#define gai_strerror pg_gai_strerror
#ifdef getnameinfo
#undef getnameinfo
#endif
#define getnameinfo pg_getnameinfo
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);
extern int getnameinfo(const struct sockaddr *sa, int salen,
char *node, int nodelen,
char *service, int servicelen, int flags);
#endif /* HAVE_GETADDRINFO */

View File

@ -5,7 +5,7 @@
*
* Copyright (c) 2003, PostgreSQL Global Development Group
*
* $Id: ip.h,v 1.7 2003/06/12 07:00:57 momjian Exp $
* $Id: ip.h,v 1.8 2003/06/12 07:36:51 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -21,12 +21,17 @@ extern int getaddrinfo2(const char *hostname, const char *servname,
struct addrinfo **result);
extern 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);
extern int rangeSockAddr(const struct sockaddr_storage *addr,
const struct sockaddr_storage *netaddr,
const struct sockaddr_storage *netmask);
extern int isAF_INETx(const int family);
extern int rangeSockAddr(const SockAddr *addr, const SockAddr *netaddr,
const SockAddr *netmask);
extern int SockAddr_cidr_mask(struct sockaddr_storage **mask,
char *numbits, int family);
#ifdef HAVE_UNIX_SOCKETS
#define IS_AF_UNIX(fam) (fam == AF_UNIX)
#else
#define IS_AF_UNIX(fam) (0)
#endif
#endif /* IP_H */

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: libpq.h,v 1.57 2003/04/19 00:02:29 tgl Exp $
* $Id: libpq.h,v 1.58 2003/06/12 07:36:51 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -46,7 +46,8 @@ typedef struct
* prototypes for functions in pqcomm.c
*/
extern int StreamServerPort(int family, char *hostName,
unsigned short portNumber, char *unixSocketName, int *fdP);
unsigned short portNumber, char *unixSocketName, int ListenSocket[],
int MaxListen);
extern int StreamConnection(int server_fd, Port *port);
extern void StreamClose(int sock);
extern void TouchSocketFile(void);

View File

@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pqcomm.h,v 1.85 2003/05/08 18:33:32 tgl Exp $
* $Id: pqcomm.h,v 1.86 2003/06/12 07:36:51 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -32,58 +32,60 @@
#include <netinet/in.h>
#endif /* not WIN32 */
#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
/* Define a struct sockaddr_storage if we don't have one. */
/*
* Desired design of maximum size and alignment
*/
#define _SS_MAXSIZE 128 /* Implementation specific max size */
#define _SS_ALIGNSIZE (sizeof (int64_t))
/* Implementation specific desired alignment */
/*
* Definitions used for sockaddr_storage structure paddings design.
*/
#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof (sa_family_t))
#define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (sa_family_t) + \
_SS_PAD1SIZE + _SS_ALIGNSIZE))
#ifndef INET_ADDRSTRLEN
#define INET_ADDRSTRLEN 16
struct sockaddr_storage {
#ifdef SALEN
uint8_t __ss_len; /* address length */
#endif
sa_family_t ss_family; /* address family */
#ifndef INET6_ADDRSTRLEN
#define INET6_ADDRSTRLEN 46
#endif
#ifndef HAVE_STRUCT_SOCKADDR_UN
struct sockaddr_un
{
short int sun_family; /* AF_UNIX */
char sun_path[108]; /* path name (gag) */
char __ss_pad1[_SS_PAD1SIZE];
/* 6 byte pad, this is to make implementation
* specific pad up to alignment field that
* follows explicit in the data structure */
int64_t __ss_align;
/* field to force desired structure
* storage alignment */
char __ss_pad2[_SS_PAD2SIZE];
/* 112 byte pad to achieve desired size,
* _SS_MAXSIZE value minus size of ss_family
* __ss_pad1, __ss_align fields is 112 */
};
#endif
/* Define a generic socket address type. */
typedef union SockAddr
{
struct sockaddr sa;
struct sockaddr_in in;
#ifdef HAVE_IPV6
struct sockaddr_in6 in6;
#endif
struct sockaddr_un un;
typedef struct {
struct sockaddr_storage addr;
ACCEPT_TYPE_ARG3 salen;
} SockAddr;
/* Some systems don't have it, so default it to 0 so it doesn't
* have any effect on those systems. */
#ifndef AI_ADDRCONFIG
#define AI_ADDRCONFIG 0
#endif
/* Configure the UNIX socket location for the well known port. */
#define UNIXSOCK_PATH(sun,port,defpath) \
snprintf((sun).sun_path, sizeof((sun).sun_path), "%s/.s.PGSQL.%d", \
#define UNIXSOCK_PATH(path,port,defpath) \
snprintf(path, sizeof(path), "%s/.s.PGSQL.%d", \
((defpath) && *(defpath) != '\0') ? (defpath) : \
DEFAULT_PGSOCKET_DIR, \
(port))
/*
* We do this because sun_len is in BSD's struct, while others don't.
* We never actually set BSD's sun_len, and I can't think of a
* platform-safe way of doing it, but the code still works. bjm
*/
#if defined(SUN_LEN)
#define UNIXSOCK_LEN(sun) \
(SUN_LEN(&(sun)))
#else
#define UNIXSOCK_LEN(sun) \
(strlen((sun).sun_path) + offsetof(struct sockaddr_un, sun_path))
#endif
/*
* These manipulate the frontend/backend protocol version number.
*

View File

@ -411,6 +411,9 @@
/* Define to 1 if the system has the type `struct fcred'. */
#undef HAVE_STRUCT_FCRED
/* Define to 1 if the system has the type `struct sockaddr_storage'. */
#undef HAVE_STRUCT_SOCKADDR_STORAGE
/* Define to 1 if the system has the type `struct sockaddr_un'. */
#undef HAVE_STRUCT_SOCKADDR_UN
@ -487,6 +490,9 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have unix sockets. */
#undef HAVE_UNIX_SOCKETS
/* Define to 1 if you have the `utime' function. */
#undef HAVE_UTIME

View File

@ -6,7 +6,7 @@
* for developers. If you edit any of these, be sure to do a *full*
* rebuild (and an initdb if noted).
*
* $Id: pg_config_manual.h,v 1.3 2003/05/15 16:35:29 momjian Exp $
* $Id: pg_config_manual.h,v 1.4 2003/06/12 07:36:51 momjian Exp $
*------------------------------------------------------------------------
*/
@ -127,11 +127,10 @@
#define BITS_PER_BYTE 8
/*
* Define this if your operating system supports AF_UNIX family
* sockets.
* Disable UNIX sockets for those operating system.
*/
#if !defined(__QNX__) && !defined(__BEOS__) && !defined(WIN32)
# define HAVE_UNIX_SOCKETS 1
#if defined(__QNX__) || defined(__BEOS__) || defined(WIN32)
# undef HAVE_UNIX_SOCKETS
#endif
/*

View File

@ -9,7 +9,3 @@
typedef unsigned char slock_t;
/* This is marked as obsoleted in BSD/OS 4.3. */
#ifndef EAI_ADDRFAMILY
#define EAI_ADDRFAMILY 1
#endif