Release 950319
[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
83 #ifndef MSG_DONTROUTE
84 #define MSG_DONTROUTE   0x4             /* send without using routing tables */
85 #endif
86 #define MSG_MAXIOVLEN   16
87
88 /*
89  * Define constant based on rfc883, used by gethostbyxxxx() calls.
90  */
91 #define MAXGETHOSTSTRUCT        1024
92
93 /*
94  * Define flags to be used with the WSAAsyncSelect() call.
95  */
96 #define FD_READ         0x01
97 #define FD_WRITE        0x02
98 #define FD_OOB          0x04
99 #define FD_ACCEPT       0x08
100 #define FD_CONNECT      0x10
101 #define FD_CLOSE        0x20
102
103 /*
104  * All Windows Sockets error constants are biased by WSABASEERR from
105  * the "normal"
106  */
107 #define WSABASEERR              10000
108 /*
109  * Windows Sockets definitions of regular Microsoft C error constants
110  */
111 #define WSAEINTR                (WSABASEERR+4)
112 #define WSAEBADF                (WSABASEERR+9)
113 #define WSAEACCES               (WSABASEERR+13)
114 #define WSAEFAULT               (WSABASEERR+14)
115 #define WSAEINVAL               (WSABASEERR+22)
116 #define WSAEMFILE               (WSABASEERR+24)
117
118 /*
119  * Windows Sockets definitions of regular Berkeley error constants
120  */
121 #define WSAEWOULDBLOCK          (WSABASEERR+35)
122 #define WSAEINPROGRESS          (WSABASEERR+36)
123 #define WSAEALREADY             (WSABASEERR+37)
124 #define WSAENOTSOCK             (WSABASEERR+38)
125 #define WSAEDESTADDRREQ         (WSABASEERR+39)
126 #define WSAEMSGSIZE             (WSABASEERR+40)
127 #define WSAEPROTOTYPE           (WSABASEERR+41)
128 #define WSAENOPROTOOPT          (WSABASEERR+42)
129 #define WSAEPROTONOSUPPORT      (WSABASEERR+43)
130 #define WSAESOCKTNOSUPPORT      (WSABASEERR+44)
131 #define WSAEOPNOTSUPP           (WSABASEERR+45)
132 #define WSAEPFNOSUPPORT         (WSABASEERR+46)
133 #define WSAEAFNOSUPPORT         (WSABASEERR+47)
134 #define WSAEADDRINUSE           (WSABASEERR+48)
135 #define WSAEADDRNOTAVAIL        (WSABASEERR+49)
136 #define WSAENETDOWN             (WSABASEERR+50)
137 #define WSAENETUNREACH          (WSABASEERR+51)
138 #define WSAENETRESET            (WSABASEERR+52)
139 #define WSAECONNABORTED         (WSABASEERR+53)
140 #define WSAECONNRESET           (WSABASEERR+54)
141 #define WSAENOBUFS              (WSABASEERR+55)
142 #define WSAEISCONN              (WSABASEERR+56)
143 #define WSAENOTCONN             (WSABASEERR+57)
144 #define WSAESHUTDOWN            (WSABASEERR+58)
145 #define WSAETOOMANYREFS         (WSABASEERR+59)
146 #define WSAETIMEDOUT            (WSABASEERR+60)
147 #define WSAECONNREFUSED         (WSABASEERR+61)
148 #define WSAELOOP                (WSABASEERR+62)
149 #define WSAENAMETOOLONG         (WSABASEERR+63)
150 #define WSAEHOSTDOWN            (WSABASEERR+64)
151 #define WSAEHOSTUNREACH         (WSABASEERR+65)
152 #define WSAENOTEMPTY            (WSABASEERR+66)
153 #define WSAEPROCLIM             (WSABASEERR+67)
154 #define WSAEUSERS               (WSABASEERR+68)
155 #define WSAEDQUOT               (WSABASEERR+69)
156 #define WSAESTALE               (WSABASEERR+70)
157 #define WSAEREMOTE              (WSABASEERR+71)
158
159 /*
160  * Extended Windows Sockets error constant definitions
161  */
162 #define WSASYSNOTREADY          (WSABASEERR+91)
163 #define WSAVERNOTSUPPORTED      (WSABASEERR+92)
164 #define WSANOTINITIALISED       (WSABASEERR+93)
165
166 /*
167  * Error return codes from gethostbyname() and gethostbyaddr()
168  * (when using the resolver). Note that these errors are
169  * retrieved via WSAGetLastError() and must therefore follow
170  * the rules for avoiding clashes with error numbers from
171  * specific implementations or language run-time systems.
172  * For this reason the codes are based at WSABASEERR+1001.
173  * Note also that [WSA]NO_ADDRESS is defined only for
174  * compatibility purposes.
175  */
176
177 #define h_errno         WSAGetLastError()
178
179 /* Authoritative Answer: Host not found */
180 #define WSAHOST_NOT_FOUND       (WSABASEERR+1001)
181
182 /* Non-Authoritative: Host not found, or SERVERFAIL */
183 #define WSATRY_AGAIN            (WSABASEERR+1002)
184
185 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
186 #define WSANO_RECOVERY          (WSABASEERR+1003)
187
188 /* Valid name, no data record of requested type */
189 #define WSANO_DATA              (WSABASEERR+1004)
190
191 /* no address, look for MX record */
192 #define WSANO_ADDRESS           WSANO_DATA
193
194 /* Socket function prototypes */
195
196 #ifdef __cplusplus
197 extern "C" {
198 #endif
199
200 /* Microsoft Windows Extension function prototypes */
201
202 INT PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
203
204 INT PASCAL FAR WSACleanup(void);
205
206 void PASCAL FAR WSASetLastError(INT iError);
207
208 INT PASCAL FAR WSAGetLastError(void);
209
210 BOOL PASCAL FAR WSAIsBlocking(void);
211
212 INT PASCAL FAR WSAUnhookBlockingHook(void);
213
214 FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc);
215
216 INT PASCAL FAR WSACancelBlockingCall(void);
217
218 HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
219                                         const char FAR *name, 
220                                         const char FAR *proto,
221                                         char FAR *buf, INT buflen);
222
223 HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, INT port,
224                                         const char FAR *proto, char FAR *buf,
225                                         INT buflen);
226
227 HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
228                                          const char FAR *name, char FAR *buf,
229                                          INT buflen);
230
231 HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
232                                            INT number, char FAR *buf,
233                                            INT buflen);
234
235 HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
236                                         const char FAR *name, char FAR *buf,
237                                         INT buflen);
238
239 HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
240                                         const char FAR *addr, INT len, INT type,
241                                         char FAR *buf, INT buflen);
242
243 INT PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
244
245 INT PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg, long lEvent);
246
247 #ifdef __cplusplus
248 }
249 #endif
250
251 /* Microsoft Windows Extended data types */
252 typedef struct sockaddr SOCKADDR;
253 typedef struct sockaddr *PSOCKADDR;
254 typedef struct sockaddr FAR *LPSOCKADDR;
255
256 typedef struct sockaddr_in SOCKADDR_IN;
257 typedef struct sockaddr_in *PSOCKADDR_IN;
258 typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
259
260 typedef struct linger LINGER;
261 typedef struct linger *PLINGER;
262 typedef struct linger FAR *LPLINGER;
263
264 typedef struct in_addr IN_ADDR;
265 typedef struct in_addr *PIN_ADDR;
266 typedef struct in_addr FAR *LPIN_ADDR;
267
268 typedef struct fd_set FD_SET;
269 typedef struct fd_set *PFD_SET;
270 typedef struct fd_set FAR *LPFD_SET;
271
272 typedef struct hostent HOSTENT;
273 typedef struct hostent *PHOSTENT;
274 typedef struct hostent FAR *LPHOSTENT;
275
276 typedef struct servent SERVENT;
277 typedef struct servent *PSERVENT;
278 typedef struct servent FAR *LPSERVENT;
279
280 typedef struct protoent PROTOENT;
281 typedef struct protoent *PPROTOENT;
282 typedef struct protoent FAR *LPPROTOENT;
283
284 typedef struct timeval TIMEVAL;
285 typedef struct timeval *PTIMEVAL;
286 typedef struct timeval FAR *LPTIMEVAL;
287
288 /*
289  * Windows message parameter composition and decomposition
290  * macros.
291  *
292  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
293  * when constructing the response to a WSAAsyncGetXByY() routine.
294  */
295 #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error)
296 /*
297  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
298  * when constructing the response to WSAAsyncSelect().
299  */
300 #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error)
301 /*
302  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
303  * to extract the buffer length from the lParam in the response
304  * to a WSAGetXByY().
305  */
306 #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
307 /*
308  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
309  * to extract the error code from the lParam in the response
310  * to a WSAGetXByY().
311  */
312 #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
313 /*
314  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
315  * to extract the event code from the lParam in the response
316  * to a WSAAsyncSelect().
317  */
318 #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
319 /*
320  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
321  * to extract the error code from the lParam in the response
322  * to a WSAAsyncSelect().
323  */
324 #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
325
326 #endif  /* _WINSOCKAPI_ */