OSDN Git Service

f0a3a82020793b97ada78bb9b02f7029f44593ed
[pg-rex/syncrep.git] / 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-2005, PostgreSQL Global Development Group
17  *
18  * $PostgreSQL: pgsql/src/include/getaddrinfo.h,v 1.17 2005/10/15 02:49:41 momjian Exp $
19  *
20  *-------------------------------------------------------------------------
21  */
22 #ifndef GETADDRINFO_H
23 #define GETADDRINFO_H
24
25 #ifndef WIN32_CLIENT_ONLY
26 #include <sys/socket.h>
27 #include <netdb.h>
28 #endif
29
30
31 /* Various macros that ought to be in <netdb.h>, but might not be */
32
33 #ifndef EAI_FAIL
34 #ifndef WIN32
35 #define EAI_BADFLAGS    (-1)
36 #define EAI_NONAME              (-2)
37 #define EAI_AGAIN               (-3)
38 #define EAI_FAIL                (-4)
39 #define EAI_FAMILY              (-6)
40 #define EAI_SOCKTYPE    (-7)
41 #define EAI_SERVICE             (-8)
42 #define EAI_MEMORY              (-10)
43 #define EAI_SYSTEM              (-11)
44 #else                                                   /* WIN32 */
45 #define EAI_AGAIN               WSATRY_AGAIN
46 #define EAI_BADFLAGS    WSAEINVAL
47 #define EAI_FAIL                WSANO_RECOVERY
48 #define EAI_FAMILY              WSAEAFNOSUPPORT
49 #define EAI_MEMORY              WSA_NOT_ENOUGH_MEMORY
50 #define EAI_NODATA              WSANO_DATA
51 #define EAI_NONAME              WSAHOST_NOT_FOUND
52 #define EAI_SERVICE             WSATYPE_NOT_FOUND
53 #define EAI_SOCKTYPE    WSAESOCKTNOSUPPORT
54 #endif   /* !WIN32 */
55 #endif   /* !EAI_FAIL */
56
57 #ifndef AI_PASSIVE
58 #define AI_PASSIVE              0x0001
59 #endif
60
61 #ifndef AI_NUMERICHOST
62 /*
63  * some platforms don't support AI_NUMERICHOST; define as zero if using
64  * the system version of getaddrinfo...
65  */
66 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
67 #define AI_NUMERICHOST  0
68 #else
69 #define AI_NUMERICHOST  0x0004
70 #endif
71 #endif
72
73 #ifndef NI_NUMERICHOST
74 #define NI_NUMERICHOST  1
75 #endif
76 #ifndef NI_NUMERICSERV
77 #define NI_NUMERICSERV  2
78 #endif
79
80 #ifndef NI_MAXHOST
81 #define NI_MAXHOST      1025
82 #endif
83 #ifndef NI_MAXSERV
84 #define NI_MAXSERV      32
85 #endif
86
87
88 #ifndef HAVE_STRUCT_ADDRINFO
89
90 struct addrinfo
91 {
92         int                     ai_flags;
93         int                     ai_family;
94         int                     ai_socktype;
95         int                     ai_protocol;
96         size_t          ai_addrlen;
97         struct sockaddr *ai_addr;
98         char       *ai_canonname;
99         struct addrinfo *ai_next;
100 };
101 #endif   /* HAVE_STRUCT_ADDRINFO */
102
103
104 #ifndef HAVE_GETADDRINFO
105
106 /* Rename private copies per comments above */
107 #ifdef getaddrinfo
108 #undef getaddrinfo
109 #endif
110 #define getaddrinfo pg_getaddrinfo
111
112 #ifdef freeaddrinfo
113 #undef freeaddrinfo
114 #endif
115 #define freeaddrinfo pg_freeaddrinfo
116
117 #ifdef gai_strerror
118 #undef gai_strerror
119 #endif
120 #define gai_strerror pg_gai_strerror
121
122 #ifdef getnameinfo
123 #undef getnameinfo
124 #endif
125 #define getnameinfo pg_getnameinfo
126
127 extern int getaddrinfo(const char *node, const char *service,
128                         const struct addrinfo * hints, struct addrinfo ** res);
129 extern void freeaddrinfo(struct addrinfo * res);
130 extern const char *gai_strerror(int errcode);
131 extern int getnameinfo(const struct sockaddr * sa, int salen,
132                         char *node, int nodelen,
133                         char *service, int servicelen, int flags);
134 #endif   /* HAVE_GETADDRINFO */
135
136 #endif   /* GETADDRINFO_H */