Release 971012
[wine/multimedia.git] / include / winsock.h
blob84187efaca9250a4e3a4e7ab8c9a5b28b43149cd
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 #include <netinet/in.h>
11 #include <arpa/inet.h>
12 #include <sys/types.h>
13 #include <sys/time.h>
14 #include <fcntl.h>
15 #include <netdb.h>
16 #include <sys/socket.h>
17 #include "windows.h"
19 #pragma pack(1)
21 /* Win16 socket-related types */
23 typedef UINT16 SOCKET16;
24 typedef UINT32 SOCKET32;
26 typedef struct ws_hostent
28 SEGPTR h_name; /* official name of host */
29 SEGPTR h_aliases; /* alias list */
30 INT16 h_addrtype; /* host address type */
31 INT16 h_length; /* length of address */
32 SEGPTR h_addr_list; /* list of addresses from name server */
33 } _ws_hostent;
35 typedef struct ws_protoent
37 SEGPTR p_name; /* official protocol name */
38 SEGPTR p_aliases; /* alias list */
39 INT16 p_proto; /* protocol # */
40 } _ws_protoent;
42 typedef struct ws_servent
44 SEGPTR s_name; /* official service name */
45 SEGPTR s_aliases; /* alias list */
46 INT16 s_port; /* port # */
47 SEGPTR s_proto; /* protocol to use */
48 } _ws_servent;
50 typedef struct ws_netent
52 SEGPTR n_name; /* official name of net */
53 SEGPTR n_aliases; /* alias list */
54 INT16 n_addrtype; /* net address type */
55 INT32 n_net; /* network # */
56 } _ws_netent;
58 typedef struct sockaddr ws_sockaddr;
60 typedef struct
62 UINT16 fd_count; /* how many are SET? */
63 SOCKET16 fd_array[FD_SETSIZE]; /* an array of SOCKETs */
64 } ws_fd_set;
66 /* ws_fd_set operations */
68 INT16 WINAPI __WSAFDIsSet16( SOCKET16, ws_fd_set * );
69 INT32 WINAPI __WSAFDIsSet32( SOCKET32, ws_fd_set * );
70 #define __WSAFDIsSet WINELIB_NAME(__WSAFDIsSet);
72 #define WS_FD_CLR(fd, set) do { \
73 UINT16 __i; \
74 for (__i = 0; __i < ((ws_fd_set*)(set))->fd_count ; __i++) \
75 { \
76 if (((ws_fd_set*)(set))->fd_array[__i] == fd) \
77 { \
78 while (__i < ((ws_fd_set*)(set))->fd_count-1) \
79 { \
80 ((ws_fd_set*)(set))->fd_array[__i] = \
81 ((ws_fd_set*)(set))->fd_array[__i+1]; \
82 __i++; \
83 } \
84 ((ws_fd_set*)(set))->fd_count--; \
85 break; \
86 } \
87 } \
88 } while(0)
90 #define WS_FD_SET(fd, set) do { \
91 if (((ws_fd_set*)(set))->fd_count < FD_SETSIZE) \
92 ((ws_fd_set*)(set))->fd_array[((ws_fd_set*)(set))->fd_count++]=(fd);\
93 } while(0)
95 #define WS_FD_ZERO(set) (((ws_fd_set*)(set))->fd_count=0)
97 #define WS_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET16)(fd), (ws_fd_set*)(set))
99 /*
100 * Internet address (old style... should be updated)
103 typedef struct ws_addr_in
105 union {
106 struct { BYTE s_b1,s_b2,s_b3,s_b4; } S_un_b;
107 struct { UINT16 s_w1,s_w2; } S_un_w;
108 UINT32 S_addr;
109 } S_un;
110 #define ws_addr S_un.S_addr /* can be used for most tcp & ip code */
111 #define ws_host S_un.S_un_b.s_b2 /* host on imp */
112 #define ws_net S_un.S_un_b.s_b1 /* network */
113 #define ws_imp S_un.S_un_w.s_w2 /* imp */
114 #define ws_impno S_un.S_un_b.s_b4 /* imp # */
115 #define ws_lh S_un.S_un_b.s_b3 /* logical host */
116 } _ws_in_addr;
118 typedef struct ws_sockaddr_in
120 INT16 sin_family;
121 UINT16 sin_port;
122 _ws_in_addr sin_addr;
123 char sin_zero[8];
124 } _ws_sockaddr_in;
126 #define WSADESCRIPTION_LEN 256
127 #define WSASYS_STATUS_LEN 128
129 typedef struct WSAData {
130 WORD wVersion;
131 WORD wHighVersion;
132 char szDescription[WSADESCRIPTION_LEN+1];
133 char szSystemStatus[WSASYS_STATUS_LEN+1];
134 UINT16 iMaxSockets;
135 UINT16 iMaxUdpDg;
136 SEGPTR lpVendorInfo;
137 } WSADATA, *LPWSADATA;
139 #pragma pack(4)
141 /* ----------------------------------- no Win16 structure defs beyond this line! */
144 * This is used instead of -1, since the
145 * SOCKET type is unsigned.
147 #define INVALID_SOCKET16 (~0)
148 #define INVALID_SOCKET32 (~0)
149 #define SOCKET_ERROR (-1)
151 DECL_WINELIB_TYPE(INVALID_SOCKET);
152 DECL_WINELIB_TYPE(SOCKET);
155 * Types
157 #define WS_SOCK_STREAM 1 /* stream socket */
158 #define WS_SOCK_DGRAM 2 /* datagram socket */
159 #define WS_SOCK_RAW 3 /* raw-protocol interface */
160 #define WS_SOCK_RDM 4 /* reliably-delivered message */
161 #define WS_SOCK_SEQPACKET 5 /* sequenced packet stream */
163 #define WS_SOL_SOCKET (-1)
164 #define WS_IPPROTO_TCP 6
167 * Option flags per-socket.
169 #define WS_SO_DEBUG 0x0001 /* turn on debugging info recording */
170 #define WS_SO_ACCEPTCONN 0x0002 /* socket has had listen() */
171 #define WS_SO_REUSEADDR 0x0004 /* allow local address reuse */
172 #define WS_SO_KEEPALIVE 0x0008 /* keep connections alive */
173 #define WS_SO_DONTROUTE 0x0010 /* just use interface addresses */
174 #define WS_SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
175 #define WS_SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
176 #define WS_SO_LINGER 0x0080 /* linger on close if data present */
177 #define WS_SO_OOBINLINE 0x0100 /* leave received OOB data in line */
179 #define WS_SO_DONTLINGER (UINT32)(~WS_SO_LINGER)
182 * Additional options.
184 #define WS_SO_SNDBUF 0x1001 /* send buffer size */
185 #define WS_SO_RCVBUF 0x1002 /* receive buffer size */
186 #define WS_SO_SNDLOWAT 0x1003 /* send low-water mark */
187 #define WS_SO_RCVLOWAT 0x1004 /* receive low-water mark */
188 #define WS_SO_SNDTIMEO 0x1005 /* send timeout */
189 #define WS_SO_RCVTIMEO 0x1006 /* receive timeout */
190 #define WS_SO_ERROR 0x1007 /* get error status and clear */
191 #define WS_SO_TYPE 0x1008 /* get socket type */
193 #define WS_IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
194 #define WS_IOC_VOID 0x20000000 /* no parameters */
195 #define WS_IOC_OUT 0x40000000 /* copy out parameters */
196 #define WS_IOC_IN 0x80000000 /* copy in parameters */
197 #define WS_IOC_INOUT (WS_IOC_IN|WS_IOC_OUT)
198 #define WS_IOR(x,y,t) (WS_IOC_OUT|(((UINT32)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
199 #define WS_IOW(x,y,t) (WS_IOC_IN|(((UINT32)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
202 * Socket I/O flags (supported by spec 1.1)
205 #define WS_FIONREAD WS_IOR('f', 127, u_long)
206 #define WS_FIONBIO WS_IOW('f', 126, u_long)
208 #define WS_SIOCATMARK WS_IOR('s', 7, u_long)
211 * Maximum queue length specifiable by listen.
213 #ifdef SOMAXCONN
214 #undef SOMAXCONN
215 #endif
216 #define SOMAXCONN 5
218 #ifndef MSG_DONTROUTE
219 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
220 #endif
221 #define MSG_MAXIOVLEN 16
224 * Define constant based on rfc883, used by gethostbyxxxx() calls.
226 #define MAXGETHOSTSTRUCT 1024
229 * Define flags to be used with the WSAAsyncSelect() call.
231 #define WS_FD_READ 0x0001
232 #define WS_FD_WRITE 0x0002
233 #define WS_FD_OOB 0x0004
234 #define WS_FD_ACCEPT 0x0008
235 #define WS_FD_CONNECT 0x0010
236 #define WS_FD_CLOSE 0x0020
238 #define WS_FD_LISTENING 0x10000000 /* internal per-socket flags */
239 #define WS_FD_INACTIVE 0x20000000
240 #define WS_FD_CONNECTED 0x40000000
241 #define WS_FD_RAW 0x80000000
242 #define WS_FD_INTERNAL 0xFFFF0000
245 * All Windows Sockets error constants are biased by WSABASEERR from
246 * the "normal"
248 #define WSABASEERR 10000
250 * Windows Sockets definitions of regular Microsoft C error constants
252 #define WSAEINTR (WSABASEERR+4)
253 #define WSAEBADF (WSABASEERR+9)
254 #define WSAEACCES (WSABASEERR+13)
255 #define WSAEFAULT (WSABASEERR+14)
256 #define WSAEINVAL (WSABASEERR+22)
257 #define WSAEMFILE (WSABASEERR+24)
260 * Windows Sockets definitions of regular Berkeley error constants
262 #define WSAEWOULDBLOCK (WSABASEERR+35)
263 #define WSAEINPROGRESS (WSABASEERR+36)
264 #define WSAEALREADY (WSABASEERR+37)
265 #define WSAENOTSOCK (WSABASEERR+38)
266 #define WSAEDESTADDRREQ (WSABASEERR+39)
267 #define WSAEMSGSIZE (WSABASEERR+40)
268 #define WSAEPROTOTYPE (WSABASEERR+41)
269 #define WSAENOPROTOOPT (WSABASEERR+42)
270 #define WSAEPROTONOSUPPORT (WSABASEERR+43)
271 #define WSAESOCKTNOSUPPORT (WSABASEERR+44)
272 #define WSAEOPNOTSUPP (WSABASEERR+45)
273 #define WSAEPFNOSUPPORT (WSABASEERR+46)
274 #define WSAEAFNOSUPPORT (WSABASEERR+47)
275 #define WSAEADDRINUSE (WSABASEERR+48)
276 #define WSAEADDRNOTAVAIL (WSABASEERR+49)
277 #define WSAENETDOWN (WSABASEERR+50)
278 #define WSAENETUNREACH (WSABASEERR+51)
279 #define WSAENETRESET (WSABASEERR+52)
280 #define WSAECONNABORTED (WSABASEERR+53)
281 #define WSAECONNRESET (WSABASEERR+54)
282 #define WSAENOBUFS (WSABASEERR+55)
283 #define WSAEISCONN (WSABASEERR+56)
284 #define WSAENOTCONN (WSABASEERR+57)
285 #define WSAESHUTDOWN (WSABASEERR+58)
286 #define WSAETOOMANYREFS (WSABASEERR+59)
287 #define WSAETIMEDOUT (WSABASEERR+60)
288 #define WSAECONNREFUSED (WSABASEERR+61)
289 #define WSAELOOP (WSABASEERR+62)
290 #define WSAENAMETOOLONG (WSABASEERR+63)
291 #define WSAEHOSTDOWN (WSABASEERR+64)
292 #define WSAEHOSTUNREACH (WSABASEERR+65)
293 #define WSAENOTEMPTY (WSABASEERR+66)
294 #define WSAEPROCLIM (WSABASEERR+67)
295 #define WSAEUSERS (WSABASEERR+68)
296 #define WSAEDQUOT (WSABASEERR+69)
297 #define WSAESTALE (WSABASEERR+70)
298 #define WSAEREMOTE (WSABASEERR+71)
301 * Extended Windows Sockets error constant definitions
303 #define WSASYSNOTREADY (WSABASEERR+91)
304 #define WSAVERNOTSUPPORTED (WSABASEERR+92)
305 #define WSANOTINITIALISED (WSABASEERR+93)
308 * Error return codes from gethostbyname() and gethostbyaddr()
309 * (when using the resolver). Note that these errors are
310 * retrieved via WSAGetLastError() and must therefore follow
311 * the rules for avoiding clashes with error numbers from
312 * specific implementations or language run-time systems.
313 * For this reason the codes are based at WSABASEERR+1001.
314 * Note also that [WSA]NO_ADDRESS is defined only for
315 * compatibility purposes.
318 /* #define h_errno WSAGetLastError() */
320 /* Authoritative Answer: Host not found */
321 #define WSAHOST_NOT_FOUND (WSABASEERR+1001)
323 /* Non-Authoritative: Host not found, or SERVERFAIL */
324 #define WSATRY_AGAIN (WSABASEERR+1002)
326 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
327 #define WSANO_RECOVERY (WSABASEERR+1003)
329 /* Valid name, no data record of requested type */
330 #define WSANO_DATA (WSABASEERR+1004)
332 /* no address, look for MX record */
333 #define WSANO_ADDRESS WSANO_DATA
335 /* Socket function prototypes */
337 #ifdef __cplusplus
338 extern "C" {
339 #endif
341 /* Microsoft Windows Extension function prototypes */
343 INT16 WINAPI WSAStartup16(UINT16 wVersionRequired, LPWSADATA lpWSAData);
344 INT32 WINAPI WSAStartup32(UINT32 wVersionRequired, LPWSADATA lpWSAData);
345 #define WSAStartup WINELIB_NAME(WSAStartup);
346 void WINAPI WSASetLastError16(INT16 iError);
347 void WINAPI WSASetLastError32(INT32 iError);
348 #define WSASetLastError WINELIB_NAME(WSASetLastError);
349 INT32 WINAPI WSACleanup(void);
350 INT32 WINAPI WSAGetLastError(void);
351 BOOL32 WINAPI WSAIsBlocking(void);
352 INT32 WINAPI WSACancelBlockingCall(void);
353 INT16 WINAPI WSAUnhookBlockingHook16(void);
354 INT32 WINAPI WSAUnhookBlockingHook32(void);
355 #define WSAUnhookBlockingHook WINELIB_NAME(WSAUnhookBlockingHook)
356 FARPROC16 WINAPI WSASetBlockingHook16(FARPROC16 lpBlockFunc);
357 FARPROC32 WINAPI WSASetBlockingHook32(FARPROC32 lpBlockFunc);
358 #define WSASetBlockingHook WINELIB_NAME(WSASetBlockingHook)
359 HANDLE16 WINAPI WSAAsyncGetServByName(HWND16 hWnd, UINT16 wMsg,
360 LPCSTR name, LPCSTR proto,
361 SEGPTR buf, INT16 buflen);
363 HANDLE16 WINAPI WSAAsyncGetServByPort(HWND16 hWnd, UINT16 wMsg, INT16 port,
364 LPCSTR proto, SEGPTR buf, INT16 buflen);
366 HANDLE16 WINAPI WSAAsyncGetProtoByName(HWND16 hWnd, UINT16 wMsg,
367 LPCSTR name, SEGPTR buf, INT16 buflen);
369 HANDLE16 WINAPI WSAAsyncGetProtoByNumber(HWND16 hWnd, UINT16 wMsg,
370 INT16 number, SEGPTR buf, INT16 buflen);
372 HANDLE16 WINAPI WSAAsyncGetHostByName(HWND16 hWnd, UINT16 wMsg,
373 LPCSTR name, SEGPTR buf, INT16 buflen);
375 HANDLE16 WINAPI WSAAsyncGetHostByAddr(HWND16 hWnd, UINT16 wMsg, LPCSTR addr,
376 INT16 len, INT16 type, SEGPTR buf, INT16 buflen);
377 INT16 WINAPI WSACancelAsyncRequest(HANDLE16 hAsyncTaskHandle);
378 INT16 WINAPI WSAAsyncSelect(SOCKET16 s, HWND16 hWnd, UINT16 wMsg,
379 UINT32 lEvent);
381 #ifdef __cplusplus
383 #endif
385 /* Microsoft Windows Extended data types */
386 typedef struct sockaddr SOCKADDR, *PSOCKADDR, *LPSOCKADDR;
387 typedef struct sockaddr_in SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN;
388 typedef struct linger LINGER, *PLINGER, *LPLINGER;
389 typedef struct in_addr IN_ADDR, *PIN_ADDR, *LPIN_ADDR;
390 typedef struct fd_set FD_SET, *PFD_SET, *LPFD_SET;
391 typedef struct hostent HOSTENT, *PHOSTENT, *LPHOSTENT;
392 typedef struct servent SERVENT, *PSERVENT, *LPSERVENT;
393 typedef struct protoent PROTOENT, *PPROTOENT, *LPPROTOENT;
394 typedef struct timeval TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
397 * Windows message parameter composition and decomposition
398 * macros.
400 * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
401 * when constructing the response to a WSAAsyncGetXByY() routine.
403 #define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
405 * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
406 * when constructing the response to WSAAsyncSelect().
408 #define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
410 * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
411 * to extract the buffer length from the lParam in the response
412 * to a WSAGetXByY().
414 #define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
416 * WSAGETASYNCERROR is intended for use by the Windows Sockets application
417 * to extract the error code from the lParam in the response
418 * to a WSAGetXByY().
420 #define WSAGETASYNCERROR(lParam) HIWORD(lParam)
422 * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
423 * to extract the event code from the lParam in the response
424 * to a WSAAsyncSelect().
426 #define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
428 * WSAGETSELECTERROR is intended for use by the Windows Sockets application
429 * to extract the error code from the lParam in the response
430 * to a WSAAsyncSelect().
432 #define WSAGETSELECTERROR(lParam) HIWORD(lParam)
434 /* ----------------------------------- internal structures */
436 /* ws_... struct conversion flags */
438 #define WS_DUP_NATIVE 0x0001 /* native structure format (not ws_..) */
439 #define WS_DUP_OFFSET 0x0002 /* internal pointers are offsets */
440 #define WS_DUP_SEGPTR 0x0004 /* internal pointers are SEGPTRs */
441 /* by default, internal pointers are linear */
442 /* async DNS op flags */
444 #define AOP_IO 0x0000001 /* aop_control paramaters */
446 #define AOP_CONTROL_REMOVE 0x0000000 /* aop_control return values */
447 #define AOP_CONTROL_KEEP 0x0000001
449 typedef struct __aop
451 /* AOp header */
453 struct __aop *next, *prev;
454 int fd[2]; /* pipe */
455 int (*aop_control)(struct __aop*, int); /* SIGIO handler */
456 pid_t pid; /* child process pid */
458 /* custom data */
460 HWND16 hWnd; /* hWnd to post */
461 UINT16 uMsg; /* uMsg message to. */
463 SEGPTR buffer_base; /* buffer to copy result to */
464 UINT16 buflen;
465 UINT16 flags; /* WSMSG_ASYNC_... */
466 } ws_async_op;
468 #define WSMSG_ASYNC_HOSTBYNAME 0x0001
469 #define WSMSG_ASYNC_HOSTBYADDR 0x0002
470 #define WSMSG_ASYNC_PROTOBYNAME 0x0010
471 #define WSMSG_ASYNC_PROTOBYNUM 0x0020
472 #define WSMSG_ASYNC_SERVBYNAME 0x0100
473 #define WSMSG_ASYNC_SERVBYPORT 0x0200
474 #define WSMSG_DEAD_AOP 0x8000
476 typedef struct __sop /* WSAAsyncSelect() control struct */
478 struct __sop *next, *prev;
480 struct __ws* pws;
481 HWND16 hWnd;
482 UINT16 uMsg;
483 } ws_select_op;
485 typedef struct __ws /* socket */
487 int fd;
488 unsigned flags;
489 ws_select_op* psop;
490 } ws_socket;
492 #define WS_MAX_SOCKETS_PER_THREAD 16
493 #define WS_MAX_UDP_DATAGRAM 1024
495 #define WSI_BLOCKINGCALL 0x00000001 /* per-thread info flags */
496 #define WSI_BLOCKINGHOOK32 0x00000002 /* 32-bit callback */
498 typedef struct _WSINFO
500 struct _WSINFO* prev,*next;
502 unsigned flags;
503 INT32 err; /* WSAGetLastError() return value */
504 INT16 num_startup; /* reference counter */
505 INT16 num_async_rq;
506 INT16 last_free; /* entry in the socket table */
507 UINT16 buflen;
508 char* buffer; /* allocated from SEGPTR heap */
509 char* dbuffer; /* buffer for dummies (32 bytes) */
511 ws_socket sock[WS_MAX_SOCKETS_PER_THREAD];
512 DWORD blocking_hook;
513 HTASK16 tid; /* owning task id - process might be better */
514 } WSINFO, *LPWSINFO;
516 int WS_dup_he(LPWSINFO pwsi, struct hostent* p_he, int flag);
517 int WS_dup_pe(LPWSINFO pwsi, struct protoent* p_pe, int flag);
518 int WS_dup_se(LPWSINFO pwsi, struct servent* p_se, int flag);
520 void WS_do_async_gethost(LPWSINFO, unsigned);
521 void WS_do_async_getproto(LPWSINFO, unsigned);
522 void WS_do_async_getserv(LPWSINFO, unsigned);
524 int WINSOCK_async_io(int fd, int async);
525 int WINSOCK_unblock_io(int fd, int noblock);
527 int WINSOCK_check_async_op(ws_async_op* p_aop);
528 void WINSOCK_link_async_op(ws_async_op* p_aop);
529 void WINSOCK_unlink_async_op(ws_async_op* p_aop);
530 int WINSOCK_cancel_async_op(ws_async_op* p_aop);
532 void WINSOCK_cancel_task_aops(HTASK16, void (*__memfree)(void*) );
534 BOOL32 WINSOCK_HandleIO(int* fd_max, int num_pending, fd_set io_set[3] );
535 void WINSOCK_Shutdown(void);
536 UINT16 wsaErrno(void);
537 UINT16 wsaHerrno(void);
539 #endif /* _WINSOCKAPI_ */