OSDN Git Service

2011-12-12 Gary Dismukes <dismukes@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / gsocket.h
1 /****************************************************************************
2  *                                                                          *
3  *                         GNAT COMPILER COMPONENTS                         *
4  *                                                                          *
5  *                              G S O C K E T                               *
6  *                                                                          *
7  *                              C Header File                               *
8  *                                                                          *
9  *         Copyright (C) 2004-2011, Free Software Foundation, Inc.          *
10  *                                                                          *
11  * GNAT is free software;  you can  redistribute it  and/or modify it under *
12  * terms of the  GNU General Public License as published  by the Free Soft- *
13  * ware  Foundation;  either version 3,  or (at your option) any later ver- *
14  * sion.  GNAT is distributed in the hope that it will be useful, but WITH- *
15  * OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY *
16  * or FITNESS FOR A PARTICULAR PURPOSE.                                     *
17  *                                                                          *
18  * As a special exception under Section 7 of GPL version 3, you are granted *
19  * additional permissions described in the GCC Runtime Library Exception,   *
20  * version 3.1, as published by the Free Software Foundation.               *
21  *                                                                          *
22  * You should have received a copy of the GNU General Public License and    *
23  * a copy of the GCC Runtime Library Exception along with this program;     *
24  * see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    *
25  * <http://www.gnu.org/licenses/>.                                          *
26  *                                                                          *
27  * GNAT was originally developed  by the GNAT team at  New York University. *
28  * Extensive contributions were provided by Ada Core Technologies Inc.      *
29  *                                                                          *
30  ****************************************************************************/
31
32 #if defined(__nucleus__) || defined(VTHREADS)
33
34 #warning Sockets not supported on these platforms
35 #undef HAVE_SOCKETS
36
37 #else
38
39 #define HAVE_SOCKETS
40
41 #ifndef _XOPEN_SOURCE_EXTENDED
42 #define _XOPEN_SOURCE_EXTENDED 1
43 /* For HP-UX */
44 #endif
45
46 #ifndef BSD_COMP
47 #define BSD_COMP 1
48 /* For Solaris */
49 #endif
50
51 #ifndef _ALL_SOURCE
52 #define _ALL_SOURCE 1
53 /* For AIX */
54 #endif
55
56 #ifndef _OSF_SOURCE
57 #define _OSF_SOURCE 1
58 /* For Tru64 */
59 #endif
60
61 /** No system header may be included prior to this point since on some targets
62  ** we need to redefine FD_SETSIZE.
63  **/
64
65 /* Target-specific includes and definitions */
66
67 #if defined(__vxworks)
68 #include <vxWorks.h>
69 #include <ioLib.h>
70 #include <hostLib.h>
71 #define SHUT_RD         0
72 #define SHUT_WR         1
73 #define SHUT_RDWR       2
74
75 #elif defined (WINNT)
76 #define FD_SETSIZE 1024
77
78 #ifdef __MINGW32__
79 #include <winsock2.h>
80 #include <ws2tcpip.h>
81
82 #undef  EACCES
83 #define EACCES          WSAEACCES
84 #undef  EADDRINUSE
85 #define EADDRINUSE      WSAEADDRINUSE
86 #undef  EADDRNOTAVAIL
87 #define EADDRNOTAVAIL   WSAEADDRNOTAVAIL
88 #undef  EAFNOSUPPORT
89 #define EAFNOSUPPORT    WSAEAFNOSUPPORT
90 #undef  EALREADY
91 #define EALREADY        WSAEALREADY
92 #undef  EBADF
93 #define EBADF           WSAEBADF
94 #undef  ECONNABORTED
95 #define ECONNABORTED    WSAECONNABORTED
96 #undef  ECONNREFUSED
97 #define ECONNREFUSED    WSAECONNREFUSED
98 #undef  ECONNRESET
99 #define ECONNRESET      WSAECONNRESET
100 #undef  EDESTADDRREQ
101 #define EDESTADDRREQ    WSAEDESTADDRREQ
102 #undef  EFAULT
103 #define EFAULT          WSAEFAULT
104 #undef  EHOSTDOWN
105 #define EHOSTDOWN       WSAEHOSTDOWN
106 #undef  EHOSTUNREACH
107 #define EHOSTUNREACH    WSAEHOSTUNREACH
108 #undef  EINPROGRESS
109 #define EINPROGRESS     WSAEINPROGRESS
110 #undef  EINTR
111 #define EINTR           WSAEINTR
112 #undef  EINVAL
113 #define EINVAL          WSAEINVAL
114 #undef  EIO
115 #define EIO             WSAEDISCON
116 #undef  EISCONN
117 #define EISCONN         WSAEISCONN
118 #undef  ELOOP
119 #define ELOOP           WSAELOOP
120 #undef  EMFILE
121 #define EMFILE          WSAEMFILE
122 #undef  EMSGSIZE
123 #define EMSGSIZE        WSAEMSGSIZE
124 #undef  ENAMETOOLONG
125 #define ENAMETOOLONG    WSAENAMETOOLONG
126 #undef  ENETDOWN
127 #define ENETDOWN        WSAENETDOWN
128 #undef  ENETRESET
129 #define ENETRESET       WSAENETRESET
130 #undef  ENETUNREACH
131 #define ENETUNREACH     WSAENETUNREACH
132 #undef  ENOBUFS
133 #define ENOBUFS         WSAENOBUFS
134 #undef  ENOPROTOOPT
135 #define ENOPROTOOPT     WSAENOPROTOOPT
136 #undef  ENOTCONN
137 #define ENOTCONN        WSAENOTCONN
138 #undef  ENOTSOCK
139 #define ENOTSOCK        WSAENOTSOCK
140 #undef  EOPNOTSUPP
141 #define EOPNOTSUPP      WSAEOPNOTSUPP
142 #undef  EPFNOSUPPORT
143 #define EPFNOSUPPORT    WSAEPFNOSUPPORT
144 #undef  EPROTONOSUPPORT
145 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
146 #undef  EPROTOTYPE
147 #define EPROTOTYPE      WSAEPROTOTYPE
148 #undef  ESHUTDOWN
149 #define ESHUTDOWN       WSAESHUTDOWN
150 #undef  ESOCKTNOSUPPORT
151 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
152 #undef  ETIMEDOUT
153 #define ETIMEDOUT       WSAETIMEDOUT
154 #undef  ETOOMANYREFS
155 #define ETOOMANYREFS    WSAETOOMANYREFS
156 #undef  EWOULDBLOCK
157 #define EWOULDBLOCK     WSAEWOULDBLOCK
158
159 #define SHUT_RD         SD_RECEIVE
160 #define SHUT_WR         SD_SEND
161 #define SHUT_RDWR       SD_BOTH
162
163 #endif
164
165 #include <windows.h>
166
167 #elif defined(VMS)
168 /* Allow a large number of fds for select.  */
169 #define FD_SETSIZE 4096
170 #ifndef IN_RTS
171 /* These DEC C headers are not available when building with GCC.  Order is
172    important.  */
173 #include <time.h>
174 #include <tcp.h>
175 #include <in.h>
176 #include <ioctl.h>
177 #include <netdb.h>
178 #endif
179
180 #endif
181
182 #include <limits.h>
183 #include <errno.h>
184
185 #if defined (__vxworks) && ! defined (__RTP__)
186 #include <sys/times.h>
187 #else
188 #include <sys/time.h>
189 #endif
190
191 /*
192  * RTEMS has these .h files but not until you have built and installed RTEMS.
193  * When building a C/C++ toolset, you also build the newlib C library, so the
194  * build procedure for an RTEMS GNAT toolset requires that you build a C/C++
195  * toolset, then build and install RTEMS with --enable-multilib, and finally
196  * build the Ada part of the toolset.
197  */
198 #if !(defined (VMS) || defined (__MINGW32__))
199 #include <sys/socket.h>
200 #include <netinet/in.h>
201 #include <netinet/tcp.h>
202 #include <sys/ioctl.h>
203 #include <netdb.h>
204 #endif
205
206 #if defined (_AIX) || defined (__FreeBSD__) || defined (__hpux__) || \
207     defined (__osf__) || defined (_WIN32) || defined (__APPLE__)
208 # define HAVE_THREAD_SAFE_GETxxxBYyyy 1
209
210 #elif defined (sgi) || defined (linux) || defined (__GLIBC__) || \
211      (defined (sun) && defined (__SVR4) && !defined (__vxworks)) || \
212       defined(__rtems__)
213 # define HAVE_GETxxxBYyyy_R 1
214 #endif
215
216 /*
217  * Properties of the unerlying NetDB library:
218  *   Need_Netdb_Buffer __gnat_getXXXbyYYY expects a caller-supplied buffer
219  *   Need_Netdb_Lock   __gnat_getXXXbyYYY expects the caller to ensure
220  *                     mutual exclusion
221  *
222  * See "Handling of gethostbyname, gethostbyaddr, getservbyname and
223  * getservbyport" in socket.c for details.
224  */
225
226 #if defined (HAVE_GETxxxBYyyy_R)
227 # define Need_Netdb_Buffer 1
228 # define Need_Netdb_Lock 0
229
230 #else
231 # define Need_Netdb_Buffer 0
232 # if !defined (HAVE_THREAD_SAFE_GETxxxBYyyy)
233 #  define Need_Netdb_Lock 1
234 # else
235 #  define Need_Netdb_Lock 0
236 # endif
237 #endif
238
239 #if defined (__FreeBSD__) || defined (__vxworks) || defined(__rtems__)
240 # define Has_Sockaddr_Len 1
241 #else
242 # define Has_Sockaddr_Len 0
243 #endif
244
245 #if !(defined (__vxworks) || defined (_WIN32) || defined (__hpux__) || defined (VMS))
246 # define HAVE_INET_PTON
247 #endif
248
249 #endif /* defined(__nucleus__) */