Implemented msvcrt._mbspbrk.
[wine/wine-kai.git] / include / winsock.h
blobbd72b49cbfd5b8033eb6ff2dc0868dfd14871c76
1 /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
3 * This header file corresponds to version 1.1 of the Windows Sockets
4 * specification.
5 */
7 #ifndef _WINSOCKAPI_
8 #define _WINSOCKAPI_
10 #ifndef RC_INVOKED
11 #include <sys/types.h>
13 #ifndef __WINE__
14 #if defined(__svr4__) || defined(__NetBSD__) || defined(__FreeBSD__)
15 #ifndef HAVE_SYS_SOCKET_H
16 #define HAVE_SYS_SOCKET_H
17 #endif /* HAVE_SYS_SOCKET_H */
18 #endif /* __svr4__ || __NetBSD__ || __FreeBSD__ */
19 #endif /* __WINE__ */
21 /* Solaris uses these macro names */
22 #undef FSHIFT
23 #undef TRANSPARENT
24 #include <netinet/in.h>
25 /* Restore the Windows values */
26 #ifdef _WINUSER_
27 #undef FSHIFT
28 #define FSHIFT 0x04
29 #endif
30 #ifdef _WINGDI_
31 #undef TRANSPARENT
32 #define TRANSPARENT 1
33 #endif
35 #ifdef HAVE_ARPA_INET_H
36 #include <arpa/inet.h>
37 #endif /* HAVE_ARPA_INET_H */
38 #include <sys/time.h>
39 #include <fcntl.h>
40 #ifdef HAVE_NETDB_H
41 #include <netdb.h>
42 #endif /* HAVE_NETDB_H */
43 #ifdef HAVE_SYS_SOCKET_H
44 #include <sys/socket.h>
45 #endif /* HAVE_SYS_SOCKET_H */
46 #include <sys/ioctl.h>
47 #endif /* RC_INVOKED */
49 #include "windef.h"
51 #ifdef __cplusplus
52 extern "C" {
53 #endif /* defined(__cplusplus) */
55 /* no "forced" alignment of ws_XXXXent here ! */
57 typedef struct ws_hostent
59 char *h_name; /* official name of host */
60 char **h_aliases; /* alias list */
61 short h_addrtype; /* host address type */
62 short h_length; /* length of address */
63 char **h_addr_list; /* list of addresses from name server */
64 } _ws_hostent;
66 typedef struct ws_protoent
68 char *p_name; /* official protocol name */
69 char **p_aliases; /* alias list */
70 short p_proto; /* protocol # */
71 } _ws_protoent;
73 typedef struct ws_servent
75 char *s_name; /* official service name */
76 char **s_aliases; /* alias list */
77 short s_port; /* port # */
78 char *s_proto; /* protocol to use */
79 } _ws_servent;
81 typedef struct ws_netent
83 char *n_name; /* official name of net */
84 char **n_aliases; /* alias list */
85 short n_addrtype; /* net address type */
86 u_long n_net; /* network # */
87 } _ws_netent;
89 #include "pshpack1.h"
91 typedef UINT SOCKET;
93 typedef struct sockaddr ws_sockaddr;
95 typedef struct ws_fd_set32_struct
97 UINT fd_count; /* how many are SET? */
98 SOCKET fd_array[FD_SETSIZE]; /* an array of SOCKETs */
99 } ws_fd_set32;
102 /* ws_fd_set operations */
104 INT WINAPI __WSAFDIsSet( SOCKET, ws_fd_set32 * );
106 #define __WS_FD_CLR(fd, set, cast) do { \
107 UINT __i; \
108 for (__i = 0; __i < ((cast*)(set))->fd_count ; __i++) \
110 if (((cast*)(set))->fd_array[__i] == fd) \
112 while (__i < ((cast*)(set))->fd_count-1) \
114 ((cast*)(set))->fd_array[__i] = \
115 ((cast*)(set))->fd_array[__i+1]; \
116 __i++; \
118 ((cast*)(set))->fd_count--; \
119 break; \
122 } while(0)
123 #define WS_FD_CLR(fd, set) __WS_FD_CLR((fd),(set), ws_fd_set32)
125 #define __WS_FD_SET(fd, set, cast) do { \
126 if (((cast*)(set))->fd_count < FD_SETSIZE) \
127 ((cast*)(set))->fd_array[((cast*)(set))->fd_count++]=(fd);\
128 } while(0)
129 #define WS_FD_SET(fd, set) __WS_FD_SET((fd),(set), ws_fd_set32)
130 #define WS_FD_ZERO(set) (((ws_fd_set32*)(set))->fd_count=0)
131 #define WS_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (ws_fd_set32*)(set))
134 * Internet address (old style... should be updated)
137 struct ws_in_addr
139 union {
140 struct { BYTE s_b1,s_b2,s_b3,s_b4; } S_un_b;
141 struct { WORD s_w1,s_w2; } S_un_w;
142 UINT S_addr;
143 } S_un;
144 #define ws_addr S_un.S_addr /* can be used for most tcp & ip code */
145 #define ws_host S_un.S_un_b.s_b2 /* host on imp */
146 #define ws_net S_un.S_un_b.s_b1 /* network */
147 #define ws_imp S_un.S_un_w.s_w2 /* imp */
148 #define ws_impno S_un.S_un_b.s_b4 /* imp # */
149 #define ws_lh S_un.S_un_b.s_b3 /* logical host */
152 struct ws_sockaddr_in
154 SHORT sin_family;
155 WORD sin_port;
156 struct ws_in_addr sin_addr;
157 BYTE sin_zero[8];
160 #define WSADESCRIPTION_LEN 256
161 #define WSASYS_STATUS_LEN 128
163 typedef struct WSAData {
164 WORD wVersion;
165 WORD wHighVersion;
166 char szDescription[WSADESCRIPTION_LEN+1];
167 char szSystemStatus[WSASYS_STATUS_LEN+1];
168 WORD iMaxSockets;
169 WORD iMaxUdpDg;
170 char *lpVendorInfo;
171 } WSADATA, *LPWSADATA;
173 #include "poppack.h"
176 * This is used instead of -1, since the
177 * SOCKET type is unsigned.
179 #define INVALID_SOCKET (~0)
180 #define SOCKET_ERROR (-1)
184 * Types
186 #define WS_SOCK_STREAM 1 /* stream socket */
187 #define WS_SOCK_DGRAM 2 /* datagram socket */
188 #define WS_SOCK_RAW 3 /* raw-protocol interface */
189 #define WS_SOCK_RDM 4 /* reliably-delivered message */
190 #define WS_SOCK_SEQPACKET 5 /* sequenced packet stream */
192 #define WS_SOL_SOCKET 0xffff
193 #define WS_IPPROTO_TCP 6
196 * Option flags per-socket.
198 #define WS_SO_DEBUG 0x0001 /* turn on debugging info recording */
199 #define WS_SO_ACCEPTCONN 0x0002 /* socket has had listen() */
200 #define WS_SO_REUSEADDR 0x0004 /* allow local address reuse */
201 #define WS_SO_KEEPALIVE 0x0008 /* keep connections alive */
202 #define WS_SO_DONTROUTE 0x0010 /* just use interface addresses */
203 #define WS_SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
204 #define WS_SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
205 #define WS_SO_LINGER 0x0080 /* linger on close if data present */
206 #define WS_SO_OOBINLINE 0x0100 /* leave received OOB data in line */
208 #define WS_SO_DONTLINGER (UINT)(~WS_SO_LINGER)
211 * Additional options.
213 #define WS_SO_SNDBUF 0x1001 /* send buffer size */
214 #define WS_SO_RCVBUF 0x1002 /* receive buffer size */
215 #define WS_SO_SNDLOWAT 0x1003 /* send low-water mark */
216 #define WS_SO_RCVLOWAT 0x1004 /* receive low-water mark */
217 #define WS_SO_SNDTIMEO 0x1005 /* send timeout */
218 #define WS_SO_RCVTIMEO 0x1006 /* receive timeout */
219 #define WS_SO_ERROR 0x1007 /* get error status and clear */
220 #define WS_SO_TYPE 0x1008 /* get socket type */
222 #define WS_IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
223 #define WS_IOC_VOID 0x20000000 /* no parameters */
224 #define WS_IOC_OUT 0x40000000 /* copy out parameters */
225 #define WS_IOC_IN 0x80000000 /* copy in parameters */
226 #define WS_IOC_INOUT (WS_IOC_IN|WS_IOC_OUT)
227 #define WS_IOR(x,y,t) (WS_IOC_OUT|(((UINT)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
228 #define WS_IOW(x,y,t) (WS_IOC_IN|(((UINT)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
230 /* IPPROTO_TCP options */
231 #define WS_TCP_NODELAY 1 /* do not apply nagle algorithm */
234 * Socket I/O flags (supported by spec 1.1)
237 #define WS_FIONREAD WS_IOR('f', 127, u_long)
238 #define WS_FIONBIO WS_IOW('f', 126, u_long)
240 #define WS_SIOCATMARK WS_IOR('s', 7, u_long)
243 * Maximum queue length specifiable by listen.
245 #ifdef SOMAXCONN
246 #undef SOMAXCONN
247 #endif
248 #define SOMAXCONN 5
250 #ifndef MSG_DONTROUTE
251 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
252 #endif
253 #define MSG_MAXIOVLEN 16
255 #ifndef MSG_PARTIAL
256 #define MSG_PARTIAL 0x8000 /* partial send or recv (WSARecvEx) */
257 #endif
260 * Define constant based on rfc883, used by gethostbyxxxx() calls.
262 #define MAXGETHOSTSTRUCT 1024
265 * Define flags to be used with the WSAAsyncSelect() call.
267 #define FD_READ WS_FD_READ
268 #define FD_WRITE WS_FD_WRITE
269 #define FD_OOB WS_FD_OOB
270 #define FD_ACCEPT WS_FD_ACCEPT
271 #define FD_CONNECT WS_FD_CONNECT
272 #define FD_CLOSE WS_FD_CLOSE
273 #define WS_FD_READ 0x0001
274 #define WS_FD_WRITE 0x0002
275 #define WS_FD_OOB 0x0004
276 #define WS_FD_ACCEPT 0x0008
277 #define WS_FD_CONNECT 0x0010
278 #define WS_FD_CLOSE 0x0020
280 #define WS_FD_LISTENING 0x10000000 /* internal per-socket flags */
281 #define WS_FD_NONBLOCKING 0x20000000
282 #define WS_FD_CONNECTED 0x40000000
283 #define WS_FD_RAW 0x80000000
284 #define WS_FD_SERVEVENT 0x01000000
285 #define WS_FD_INTERNAL 0xFFFF0000
288 * All Windows Sockets error constants are biased by WSABASEERR from
289 * the "normal"
291 #define WSABASEERR 10000
293 * Windows Sockets definitions of regular Microsoft C error constants
295 #define WSAEINTR (WSABASEERR+4)
296 #define WSAEBADF (WSABASEERR+9)
297 #define WSAEACCES (WSABASEERR+13)
298 #define WSAEFAULT (WSABASEERR+14)
299 #define WSAEINVAL (WSABASEERR+22)
300 #define WSAEMFILE (WSABASEERR+24)
303 * Windows Sockets definitions of regular Berkeley error constants
305 #define WSAEWOULDBLOCK (WSABASEERR+35)
306 #define WSAEINPROGRESS (WSABASEERR+36)
307 #define WSAEALREADY (WSABASEERR+37)
308 #define WSAENOTSOCK (WSABASEERR+38)
309 #define WSAEDESTADDRREQ (WSABASEERR+39)
310 #define WSAEMSGSIZE (WSABASEERR+40)
311 #define WSAEPROTOTYPE (WSABASEERR+41)
312 #define WSAENOPROTOOPT (WSABASEERR+42)
313 #define WSAEPROTONOSUPPORT (WSABASEERR+43)
314 #define WSAESOCKTNOSUPPORT (WSABASEERR+44)
315 #define WSAEOPNOTSUPP (WSABASEERR+45)
316 #define WSAEPFNOSUPPORT (WSABASEERR+46)
317 #define WSAEAFNOSUPPORT (WSABASEERR+47)
318 #define WSAEADDRINUSE (WSABASEERR+48)
319 #define WSAEADDRNOTAVAIL (WSABASEERR+49)
320 #define WSAENETDOWN (WSABASEERR+50)
321 #define WSAENETUNREACH (WSABASEERR+51)
322 #define WSAENETRESET (WSABASEERR+52)
323 #define WSAECONNABORTED (WSABASEERR+53)
324 #define WSAECONNRESET (WSABASEERR+54)
325 #define WSAENOBUFS (WSABASEERR+55)
326 #define WSAEISCONN (WSABASEERR+56)
327 #define WSAENOTCONN (WSABASEERR+57)
328 #define WSAESHUTDOWN (WSABASEERR+58)
329 #define WSAETOOMANYREFS (WSABASEERR+59)
330 #define WSAETIMEDOUT (WSABASEERR+60)
331 #define WSAECONNREFUSED (WSABASEERR+61)
332 #define WSAELOOP (WSABASEERR+62)
333 #define WSAENAMETOOLONG (WSABASEERR+63)
334 #define WSAEHOSTDOWN (WSABASEERR+64)
335 #define WSAEHOSTUNREACH (WSABASEERR+65)
336 #define WSAENOTEMPTY (WSABASEERR+66)
337 #define WSAEPROCLIM (WSABASEERR+67)
338 #define WSAEUSERS (WSABASEERR+68)
339 #define WSAEDQUOT (WSABASEERR+69)
340 #define WSAESTALE (WSABASEERR+70)
341 #define WSAEREMOTE (WSABASEERR+71)
344 * Extended Windows Sockets error constant definitions
346 #define WSASYSNOTREADY (WSABASEERR+91)
347 #define WSAVERNOTSUPPORTED (WSABASEERR+92)
348 #define WSANOTINITIALISED (WSABASEERR+93)
351 * Error return codes from gethostbyname() and gethostbyaddr()
352 * (when using the resolver). Note that these errors are
353 * retrieved via WSAGetLastError() and must therefore follow
354 * the rules for avoiding clashes with error numbers from
355 * specific implementations or language run-time systems.
356 * For this reason the codes are based at WSABASEERR+1001.
357 * Note also that [WSA]NO_ADDRESS is defined only for
358 * compatibility purposes.
361 /* #define h_errno WSAGetLastError() */
363 /* Authoritative Answer: Host not found */
364 #define WSAHOST_NOT_FOUND (WSABASEERR+1001)
366 /* Non-Authoritative: Host not found, or SERVERFAIL */
367 #define WSATRY_AGAIN (WSABASEERR+1002)
369 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
370 #define WSANO_RECOVERY (WSABASEERR+1003)
372 /* Valid name, no data record of requested type */
373 #define WSANO_DATA (WSABASEERR+1004)
375 /* no address, look for MX record */
376 #define WSANO_ADDRESS WSANO_DATA
378 /* Socket function prototypes */
380 #ifdef __cplusplus
381 extern "C" {
382 #endif
384 /* Microsoft Windows Extension function prototypes */
386 int WINAPI closesocket(SOCKET s);
388 INT WINAPI WSAStartup(UINT wVersionRequired, LPWSADATA lpWSAData);
389 void WINAPI WSASetLastError(INT iError);
390 INT WINAPI WSACleanup(void);
391 INT WINAPI WSAGetLastError(void);
392 BOOL WINAPI WSAIsBlocking(void);
393 INT WINAPI WSACancelBlockingCall(void);
394 INT WINAPI WSAUnhookBlockingHook(void);
395 FARPROC WINAPI WSASetBlockingHook(FARPROC lpBlockFunc);
396 HANDLE WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name, LPCSTR proto,
397 LPSTR sbuf, INT buflen);
398 HANDLE WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
399 LPCSTR proto, LPSTR sbuf, INT buflen);
400 HANDLE WINAPI WSAAsyncGetProtoByName(HWND hWnd, UINT uMsg,
401 LPCSTR name, LPSTR sbuf, INT buflen);
402 HANDLE WINAPI WSAAsyncGetProtoByNumber(HWND hWnd, UINT uMsg,
403 INT number, LPSTR sbuf, INT buflen);
404 HANDLE WINAPI WSAAsyncGetHostByName(HWND hWnd, UINT uMsg,
405 LPCSTR name, LPSTR sbuf, INT buflen);
406 HANDLE WINAPI WSAAsyncGetHostByAddr(HWND hWnd, UINT uMsg, LPCSTR addr,
407 INT len, INT type, LPSTR sbuf, INT buflen);
408 INT WINAPI WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
409 INT WINAPI WSAAsyncSelect(SOCKET s, HWND hWnd, UINT uMsg, LONG lEvent);
410 INT WINAPI WSARecvEx(SOCKET s, char *buf, INT len, INT *flags);
413 * Address families
415 #define WS_AF_UNSPEC 0 /* unspecified */
416 #define WS_AF_UNIX 1 /* local to host (pipes, portals) */
417 #define WS_AF_INET 2 /* internetwork: UDP, TCP, etc. */
418 #define WS_AF_IMPLINK 3 /* arpanet imp addresses */
419 #define WS_AF_PUP 4 /* pup protocols: e.g. BSP */
420 #define WS_AF_CHAOS 5 /* mit CHAOS protocols */
421 #define WS_AF_NS 6 /* XEROX NS protocols */
422 #define WS_AF_IPX WS_AF_NS /* IPX protocols: IPX, SPX, etc. */
423 #define WS_AF_ISO 7 /* ISO protocols */
424 #define WS_AF_OSI AF_ISO /* OSI is ISO */
425 #define WS_AF_ECMA 8 /* european computer manufacturers */
426 #define WS_AF_DATAKIT 9 /* datakit protocols */
427 #define WS_AF_CCITT 10 /* CCITT protocols, X.25 etc */
428 #define WS_AF_SNA 11 /* IBM SNA */
429 #define WS_AF_DECnet 12 /* DECnet */
430 #define WS_AF_DLI 13 /* Direct data link interface */
431 #define WS_AF_LAT 14 /* LAT */
432 #define WS_AF_HYLINK 15 /* NSC Hyperchannel */
433 #define WS_AF_APPLETALK 16 /* AppleTalk */
434 #define WS_AF_NETBIOS 17 /* NetBios-style addresses */
435 #define WS_AF_VOICEVIEW 18 /* VoiceView */
436 #define WS_AF_FIREFOX 19 /* Protocols from Firefox */
437 #define WS_AF_UNKNOWN1 20 /* Somebody is using this! */
438 #define WS_AF_BAN 21 /* Banyan */
439 #define WS_AF_ATM 22 /* Native ATM Services */
440 #define WS_AF_INET6 23 /* Internetwork Version 6 */
441 #define WS_AF_CLUSTER 24 /* Microsoft Wolfpack */
442 #define WS_AF_12844 25 /* IEEE 1284.4 WG AF */
443 #define WS_AF_IRDA 26 /* IrDA */
445 #define WS_AF_MAX 27
447 #include "pshpack1.h"
449 struct ws_sockaddr_ipx
451 SHORT sipx_family;
452 UINT sipx_network;
453 CHAR sipx_node[6];
454 WORD sipx_port;
457 #include "poppack.h"
459 #ifdef __cplusplus
461 #endif
463 /* Microsoft Windows Extended data types */
464 typedef struct sockaddr SOCKADDR, *PSOCKADDR, *LPSOCKADDR;
465 typedef struct sockaddr_in SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN;
466 typedef struct linger LINGER, *PLINGER, *LPLINGER;
467 typedef struct in_addr IN_ADDR, *PIN_ADDR, *LPIN_ADDR;
468 typedef struct ws_fd_set32_struct FD_SET, *PFD_SET, *LPFD_SET;
469 typedef struct hostent HOSTENT, *PHOSTENT, *LPHOSTENT;
470 typedef struct servent SERVENT, *PSERVENT, *LPSERVENT;
471 typedef struct protoent PROTOENT, *PPROTOENT, *LPPROTOENT;
472 typedef struct timeval TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
475 * Windows message parameter composition and decomposition
476 * macros.
478 * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
479 * when constructing the response to a WSAAsyncGetXByY() routine.
481 #define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
483 * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
484 * when constructing the response to WSAAsyncSelect().
486 #define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
488 * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
489 * to extract the buffer length from the lParam in the response
490 * to a WSAGetXByY().
492 #define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
494 * WSAGETASYNCERROR is intended for use by the Windows Sockets application
495 * to extract the error code from the lParam in the response
496 * to a WSAGetXByY().
498 #define WSAGETASYNCERROR(lParam) HIWORD(lParam)
500 * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
501 * to extract the event code from the lParam in the response
502 * to a WSAAsyncSelect().
504 #define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
506 * WSAGETSELECTERROR is intended for use by the Windows Sockets application
507 * to extract the error code from the lParam in the response
508 * to a WSAAsyncSelect().
510 #define WSAGETSELECTERROR(lParam) HIWORD(lParam)
512 #ifdef __cplusplus
513 } /* extern "C" */
514 #endif /* defined(__cplusplus) */
516 #endif /* _WINSOCKAPI_ */