Release 961208
[wine/multimedia.git] / include / winsock.h
blobca7bcafc2997e8c6ec285bd52be55f207fb758d2
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;
25 typedef struct ws_hostent
27 SEGPTR h_name; /* official name of host */
28 SEGPTR h_aliases; /* alias list */
29 INT16 h_addrtype; /* host address type */
30 INT16 h_length; /* length of address */
31 SEGPTR h_addr_list; /* list of addresses from name server */
32 } _ws_hostent;
34 typedef struct ws_protoent
36 SEGPTR p_name; /* official protocol name */
37 SEGPTR p_aliases; /* alias list */
38 INT16 p_proto; /* protocol # */
39 } _ws_protoent;
41 typedef struct ws_servent
43 SEGPTR s_name; /* official service name */
44 SEGPTR s_aliases; /* alias list */
45 INT16 s_port; /* port # */
46 SEGPTR s_proto; /* protocol to use */
47 } _ws_servent;
49 typedef struct ws_netent
51 SEGPTR n_name; /* official name of net */
52 SEGPTR n_aliases; /* alias list */
53 INT16 n_addrtype; /* net address type */
54 INT32 n_net; /* network # */
55 } _ws_netent;
57 typedef struct sockaddr ws_sockaddr;
59 typedef struct
61 UINT16 fd_count; /* how many are SET? */
62 SOCKET16 fd_array[FD_SETSIZE]; /* an array of SOCKETs */
63 } ws_fd_set;
65 /* ws_fd_set operations */
67 INT16 __WSAFDIsSet( SOCKET16, ws_fd_set * );
69 #define WS_FD_CLR(fd, set) do { \
70 UINT16 __i; \
71 for (__i = 0; __i < ((ws_fd_set*)(set))->fd_count ; __i++) \
72 { \
73 if (((ws_fd_set*)(set))->fd_array[__i] == fd) \
74 { \
75 while (__i < ((ws_fd_set*)(set))->fd_count-1) \
76 { \
77 ((ws_fd_set*)(set))->fd_array[__i] = \
78 ((ws_fd_set*)(set))->fd_array[__i+1]; \
79 __i++; \
80 } \
81 ((ws_fd_set*)(set))->fd_count--; \
82 break; \
83 } \
84 } \
85 } while(0)
87 #define WS_FD_SET(fd, set) do { \
88 if (((ws_fd_set*)(set))->fd_count < FD_SETSIZE) \
89 ((ws_fd_set*)(set))->fd_array[((ws_fd_set*)(set))->fd_count++]=(fd);\
90 } while(0)
92 #define WS_FD_ZERO(set) (((ws_fd_set*)(set))->fd_count=0)
94 #define WS_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET16)(fd), (ws_fd_set*)(set))
96 /*
97 * Internet address (old style... should be updated)
100 typedef struct ws_addr_in
102 union {
103 struct { BYTE s_b1,s_b2,s_b3,s_b4; } S_un_b;
104 struct { UINT16 s_w1,s_w2; } S_un_w;
105 UINT32 S_addr;
106 } S_un;
107 #define ws_addr S_un.S_addr /* can be used for most tcp & ip code */
108 #define ws_host S_un.S_un_b.s_b2 /* host on imp */
109 #define ws_net S_un.S_un_b.s_b1 /* network */
110 #define ws_imp S_un.S_un_w.s_w2 /* imp */
111 #define ws_impno S_un.S_un_b.s_b4 /* imp # */
112 #define ws_lh S_un.S_un_b.s_b3 /* logical host */
113 } _ws_in_addr;
115 typedef struct ws_sockaddr_in
117 INT16 sin_family;
118 UINT16 sin_port;
119 _ws_in_addr sin_addr;
120 char sin_zero[8];
121 } _ws_sockaddr_in;
123 #define WSADESCRIPTION_LEN 256
124 #define WSASYS_STATUS_LEN 128
126 typedef struct WSAData {
127 WORD wVersion;
128 WORD wHighVersion;
129 char szDescription[WSADESCRIPTION_LEN+1];
130 char szSystemStatus[WSASYS_STATUS_LEN+1];
131 UINT16 iMaxSockets;
132 UINT16 iMaxUdpDg;
133 SEGPTR lpVendorInfo;
134 } WSADATA, *LPWSADATA;
136 #pragma pack(4)
138 /* ----------------------------------- no Win16 structure defs beyond this line! */
141 * This is used instead of -1, since the
142 * SOCKET type is unsigned.
144 #define INVALID_SOCKET (SOCKET16)(~0)
145 #define SOCKET_ERROR (-1)
148 * Types
150 #define WS_SOCK_STREAM 1 /* stream socket */
151 #define WS_SOCK_DGRAM 2 /* datagram socket */
152 #define WS_SOCK_RAW 3 /* raw-protocol interface */
153 #define WS_SOCK_RDM 4 /* reliably-delivered message */
154 #define WS_SOCK_SEQPACKET 5 /* sequenced packet stream */
156 #define WS_SOL_SOCKET (-1)
157 #define WS_IPPROTO_TCP 6
160 * Option flags per-socket.
162 #define WS_SO_DEBUG 0x0001 /* turn on debugging info recording */
163 #define WS_SO_ACCEPTCONN 0x0002 /* socket has had listen() */
164 #define WS_SO_REUSEADDR 0x0004 /* allow local address reuse */
165 #define WS_SO_KEEPALIVE 0x0008 /* keep connections alive */
166 #define WS_SO_DONTROUTE 0x0010 /* just use interface addresses */
167 #define WS_SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
168 #define WS_SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
169 #define WS_SO_LINGER 0x0080 /* linger on close if data present */
170 #define WS_SO_OOBINLINE 0x0100 /* leave received OOB data in line */
172 #define WS_SO_DONTLINGER (UINT16)(~WS_SO_LINGER)
175 * Additional options.
177 #define WS_SO_SNDBUF 0x1001 /* send buffer size */
178 #define WS_SO_RCVBUF 0x1002 /* receive buffer size */
179 #define WS_SO_SNDLOWAT 0x1003 /* send low-water mark */
180 #define WS_SO_RCVLOWAT 0x1004 /* receive low-water mark */
181 #define WS_SO_SNDTIMEO 0x1005 /* send timeout */
182 #define WS_SO_RCVTIMEO 0x1006 /* receive timeout */
183 #define WS_SO_ERROR 0x1007 /* get error status and clear */
184 #define WS_SO_TYPE 0x1008 /* get socket type */
186 #define WS_IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
187 #define WS_IOC_VOID 0x20000000 /* no parameters */
188 #define WS_IOC_OUT 0x40000000 /* copy out parameters */
189 #define WS_IOC_IN 0x80000000 /* copy in parameters */
190 #define WS_IOC_INOUT (WS_IOC_IN|WS_IOC_OUT)
191 #define WS_IOR(x,y,t) (WS_IOC_OUT|(((UINT32)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
192 #define WS_IOW(x,y,t) (WS_IOC_IN|(((UINT32)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
195 * Socket I/O flags (supported by spec 1.1)
198 #define WS_FIONREAD WS_IOR('f', 127, u_long)
199 #define WS_FIONBIO WS_IOW('f', 126, u_long)
201 #define WS_SIOCATMARK WS_IOR('s', 7, u_long)
204 * Maximum queue length specifiable by listen.
206 #ifdef SOMAXCONN
207 #undef SOMAXCONN
208 #endif
209 #define SOMAXCONN 5
211 #ifndef MSG_DONTROUTE
212 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
213 #endif
214 #define MSG_MAXIOVLEN 16
217 * Define constant based on rfc883, used by gethostbyxxxx() calls.
219 #define MAXGETHOSTSTRUCT 1024
222 * Define flags to be used with the WSAAsyncSelect() call.
224 #define WS_FD_READ 0x01
225 #define WS_FD_WRITE 0x02
226 #define WS_FD_OOB 0x04
227 #define WS_FD_ACCEPT 0x08
228 #define WS_FD_CONNECT 0x10
229 #define WS_FD_CLOSE 0x20
231 #define WS_FD_NONBLOCK 0x10000000 /* internal per-socket flags */
232 #define WS_FD_INACTIVE 0x20000000
233 #define WS_FD_CONNECTED 0x40000000
234 #define WS_FD_INTERNAL 0xFFFF0000
237 * All Windows Sockets error constants are biased by WSABASEERR from
238 * the "normal"
240 #define WSABASEERR 10000
242 * Windows Sockets definitions of regular Microsoft C error constants
244 #define WSAEINTR (WSABASEERR+4)
245 #define WSAEBADF (WSABASEERR+9)
246 #define WSAEACCES (WSABASEERR+13)
247 #define WSAEFAULT (WSABASEERR+14)
248 #define WSAEINVAL (WSABASEERR+22)
249 #define WSAEMFILE (WSABASEERR+24)
252 * Windows Sockets definitions of regular Berkeley error constants
254 #define WSAEWOULDBLOCK (WSABASEERR+35)
255 #define WSAEINPROGRESS (WSABASEERR+36)
256 #define WSAEALREADY (WSABASEERR+37)
257 #define WSAENOTSOCK (WSABASEERR+38)
258 #define WSAEDESTADDRREQ (WSABASEERR+39)
259 #define WSAEMSGSIZE (WSABASEERR+40)
260 #define WSAEPROTOTYPE (WSABASEERR+41)
261 #define WSAENOPROTOOPT (WSABASEERR+42)
262 #define WSAEPROTONOSUPPORT (WSABASEERR+43)
263 #define WSAESOCKTNOSUPPORT (WSABASEERR+44)
264 #define WSAEOPNOTSUPP (WSABASEERR+45)
265 #define WSAEPFNOSUPPORT (WSABASEERR+46)
266 #define WSAEAFNOSUPPORT (WSABASEERR+47)
267 #define WSAEADDRINUSE (WSABASEERR+48)
268 #define WSAEADDRNOTAVAIL (WSABASEERR+49)
269 #define WSAENETDOWN (WSABASEERR+50)
270 #define WSAENETUNREACH (WSABASEERR+51)
271 #define WSAENETRESET (WSABASEERR+52)
272 #define WSAECONNABORTED (WSABASEERR+53)
273 #define WSAECONNRESET (WSABASEERR+54)
274 #define WSAENOBUFS (WSABASEERR+55)
275 #define WSAEISCONN (WSABASEERR+56)
276 #define WSAENOTCONN (WSABASEERR+57)
277 #define WSAESHUTDOWN (WSABASEERR+58)
278 #define WSAETOOMANYREFS (WSABASEERR+59)
279 #define WSAETIMEDOUT (WSABASEERR+60)
280 #define WSAECONNREFUSED (WSABASEERR+61)
281 #define WSAELOOP (WSABASEERR+62)
282 #define WSAENAMETOOLONG (WSABASEERR+63)
283 #define WSAEHOSTDOWN (WSABASEERR+64)
284 #define WSAEHOSTUNREACH (WSABASEERR+65)
285 #define WSAENOTEMPTY (WSABASEERR+66)
286 #define WSAEPROCLIM (WSABASEERR+67)
287 #define WSAEUSERS (WSABASEERR+68)
288 #define WSAEDQUOT (WSABASEERR+69)
289 #define WSAESTALE (WSABASEERR+70)
290 #define WSAEREMOTE (WSABASEERR+71)
293 * Extended Windows Sockets error constant definitions
295 #define WSASYSNOTREADY (WSABASEERR+91)
296 #define WSAVERNOTSUPPORTED (WSABASEERR+92)
297 #define WSANOTINITIALISED (WSABASEERR+93)
300 * Error return codes from gethostbyname() and gethostbyaddr()
301 * (when using the resolver). Note that these errors are
302 * retrieved via WSAGetLastError() and must therefore follow
303 * the rules for avoiding clashes with error numbers from
304 * specific implementations or language run-time systems.
305 * For this reason the codes are based at WSABASEERR+1001.
306 * Note also that [WSA]NO_ADDRESS is defined only for
307 * compatibility purposes.
310 /* #define h_errno WSAGetLastError() */
312 /* Authoritative Answer: Host not found */
313 #define WSAHOST_NOT_FOUND (WSABASEERR+1001)
315 /* Non-Authoritative: Host not found, or SERVERFAIL */
316 #define WSATRY_AGAIN (WSABASEERR+1002)
318 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
319 #define WSANO_RECOVERY (WSABASEERR+1003)
321 /* Valid name, no data record of requested type */
322 #define WSANO_DATA (WSABASEERR+1004)
324 /* no address, look for MX record */
325 #define WSANO_ADDRESS WSANO_DATA
327 /* Socket function prototypes */
329 #ifdef __cplusplus
330 extern "C" {
331 #endif
333 /* Microsoft Windows Extension function prototypes */
335 INT16 WSAStartup(UINT16 wVersionRequired, LPWSADATA lpWSAData);
336 INT16 WSACleanup(void);
337 void WSASetLastError(INT16 iError);
338 INT16 WSAGetLastError(void);
339 BOOL16 WSAIsBlocking(void);
340 INT16 WSAUnhookBlockingHook(void);
341 FARPROC16 WSASetBlockingHook(FARPROC16 lpBlockFunc);
342 INT16 WSACancelBlockingCall(void);
343 HANDLE16 WSAAsyncGetServByName(HWND16 hWnd, UINT16 wMsg,
344 LPCSTR name, LPCSTR proto,
345 SEGPTR buf, INT16 buflen);
347 HANDLE16 WSAAsyncGetServByPort(HWND16 hWnd, UINT16 wMsg, INT16 port,
348 LPCSTR proto, SEGPTR buf, INT16 buflen);
350 HANDLE16 WSAAsyncGetProtoByName(HWND16 hWnd, UINT16 wMsg,
351 LPCSTR name, SEGPTR buf, INT16 buflen);
353 HANDLE16 WSAAsyncGetProtoByNumber(HWND16 hWnd, UINT16 wMsg,
354 INT16 number, SEGPTR buf, INT16 buflen);
356 HANDLE16 WSAAsyncGetHostByName(HWND16 hWnd, UINT16 wMsg,
357 LPCSTR name, SEGPTR buf, INT16 buflen);
359 HANDLE16 WSAAsyncGetHostByAddr(HWND16 hWnd, UINT16 wMsg, LPCSTR addr, INT16 len,
360 INT16 type, SEGPTR buf, INT16 buflen);
362 INT16 WSACancelAsyncRequest(HANDLE16 hAsyncTaskHandle);
363 INT16 WSAAsyncSelect(SOCKET16 s, HWND16 hWnd, UINT16 wMsg, UINT32 lEvent);
365 #ifdef __cplusplus
367 #endif
369 /* Microsoft Windows Extended data types */
370 typedef struct sockaddr SOCKADDR, *PSOCKADDR, *LPSOCKADDR;
371 typedef struct sockaddr_in SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN;
372 typedef struct linger LINGER, *PLINGER, *LPLINGER;
373 typedef struct in_addr IN_ADDR, *PIN_ADDR, *LPIN_ADDR;
374 typedef struct fd_set FD_SET, *PFD_SET, *LPFD_SET;
375 typedef struct hostent HOSTENT, *PHOSTENT, *LPHOSTENT;
376 typedef struct servent SERVENT, *PSERVENT, *LPSERVENT;
377 typedef struct protoent PROTOENT, *PPROTOENT, *LPPROTOENT;
378 typedef struct timeval TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
381 * Windows message parameter composition and decomposition
382 * macros.
384 * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
385 * when constructing the response to a WSAAsyncGetXByY() routine.
387 #define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
389 * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
390 * when constructing the response to WSAAsyncSelect().
392 #define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
394 * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
395 * to extract the buffer length from the lParam in the response
396 * to a WSAGetXByY().
398 #define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
400 * WSAGETASYNCERROR is intended for use by the Windows Sockets application
401 * to extract the error code from the lParam in the response
402 * to a WSAGetXByY().
404 #define WSAGETASYNCERROR(lParam) HIWORD(lParam)
406 * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
407 * to extract the event code from the lParam in the response
408 * to a WSAAsyncSelect().
410 #define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
412 * WSAGETSELECTERROR is intended for use by the Windows Sockets application
413 * to extract the error code from the lParam in the response
414 * to a WSAAsyncSelect().
416 #define WSAGETSELECTERROR(lParam) HIWORD(lParam)
418 /* ----------------------------------- internal structures */
420 #define WS_DUP_NATIVE 0x0
421 #define WS_DUP_OFFSET 0x2
422 #define WS_DUP_SEGPTR 0x4
424 #define AOP_IO 0x0000001 /* aop_control paramaters */
426 #define AOP_CONTROL_REMOVE 0x0000000 /* aop_control return values */
427 #define AOP_CONTROL_KEEP 0x0000001
429 typedef struct __aop
431 /* AOp header */
433 struct __aop *next, *prev;
434 int fd[2]; /* pipe */
435 int (*aop_control)(struct __aop*, int); /* SIGIO handler */
436 pid_t pid; /* child process pid */
438 /* custom data */
440 HWND16 hWnd;
441 UINT16 uMsg;
443 unsigned flags;
444 SEGPTR buffer_base;
445 int buflen;
446 char* init; /* parameter data - length is in the async_ctl */
447 } ws_async_op;
449 #define WSMSG_ASYNC_SELECT 0x0000001
450 #define WSMSG_ASYNC_HOSTBYNAME 0x0000010
451 #define WSMSG_ASYNC_HOSTBYADDR 0x0000020
452 #define WSMSG_ASYNC_PROTOBYNAME 0x0000100
453 #define WSMSG_ASYNC_PROTOBYNUM 0x0000200
454 #define WSMSG_ASYNC_SERVBYNAME 0x0001000
455 #define WSMSG_ASYNC_SERVBYPORT 0x0002000
457 #define MTYPE_PARENT 0x50505357
458 #define MTYPE_CLIENT 0x50435357
460 #pragma pack(1)
461 typedef struct
463 long mtype; /* WSMSG_... */
465 UINT32 lParam;
466 UINT16 wParam; /* socket handle */
467 } ipc_packet;
469 #define MTYPE_PARENT_SIZE \
470 (sizeof(UINT32))
471 #define MTYPE_CLIENT_SIZE \
472 (sizeof(ipc_packet) - sizeof(long))
473 #pragma pack(4)
475 typedef struct
477 int fd;
478 unsigned flags;
479 ws_async_op* p_aop;
480 } ws_socket;
482 typedef struct
484 ws_async_op* ws_aop; /* init'ed for getXbyY */
485 ws_socket* ws_sock; /* init'ed for AsyncSelect */
486 int lEvent;
487 int lLength;
488 char* buffer;
489 ipc_packet ip;
490 } ws_async_ctl;
492 #define WS_MAX_SOCKETS_PER_THREAD 16
493 #define WS_MAX_UDP_DATAGRAM 1024
495 #define WSI_BLOCKINGCALL 0x00000001 /* per-thread info flags */
497 typedef struct __WSINFO
499 struct __WSINFO* prev,*next;
501 unsigned flags;
502 int errno;
503 int num_startup;
504 int num_async_rq;
505 int last_free;
506 ws_socket sock[WS_MAX_SOCKETS_PER_THREAD];
507 int buflen;
508 char* buffer;
509 FARPROC16 blocking_hook;
510 HTASK16 tid; /* owning thread id - better switch
511 * to TLS when it gets fixed */
512 } WSINFO, *LPWSINFO;
514 int WS_dup_he(LPWSINFO pwsi, struct hostent* p_he, int flag);
515 int WS_dup_pe(LPWSINFO pwsi, struct protoent* p_pe, int flag);
516 int WS_dup_se(LPWSINFO pwsi, struct servent* p_se, int flag);
518 void WS_do_async_gethost(LPWSINFO, unsigned);
519 void WS_do_async_getproto(LPWSINFO, unsigned);
520 void WS_do_async_getserv(LPWSINFO, unsigned);
522 int WINSOCK_async_io(int fd, int async);
523 int WINSOCK_unblock_io(int fd, int noblock);
525 int WINSOCK_check_async_op(ws_async_op* p_aop);
526 void WINSOCK_link_async_op(ws_async_op* p_aop);
527 void WINSOCK_unlink_async_op(ws_async_op* p_aop);
528 void WINSOCK_cancel_async_op(HTASK16 tid);
529 void WINSOCK_do_async_select(void);
531 UINT16 wsaErrno(void);
532 UINT16 wsaHerrno(void);
534 #endif /* _WINSOCKAPI_ */