]> granicus.if.org Git - postgresql/blob - src/include/getaddrinfo.h
Fix a few macro definitions to ensure that unary minus is enclosed in
[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-2005, PostgreSQL Global Development Group
17  *
18  * $PostgreSQL: pgsql/src/include/getaddrinfo.h,v 1.15 2005/07/27 12:44:10 neilc 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 #define EAI_BADFLAGS    (-1)
35 #define EAI_NONAME              (-2)
36 #define EAI_AGAIN               (-3)
37 #define EAI_FAIL                (-4)
38 #define EAI_FAMILY              (-6)
39 #define EAI_SOCKTYPE    (-7)
40 #define EAI_SERVICE             (-8)
41 #define EAI_MEMORY              (-10)
42 #define EAI_SYSTEM              (-11)
43 #endif
44
45 #ifndef AI_PASSIVE
46 #define AI_PASSIVE              0x0001
47 #endif
48
49 #ifndef AI_NUMERICHOST
50 /*
51  * some platforms don't support AI_NUMERICHOST; define as zero if using
52  * the system version of getaddrinfo...
53  */
54 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
55 #define AI_NUMERICHOST  0
56 #else
57 #define AI_NUMERICHOST  0x0004
58 #endif
59 #endif
60
61 #ifndef NI_NUMERICHOST
62 #define NI_NUMERICHOST  1
63 #endif
64 #ifndef NI_NUMERICSERV
65 #define NI_NUMERICSERV  2
66 #endif
67
68 #ifndef NI_MAXHOST
69 #define NI_MAXHOST      1025
70 #endif
71 #ifndef NI_MAXSERV
72 #define NI_MAXSERV      32
73 #endif
74
75
76 #ifndef HAVE_STRUCT_ADDRINFO
77
78 struct addrinfo
79 {
80         int                     ai_flags;
81         int                     ai_family;
82         int                     ai_socktype;
83         int                     ai_protocol;
84         size_t          ai_addrlen;
85         struct sockaddr *ai_addr;
86         char       *ai_canonname;
87         struct addrinfo *ai_next;
88 };
89 #endif   /* HAVE_STRUCT_ADDRINFO */
90
91
92 #ifndef HAVE_GETADDRINFO
93
94 /* Rename private copies per comments above */
95 #ifdef getaddrinfo
96 #undef getaddrinfo
97 #endif
98 #define getaddrinfo pg_getaddrinfo
99
100 #ifdef freeaddrinfo
101 #undef freeaddrinfo
102 #endif
103 #define freeaddrinfo pg_freeaddrinfo
104
105 #ifdef gai_strerror
106 #undef gai_strerror
107 #endif
108 #define gai_strerror pg_gai_strerror
109
110 #ifdef getnameinfo
111 #undef getnameinfo
112 #endif
113 #define getnameinfo pg_getnameinfo
114
115 extern int getaddrinfo(const char *node, const char *service,
116                         const struct addrinfo * hints, struct addrinfo ** res);
117 extern void freeaddrinfo(struct addrinfo * res);
118 extern const char *gai_strerror(int errcode);
119 extern int getnameinfo(const struct sockaddr * sa, int salen,
120                         char *node, int nodelen,
121                         char *service, int servicelen, int flags);
122 #endif   /* HAVE_GETADDRINFO */
123
124 #endif   /* GETADDRINFO_H */