]> granicus.if.org Git - postgresql/blob - src/include/getaddrinfo.h
Add 'output file' option for pg_dumpall, especially useful for Win32,
[postgresql] / src / include / getaddrinfo.h
1 /*-------------------------------------------------------------------------
2  *
3  * getaddrinfo.h
4  *        Support getaddrinfo() on platforms that don't have it.
5  *
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.
12  *
13  * This code will also work on platforms where struct addrinfo is defined
14  * in the system headers but no getaddrinfo() can be located.
15  *
16  * Copyright (c) 2003-2007, PostgreSQL Global Development Group
17  *
18  * $PostgreSQL: pgsql/src/include/getaddrinfo.h,v 1.23 2007/01/05 22:19:50 momjian Exp $
19  *
20  *-------------------------------------------------------------------------
21  */
22 #ifndef GETADDRINFO_H
23 #define GETADDRINFO_H
24
25 #include <sys/socket.h>
26 #include <netdb.h>
27
28
29 /* Various macros that ought to be in <netdb.h>, but might not be */
30
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 #define WSATYPE_NOT_FOUND               (WSABASEERR+109)
48 #endif
49 #define EAI_AGAIN               WSATRY_AGAIN
50 #define EAI_BADFLAGS    WSAEINVAL
51 #define EAI_FAIL                WSANO_RECOVERY
52 #define EAI_FAMILY              WSAEAFNOSUPPORT
53 #define EAI_MEMORY              WSA_NOT_ENOUGH_MEMORY
54 #define EAI_NODATA              WSANO_DATA
55 #define EAI_NONAME              WSAHOST_NOT_FOUND
56 #define EAI_SERVICE             WSATYPE_NOT_FOUND
57 #define EAI_SOCKTYPE    WSAESOCKTNOSUPPORT
58 #endif   /* !WIN32 */
59 #endif   /* !EAI_FAIL */
60
61 #ifndef AI_PASSIVE
62 #define AI_PASSIVE              0x0001
63 #endif
64
65 #ifndef AI_NUMERICHOST
66 /*
67  * some platforms don't support AI_NUMERICHOST; define as zero if using
68  * the system version of getaddrinfo...
69  */
70 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
71 #define AI_NUMERICHOST  0
72 #else
73 #define AI_NUMERICHOST  0x0004
74 #endif
75 #endif
76
77 #ifndef NI_NUMERICHOST
78 #define NI_NUMERICHOST  1
79 #endif
80 #ifndef NI_NUMERICSERV
81 #define NI_NUMERICSERV  2
82 #endif
83
84 #ifndef NI_MAXHOST
85 #define NI_MAXHOST      1025
86 #endif
87 #ifndef NI_MAXSERV
88 #define NI_MAXSERV      32
89 #endif
90
91
92 #ifndef HAVE_STRUCT_ADDRINFO
93
94 #ifndef WIN32
95 struct addrinfo
96 {
97         int                     ai_flags;
98         int                     ai_family;
99         int                     ai_socktype;
100         int                     ai_protocol;
101         size_t          ai_addrlen;
102         struct sockaddr *ai_addr;
103         char       *ai_canonname;
104         struct addrinfo *ai_next;
105 };
106 #else
107 /*
108  *      The order of the structure elements on Win32 doesn't match the
109  *      order specified in the standard, but we have to match it for
110  *      IPv6 to work.
111  */
112 struct addrinfo
113 {
114         int                     ai_flags;
115         int                     ai_family;
116         int                     ai_socktype;
117         int                     ai_protocol;
118         size_t          ai_addrlen;
119         char       *ai_canonname;
120         struct sockaddr *ai_addr;
121         struct addrinfo *ai_next;
122 };
123 #endif
124 #endif   /* HAVE_STRUCT_ADDRINFO */
125
126
127 #ifndef HAVE_GETADDRINFO
128
129 /* Rename private copies per comments above */
130 #ifdef getaddrinfo
131 #undef getaddrinfo
132 #endif
133 #define getaddrinfo pg_getaddrinfo
134
135 #ifdef freeaddrinfo
136 #undef freeaddrinfo
137 #endif
138 #define freeaddrinfo pg_freeaddrinfo
139
140 #ifdef gai_strerror
141 #undef gai_strerror
142 #endif
143 #define gai_strerror pg_gai_strerror
144
145 #ifdef getnameinfo
146 #undef getnameinfo
147 #endif
148 #define getnameinfo pg_getnameinfo
149
150 extern int getaddrinfo(const char *node, const char *service,
151                         const struct addrinfo * hints, struct addrinfo ** res);
152 extern void freeaddrinfo(struct addrinfo * res);
153 extern const char *gai_strerror(int errcode);
154 extern int getnameinfo(const struct sockaddr * sa, int salen,
155                         char *node, int nodelen,
156                         char *service, int servicelen, int flags);
157 #endif   /* HAVE_GETADDRINFO */
158
159 #endif   /* GETADDRINFO_H */