libpqtypes - getaddrinfo.h

Home Page

array.c
datetime.c
error.c
events.c
exec.c
geo.c
getaddrinfo.h
handler.c
libpqtypes-int.h
libpqtypes.h
misc.c
network.c
numerics.c
param.c
port.c
record.c
regression-test.c
spec.c
utils.c
varlena.c
  1 
  2 /*
  3  * Copyright (c) 2003-2008, PostgreSQL Global Development Group
  4  * $PostgreSQL: pgsql/src/include/getaddrinfo.h
  5  */
  6 
  7 #if defined(__CYGWIN__) || (defined(HAVE_CONFIG_H) && \
  8   !defined(HAVE_GETADDRINFO))
  9 
 10 #ifndef GETADDRINFO_H
 11 #define GETADDRINFO_H
 12 
 13 #include <sys/socket.h>
 14 #define _XOPEN_SOURCE_EXTENDED 1
 15 #include <netdb.h>
 16 
 17 
 18 /* Various macros that ought to be in <netdb.h>, but might not be */
 19 
 20 #ifndef EAI_FAIL
 21 #define EAI_BADFLAGS  (-1)
 22 #define EAI_NONAME    (-2)
 23 #define EAI_AGAIN   (-3)
 24 #define EAI_FAIL    (-4)
 25 #define EAI_FAMILY    (-6)
 26 #define EAI_SOCKTYPE  (-7)
 27 #define EAI_SERVICE   (-8)
 28 #define EAI_MEMORY    (-10)
 29 #define EAI_SYSTEM    (-11)
 30 #endif   /* !EAI_FAIL */
 31 
 32 #ifndef AI_PASSIVE
 33 #define AI_PASSIVE    0x0001
 34 #endif
 35 
 36 #ifndef AI_NUMERICHOST
 37 /*
 38  * some platforms don't support AI_NUMERICHOST; define as zero if using
 39  * the system version of getaddrinfo...
 40  */
 41 #if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO)
 42 #define AI_NUMERICHOST  0
 43 #else
 44 #define AI_NUMERICHOST  0x0004
 45 #endif
 46 #endif
 47 
 48 #ifndef NI_NUMERICHOST
 49 #define NI_NUMERICHOST  1
 50 #endif
 51 #ifndef NI_NUMERICSERV
 52 #define NI_NUMERICSERV  2
 53 #endif
 54 
 55 #ifndef NI_MAXHOST
 56 #define NI_MAXHOST  1025
 57 #endif
 58 #ifndef NI_MAXSERV
 59 #define NI_MAXSERV  32
 60 #endif
 61 
 62 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
 63 
 64 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
 65 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
 66 #define ss_family __ss_family
 67 #else
 68 #error struct sockaddr_storage does not provide an ss_family member
 69 #endif
 70 #endif
 71 
 72 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN
 73 #define ss_len __ss_len
 74 #define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
 75 #endif
 76 #else             /* !HAVE_STRUCT_SOCKADDR_STORAGE */
 77 
 78 /* Define a struct sockaddr_storage if we don't have one. */
 79 
 80 #ifndef __CYGWIN__
 81 struct sockaddr_storage
 82 {
 83   union
 84   {
 85     struct sockaddr sa;   /* get the system-dependent fields */
 86     long long int   ss_align; /* ensures struct is properly aligned */
 87     char    ss_pad[128];  /* ensures struct has desired size */
 88   }     ss_stuff;
 89 };
 90 #endif
 91 
 92 #define ss_family ss_stuff.sa.sa_family
 93 /* It should have an ss_len field if sockaddr has sa_len. */
 94 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
 95 #define ss_len    ss_stuff.sa.sa_len
 96 #define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
 97 #endif
 98 #endif   /* HAVE_STRUCT_SOCKADDR_STORAGE */
 99 
100 #ifndef HAVE_STRUCT_ADDRINFO
101 
102 struct addrinfo
103 {
104   int     ai_flags;
105   int     ai_family;
106   int     ai_socktype;
107   int     ai_protocol;
108   size_t    ai_addrlen;
109   struct sockaddr *ai_addr;
110   char     *ai_canonname;
111   struct addrinfo *ai_next;
112 };
113 
114 #endif   /* HAVE_STRUCT_ADDRINFO */
115 
116 
117 
118 /* Rename private copies per comments above */
119 #ifdef getaddrinfo
120 #undef getaddrinfo
121 #endif
122 
123 #ifdef freeaddrinfo
124 #undef freeaddrinfo
125 #endif
126 
127 #ifdef gai_strerror
128 #undef gai_strerror
129 #endif
130 
131 #ifdef getnameinfo
132 #undef getnameinfo
133 #endif
134 
135 extern int getaddrinfo(const char *node, const char *service,
136       const struct addrinfo * hints, struct addrinfo ** res);
137 extern void freeaddrinfo(struct addrinfo * res);
138 extern const char *gai_strerror(int errcode);
139 extern int getnameinfo(const struct sockaddr * sa, int salen,
140       char *node, int nodelen,
141       char *service, int servicelen, int flags);
142 
143 #endif   /* GETADDRINFO_H */
144 
145 #endif /* HAVE_GETADDRINFO */