Release 940405
[wine] / include / winsock.h
1 /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
2  *
3  * This header file corresponds to version 1.1 of the Windows Sockets
4  * specification.
5  */
6
7 #ifndef _WINSOCKAPI_
8 #define _WINSOCKAPI_
9
10 #include <windows.h>
11 #include <sys/types.h>
12 #include <sys/time.h>
13 #include <fcntl.h>
14 #include <netdb.h>
15 #include <netinet/in.h>
16 #include <sys/socket.h>
17
18 /*
19  * The new type to be used in all
20  * instances which refer to sockets.
21  */
22 typedef u_int   SOCKET;
23
24 extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
25
26 /*
27  * Internet address (old style... should be updated)
28  */
29 #define s_addr  S_un.S_addr     /* can be used for most tcp & ip code */
30 #define s_host  S_un.S_un_b.s_b2        /* host on imp */
31 #define s_net   S_un.S_un_b.s_b1        /* network */
32 #define s_imp   S_un.S_un_w.s_w2        /* imp */
33 #define s_impno S_un.S_un_b.s_b4        /* imp # */
34 #define s_lh    S_un.S_un_b.s_b3        /* logical host */
35
36 #define WSADESCRIPTION_LEN      256
37 #define WSASYS_STATUS_LEN       128
38
39 typedef struct WSAData {
40         WORD                    wVersion;
41         WORD                    wHighVersion;
42         char                    szDescription[WSADESCRIPTION_LEN+1];
43         char                    szSystemStatus[WSASYS_STATUS_LEN+1];
44         unsigned short          iMaxSockets;
45         unsigned short          iMaxUdpDg;
46         char FAR *              lpVendorInfo;
47 } WSADATA;
48
49 typedef WSADATA FAR *LPWSADATA;
50
51 /*
52  * This is used instead of -1, since the
53  * SOCKET type is unsigned.
54  */
55 #define INVALID_SOCKET  (SOCKET)(~0)
56 #define SOCKET_ERROR            (-1)
57
58 /*
59  * Option flags per-socket.
60  */
61 #ifndef SO_DONTLINGER
62 #define SO_DONTLINGER   (u_int)(~SO_LINGER)
63 #endif
64
65 #ifndef _SYS_SOCKET_H_
66 #ifndef _sys_socket_h
67 /*
68  * Structure used by kernel to pass protocol
69  * information in raw sockets.
70  */
71 struct sockproto {
72         u_short sp_family;              /* address family */
73         u_short sp_protocol;            /* protocol */
74 };
75 #endif
76 #endif
77
78 /*
79  * Maximum queue length specifiable by listen.
80  */
81 #define SOMAXCONN       5
82 #define MSG_DONTROUTE   0x4             /* send without using routing tables */
83 #define MSG_MAXIOVLEN   16
84
85 /*
86  * Define constant based on rfc883, used by gethostbyxxxx() calls.
87  */
88 #define MAXGETHOSTSTRUCT        1024
89
90 /*
91  * Define flags to be used with the WSAAsyncSelect() call.
92  */
93 #define FD_READ         0x01
94 #define FD_WRITE        0x02
95 #define FD_OOB          0x04
96 #define FD_ACCEPT       0x08
97 #define FD_CONNECT      0x10
98 #define FD_CLOSE        0x20
99
100 /*
101  * All Windows Sockets error constants are biased by WSABASEERR from
102  * the "normal"
103  */
104 #define WSABASEERR              10000
105 /*
106  * Windows Sockets definitions of regular Microsoft C error constants
107  */
108 #define WSAEINTR                (WSABASEERR+4)
109 #define WSAEBADF                (WSABASEERR+9)
110 #define WSAEACCES               (WSABASEERR+13)
111 #define WSAEFAULT               (WSABASEERR+14)
112 #define WSAEINVAL               (WSABASEERR+22)
113 #define WSAEMFILE               (WSABASEERR+24)
114
115 /*
116  * Windows Sockets definitions of regular Berkeley error constants
117  */
118 #define WSAEWOULDBLOCK          (WSABASEERR+35)
119 #define WSAEINPROGRESS          (WSABASEERR+36)
120 #define WSAEALREADY             (WSABASEERR+37)
121 #define WSAENOTSOCK             (WSABASEERR+38)
122 #define WSAEDESTADDRREQ         (WSABASEERR+39)
123 #define WSAEMSGSIZE             (WSABASEERR+40)
124 #define WSAEPROTOTYPE           (WSABASEERR+41)
125 #define WSAENOPROTOOPT          (WSABASEERR+42)
126 #define WSAEPROTONOSUPPORT      (WSABASEERR+43)
127 #define WSAESOCKTNOSUPPORT      (WSABASEERR+44)
128 #define WSAEOPNOTSUPP           (WSABASEERR+45)
129 #define WSAEPFNOSUPPORT         (WSABASEERR+46)
130 #define WSAEAFNOSUPPORT         (WSABASEERR+47)
131 #define WSAEADDRINUSE           (WSABASEERR+48)
132 #define WSAEADDRNOTAVAIL        (WSABASEERR+49)
133 #define WSAENETDOWN             (WSABASEERR+50)
134 #define WSAENETUNREACH          (WSABASEERR+51)
135 #define WSAENETRESET            (WSABASEERR+52)
136 #define WSAECONNABORTED         (WSABASEERR+53)
137 #define WSAECONNRESET           (WSABASEERR+54)
138 #define WSAENOBUFS              (WSABASEERR+55)
139 #define WSAEISCONN              (WSABASEERR+56)
140 #define WSAENOTCONN             (WSABASEERR+57)
141 #define WSAESHUTDOWN            (WSABASEERR+58)
142 #define WSAETOOMANYREFS         (WSABASEERR+59)
143 #define WSAETIMEDOUT            (WSABASEERR+60)
144 #define WSAECONNREFUSED         (WSABASEERR+61)
145 #define WSAELOOP                (WSABASEERR+62)
146 #define WSAENAMETOOLONG         (WSABASEERR+63)
147 #define WSAEHOSTDOWN            (WSABASEERR+64)
148 #define WSAEHOSTUNREACH         (WSABASEERR+65)
149 #define WSAENOTEMPTY            (WSABASEERR+66)
150 #define WSAEPROCLIM             (WSABASEERR+67)
151 #define WSAEUSERS               (WSABASEERR+68)
152 #define WSAEDQUOT               (WSABASEERR+69)
153 #define WSAESTALE               (WSABASEERR+70)
154 #define WSAEREMOTE              (WSABASEERR+71)
155
156 /*
157  * Extended Windows Sockets error constant definitions
158  */
159 #define WSASYSNOTREADY          (WSABASEERR+91)
160 #define WSAVERNOTSUPPORTED      (WSABASEERR+92)
161 #define WSANOTINITIALISED       (WSABASEERR+93)
162
163 /*
164  * Error return codes from gethostbyname() and gethostbyaddr()
165  * (when using the resolver). Note that these errors are
166  * retrieved via WSAGetLastError() and must therefore follow
167  * the rules for avoiding clashes with error numbers from
168  * specific implementations or language run-time systems.
169  * For this reason the codes are based at WSABASEERR+1001.
170  * Note also that [WSA]NO_ADDRESS is defined only for
171  * compatibility purposes.
172  */
173
174 #define h_errno         WSAGetLastError()
175
176 /* Authoritative Answer: Host not found */
177 #define WSAHOST_NOT_FOUND       (WSABASEERR+1001)
178
179 /* Non-Authoritative: Host not found, or SERVERFAIL */
180 #define WSATRY_AGAIN            (WSABASEERR+1002)
181
182 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
183 #define WSANO_RECOVERY          (WSABASEERR+1003)
184
185 /* Valid name, no data record of requested type */
186 #define WSANO_DATA              (WSABASEERR+1004)
187
188 /* no address, look for MX record */
189 #define WSANO_ADDRESS           WSANO_DATA
190
191 /*
192  * Windows Sockets errors redefined as regular Berkeley error constants
193
194         * AAARGH! *
195
196 #define EWOULDBLOCK             WSAEWOULDBLOCK
197 #define EINPROGRESS             WSAEINPROGRESS
198 #define EALREADY                WSAEALREADY
199 #define ENOTSOCK                WSAENOTSOCK
200 #define EDESTADDRREQ            WSAEDESTADDRREQ
201 #define EMSGSIZE                WSAEMSGSIZE
202 #define EPROTOTYPE              WSAEPROTOTYPE
203 #define ENOPROTOOPT             WSAENOPROTOOPT
204 #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
205 #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
206 #define EOPNOTSUPP              WSAEOPNOTSUPP
207 #define EPFNOSUPPORT            WSAEPFNOSUPPORT
208 #define EAFNOSUPPORT            WSAEAFNOSUPPORT
209 #define EADDRINUSE              WSAEADDRINUSE
210 #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
211 #define ENETDOWN                WSAENETDOWN
212 #define ENETUNREACH             WSAENETUNREACH
213 #define ENETRESET               WSAENETRESET
214 #define ECONNABORTED            WSAECONNABORTED
215 #define ECONNRESET              WSAECONNRESET
216 #define ENOBUFS                 WSAENOBUFS
217 #define EISCONN                 WSAEISCONN
218 #define ENOTCONN                WSAENOTCONN
219 #define ESHUTDOWN               WSAESHUTDOWN
220 #define ETOOMANYREFS            WSAETOOMANYREFS
221 #define ETIMEDOUT               WSAETIMEDOUT
222 #define ECONNREFUSED            WSAECONNREFUSED
223 #define ELOOP                   WSAELOOP
224 #define ENAMETOOLONG            WSAENAMETOOLONG
225 #define EHOSTDOWN               WSAEHOSTDOWN
226 #define EHOSTUNREACH            WSAEHOSTUNREACH
227 #define ENOTEMPTY               WSAENOTEMPTY
228 #define EPROCLIM                WSAEPROCLIM
229 #define EUSERS                  WSAEUSERS
230 #define EDQUOT                  WSAEDQUOT
231 #define ESTALE                  WSAESTALE
232 #define EREMOTE                 WSAEREMOTE
233
234 */
235
236 /* Socket function prototypes */
237
238 #ifdef __cplusplus
239 extern "C" {
240 #endif
241
242 /* Microsoft Windows Extension function prototypes */
243
244 int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
245
246 int PASCAL FAR WSACleanup(void);
247
248 void PASCAL FAR WSASetLastError(int iError);
249
250 int PASCAL FAR WSAGetLastError(void);
251
252 BOOL PASCAL FAR WSAIsBlocking(void);
253
254 int PASCAL FAR WSAUnhookBlockingHook(void);
255
256 FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc);
257
258 int PASCAL FAR WSACancelBlockingCall(void);
259
260 HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
261                                         const char FAR * name, 
262                                         const char FAR * proto,
263                                         char FAR * buf, int buflen);
264
265 HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
266                                         const char FAR * proto, char FAR * buf,
267                                         int buflen);
268
269 HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
270                                          const char FAR * name, char FAR * buf,
271                                          int buflen);
272
273 HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
274                                            int number, char FAR * buf,
275                                            int buflen);
276
277 HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
278                                         const char FAR * name, char FAR * buf,
279                                         int buflen);
280
281 HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
282                                         const char FAR * addr, int len, int type,
283                                         const char FAR * buf, int buflen);
284
285 int PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
286
287 int PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
288                                long lEvent);
289
290 #ifdef __cplusplus
291 }
292 #endif
293
294 /* Microsoft Windows Extended data types */
295 typedef struct sockaddr SOCKADDR;
296 typedef struct sockaddr *PSOCKADDR;
297 typedef struct sockaddr FAR *LPSOCKADDR;
298
299 typedef struct sockaddr_in SOCKADDR_IN;
300 typedef struct sockaddr_in *PSOCKADDR_IN;
301 typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
302
303 typedef struct linger LINGER;
304 typedef struct linger *PLINGER;
305 typedef struct linger FAR *LPLINGER;
306
307 typedef struct in_addr IN_ADDR;
308 typedef struct in_addr *PIN_ADDR;
309 typedef struct in_addr FAR *LPIN_ADDR;
310
311 typedef struct fd_set FD_SET;
312 typedef struct fd_set *PFD_SET;
313 typedef struct fd_set FAR *LPFD_SET;
314
315 typedef struct hostent HOSTENT;
316 typedef struct hostent *PHOSTENT;
317 typedef struct hostent FAR *LPHOSTENT;
318
319 typedef struct servent SERVENT;
320 typedef struct servent *PSERVENT;
321 typedef struct servent FAR *LPSERVENT;
322
323 typedef struct protoent PROTOENT;
324 typedef struct protoent *PPROTOENT;
325 typedef struct protoent FAR *LPPROTOENT;
326
327 typedef struct timeval TIMEVAL;
328 typedef struct timeval *PTIMEVAL;
329 typedef struct timeval FAR *LPTIMEVAL;
330
331 /*
332  * Windows message parameter composition and decomposition
333  * macros.
334  *
335  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
336  * when constructing the response to a WSAAsyncGetXByY() routine.
337  */
338 #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error)
339 /*
340  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
341  * when constructing the response to WSAAsyncSelect().
342  */
343 #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error)
344 /*
345  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
346  * to extract the buffer length from the lParam in the response
347  * to a WSAGetXByY().
348  */
349 #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
350 /*
351  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
352  * to extract the error code from the lParam in the response
353  * to a WSAGetXByY().
354  */
355 #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
356 /*
357  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
358  * to extract the event code from the lParam in the response
359  * to a WSAAsyncSelect().
360  */
361 #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
362 /*
363  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
364  * to extract the error code from the lParam in the response
365  * to a WSAAsyncSelect().
366  */
367 #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
368
369 #endif  /* _WINSOCKAPI_ */