Header And Logo

PostgreSQL
| The world's most advanced open source database.

getaddrinfo.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * getaddrinfo.h
00004  *    Support getaddrinfo() on platforms that don't have it.
00005  *
00006  * Note: we use our own routines on platforms that don't HAVE_STRUCT_ADDRINFO,
00007  * whether or not the library routine getaddrinfo() can be found.  This
00008  * policy is needed because on some platforms a manually installed libbind.a
00009  * may provide getaddrinfo(), yet the system headers may not provide the
00010  * struct definitions needed to call it.  To avoid conflict with the libbind
00011  * definition in such cases, we rename our routines to pg_xxx() via macros.
00012  *
00013  * This code will also work on platforms where struct addrinfo is defined
00014  * in the system headers but no getaddrinfo() can be located.
00015  *
00016  * Copyright (c) 2003-2013, PostgreSQL Global Development Group
00017  *
00018  * src/include/getaddrinfo.h
00019  *
00020  *-------------------------------------------------------------------------
00021  */
00022 #ifndef GETADDRINFO_H
00023 #define GETADDRINFO_H
00024 
00025 #include <sys/socket.h>
00026 #include <netdb.h>
00027 
00028 
00029 /* Various macros that ought to be in <netdb.h>, but might not be */
00030 
00031 #ifndef EAI_FAIL
00032 #ifndef WIN32
00033 #define EAI_BADFLAGS    (-1)
00034 #define EAI_NONAME      (-2)
00035 #define EAI_AGAIN       (-3)
00036 #define EAI_FAIL        (-4)
00037 #define EAI_FAMILY      (-6)
00038 #define EAI_SOCKTYPE    (-7)
00039 #define EAI_SERVICE     (-8)
00040 #define EAI_MEMORY      (-10)
00041 #define EAI_SYSTEM      (-11)
00042 #else                           /* WIN32 */
00043 #ifdef WIN32_ONLY_COMPILER
00044 #ifndef WSA_NOT_ENOUGH_MEMORY
00045 #define WSA_NOT_ENOUGH_MEMORY   (WSAENOBUFS)
00046 #endif
00047 #ifndef __BORLANDC__
00048 #define WSATYPE_NOT_FOUND       (WSABASEERR+109)
00049 #endif
00050 #endif
00051 #define EAI_AGAIN       WSATRY_AGAIN
00052 #define EAI_BADFLAGS    WSAEINVAL
00053 #define EAI_FAIL        WSANO_RECOVERY
00054 #define EAI_FAMILY      WSAEAFNOSUPPORT
00055 #define EAI_MEMORY      WSA_NOT_ENOUGH_MEMORY
00056 #define EAI_NODATA      WSANO_DATA
00057 #define EAI_NONAME      WSAHOST_NOT_FOUND
00058 #define EAI_SERVICE     WSATYPE_NOT_FOUND
00059 #define EAI_SOCKTYPE    WSAESOCKTNOSUPPORT
00060 #endif   /* !WIN32 */
00061 #endif   /* !EAI_FAIL */
00062 
00063 #ifndef AI_PASSIVE
00064 #define AI_PASSIVE      0x0001
00065 #endif
00066 
00067 #ifndef AI_NUMERICHOST
00068 /*
00069  * some platforms don't support AI_NUMERICHOST; define as zero if using
00070  * the system version of getaddrinfo...
00071  */
00072 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
00073 #define AI_NUMERICHOST  0
00074 #else
00075 #define AI_NUMERICHOST  0x0004
00076 #endif
00077 #endif
00078 
00079 #ifndef NI_NUMERICHOST
00080 #define NI_NUMERICHOST  1
00081 #endif
00082 #ifndef NI_NUMERICSERV
00083 #define NI_NUMERICSERV  2
00084 #endif
00085 
00086 #ifndef NI_MAXHOST
00087 #define NI_MAXHOST  1025
00088 #endif
00089 #ifndef NI_MAXSERV
00090 #define NI_MAXSERV  32
00091 #endif
00092 
00093 
00094 #ifndef HAVE_STRUCT_ADDRINFO
00095 
00096 #ifndef WIN32
00097 struct addrinfo
00098 {
00099     int         ai_flags;
00100     int         ai_family;
00101     int         ai_socktype;
00102     int         ai_protocol;
00103     size_t      ai_addrlen;
00104     struct sockaddr *ai_addr;
00105     char       *ai_canonname;
00106     struct addrinfo *ai_next;
00107 };
00108 #else
00109 /*
00110  *  The order of the structure elements on Win32 doesn't match the
00111  *  order specified in the standard, but we have to match it for
00112  *  IPv6 to work.
00113  */
00114 struct addrinfo
00115 {
00116     int         ai_flags;
00117     int         ai_family;
00118     int         ai_socktype;
00119     int         ai_protocol;
00120     size_t      ai_addrlen;
00121     char       *ai_canonname;
00122     struct sockaddr *ai_addr;
00123     struct addrinfo *ai_next;
00124 };
00125 #endif
00126 #endif   /* HAVE_STRUCT_ADDRINFO */
00127 
00128 
00129 #ifndef HAVE_GETADDRINFO
00130 
00131 /* Rename private copies per comments above */
00132 #ifdef getaddrinfo
00133 #undef getaddrinfo
00134 #endif
00135 #define getaddrinfo pg_getaddrinfo
00136 
00137 #ifdef freeaddrinfo
00138 #undef freeaddrinfo
00139 #endif
00140 #define freeaddrinfo pg_freeaddrinfo
00141 
00142 #ifdef gai_strerror
00143 #undef gai_strerror
00144 #endif
00145 #define gai_strerror pg_gai_strerror
00146 
00147 #ifdef getnameinfo
00148 #undef getnameinfo
00149 #endif
00150 #define getnameinfo pg_getnameinfo
00151 
00152 extern int getaddrinfo(const char *node, const char *service,
00153             const struct addrinfo * hints, struct addrinfo ** res);
00154 extern void freeaddrinfo(struct addrinfo * res);
00155 extern const char *gai_strerror(int errcode);
00156 extern int getnameinfo(const struct sockaddr * sa, int salen,
00157             char *node, int nodelen,
00158             char *service, int servicelen, int flags);
00159 #endif   /* HAVE_GETADDRINFO */
00160 
00161 #endif   /* GETADDRINFO_H */