1 /*-------------------------------------------------------------------------
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-2021, PostgreSQL Global Development Group
18 * src/include/getaddrinfo.h
20 *-------------------------------------------------------------------------
25 #include <sys/socket.h>
29 /* Various macros that ought to be in <netdb.h>, but might not be */
33 #define EAI_BADFLAGS (-1)
34 #define EAI_NONAME (-2)
35 #define EAI_AGAIN (-3)
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)
44 #ifndef WSA_NOT_ENOUGH_MEMORY
45 #define WSA_NOT_ENOUGH_MEMORY (WSAENOBUFS)
47 #define WSATYPE_NOT_FOUND (WSABASEERR+109)
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
59 #endif /* !EAI_FAIL */
62 #define AI_PASSIVE 0x0001
65 #ifndef AI_NUMERICHOST
67 * some platforms don't support AI_NUMERICHOST; define as zero if using
68 * the system version of getaddrinfo...
70 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
71 #define AI_NUMERICHOST 0
73 #define AI_NUMERICHOST 0x0004
77 #ifndef NI_NUMERICHOST
78 #define NI_NUMERICHOST 1
80 #ifndef NI_NUMERICSERV
81 #define NI_NUMERICSERV 2
88 #define NI_MAXHOST 1025
95 #ifndef HAVE_STRUCT_ADDRINFO
105 struct sockaddr
*ai_addr
;
107 struct addrinfo
*ai_next
;
111 * The order of the structure elements on Win32 doesn't match the
112 * order specified in the standard, but we have to match it for
123 struct sockaddr
*ai_addr
;
124 struct addrinfo
*ai_next
;
127 #endif /* HAVE_STRUCT_ADDRINFO */
130 #ifndef HAVE_GETADDRINFO
132 /* Rename private copies per comments above */
136 #define getaddrinfo pg_getaddrinfo
141 #define freeaddrinfo pg_freeaddrinfo
146 #define gai_strerror pg_gai_strerror
151 #define getnameinfo pg_getnameinfo
153 extern int getaddrinfo(const char *node
, const char *service
,
154 const struct addrinfo
*hints
, struct addrinfo
**res
);
155 extern void freeaddrinfo(struct addrinfo
*res
);
156 extern const char *gai_strerror(int errcode
);
157 extern int getnameinfo(const struct sockaddr
*sa
, int salen
,
158 char *node
, int nodelen
,
159 char *service
, int servicelen
, int flags
);
160 #endif /* HAVE_GETADDRINFO */
162 #endif /* GETADDRINFO_H */