Fix pg_dump bug in the database-level collation patch. "datcollate" and
[PostgreSQL.git] / src / include / getaddrinfo.h
blob4db0f05f7ee2f638611bd10c29aabb705c292b2d
1 /*-------------------------------------------------------------------------
3 * getaddrinfo.h
4 * Support getaddrinfo() on platforms that don't have it.
6 * Note: we use our own routines on platforms that don't HAVE_STRUCT_ADDRINFO,
7 * whether or not the library routine getaddrinfo() can be found. This
8 * policy is needed because on some platforms a manually installed libbind.a
9 * may provide getaddrinfo(), yet the system headers may not provide the
10 * struct definitions needed to call it. To avoid conflict with the libbind
11 * definition in such cases, we rename our routines to pg_xxx() via macros.
13 * This code will also work on platforms where struct addrinfo is defined
14 * in the system headers but no getaddrinfo() can be located.
16 * Copyright (c) 2003-2008, PostgreSQL Global Development Group
18 * $PostgreSQL$
20 *-------------------------------------------------------------------------
22 #ifndef GETADDRINFO_H
23 #define GETADDRINFO_H
25 #include <sys/socket.h>
26 #include <netdb.h>
29 /* Various macros that ought to be in <netdb.h>, but might not be */
31 #ifndef EAI_FAIL
32 #ifndef WIN32
33 #define EAI_BADFLAGS (-1)
34 #define EAI_NONAME (-2)
35 #define EAI_AGAIN (-3)
36 #define EAI_FAIL (-4)
37 #define EAI_FAMILY (-6)
38 #define EAI_SOCKTYPE (-7)
39 #define EAI_SERVICE (-8)
40 #define EAI_MEMORY (-10)
41 #define EAI_SYSTEM (-11)
42 #else /* WIN32 */
43 #ifdef WIN32_ONLY_COMPILER
44 #ifndef WSA_NOT_ENOUGH_MEMORY
45 #define WSA_NOT_ENOUGH_MEMORY (WSAENOBUFS)
46 #endif
47 #ifndef __BORLANDC__
48 #define WSATYPE_NOT_FOUND (WSABASEERR+109)
49 #endif
50 #endif
51 #define EAI_AGAIN WSATRY_AGAIN
52 #define EAI_BADFLAGS WSAEINVAL
53 #define EAI_FAIL WSANO_RECOVERY
54 #define EAI_FAMILY WSAEAFNOSUPPORT
55 #define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
56 #define EAI_NODATA WSANO_DATA
57 #define EAI_NONAME WSAHOST_NOT_FOUND
58 #define EAI_SERVICE WSATYPE_NOT_FOUND
59 #define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
60 #endif /* !WIN32 */
61 #endif /* !EAI_FAIL */
63 #ifndef AI_PASSIVE
64 #define AI_PASSIVE 0x0001
65 #endif
67 #ifndef AI_NUMERICHOST
69 * some platforms don't support AI_NUMERICHOST; define as zero if using
70 * the system version of getaddrinfo...
72 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
73 #define AI_NUMERICHOST 0
74 #else
75 #define AI_NUMERICHOST 0x0004
76 #endif
77 #endif
79 #ifndef NI_NUMERICHOST
80 #define NI_NUMERICHOST 1
81 #endif
82 #ifndef NI_NUMERICSERV
83 #define NI_NUMERICSERV 2
84 #endif
86 #ifndef NI_MAXHOST
87 #define NI_MAXHOST 1025
88 #endif
89 #ifndef NI_MAXSERV
90 #define NI_MAXSERV 32
91 #endif
94 #ifndef HAVE_STRUCT_ADDRINFO
96 #ifndef WIN32
97 struct addrinfo
99 int ai_flags;
100 int ai_family;
101 int ai_socktype;
102 int ai_protocol;
103 size_t ai_addrlen;
104 struct sockaddr *ai_addr;
105 char *ai_canonname;
106 struct addrinfo *ai_next;
108 #else
110 * The order of the structure elements on Win32 doesn't match the
111 * order specified in the standard, but we have to match it for
112 * IPv6 to work.
114 struct addrinfo
116 int ai_flags;
117 int ai_family;
118 int ai_socktype;
119 int ai_protocol;
120 size_t ai_addrlen;
121 char *ai_canonname;
122 struct sockaddr *ai_addr;
123 struct addrinfo *ai_next;
125 #endif
126 #endif /* HAVE_STRUCT_ADDRINFO */
129 #ifndef HAVE_GETADDRINFO
131 /* Rename private copies per comments above */
132 #ifdef getaddrinfo
133 #undef getaddrinfo
134 #endif
135 #define getaddrinfo pg_getaddrinfo
137 #ifdef freeaddrinfo
138 #undef freeaddrinfo
139 #endif
140 #define freeaddrinfo pg_freeaddrinfo
142 #ifdef gai_strerror
143 #undef gai_strerror
144 #endif
145 #define gai_strerror pg_gai_strerror
147 #ifdef getnameinfo
148 #undef getnameinfo
149 #endif
150 #define getnameinfo pg_getnameinfo
152 extern int getaddrinfo(const char *node, const char *service,
153 const struct addrinfo * hints, struct addrinfo ** res);
154 extern void freeaddrinfo(struct addrinfo * res);
155 extern const char *gai_strerror(int errcode);
156 extern int getnameinfo(const struct sockaddr * sa, int salen,
157 char *node, int nodelen,
158 char *service, int servicelen, int flags);
159 #endif /* HAVE_GETADDRINFO */
161 #endif /* GETADDRINFO_H */