1 /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
3 * This header file corresponds to version 1.1 of the Windows Sockets
10 #include <netinet/in.h>
11 #include <arpa/inet.h>
12 #include <sys/types.h>
16 #include <sys/socket.h>
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 */
35 typedef struct ws_protoent
37 SEGPTR p_name
; /* official protocol name */
38 SEGPTR p_aliases
; /* alias list */
39 INT16 p_proto
; /* protocol # */
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 */
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 # */
58 typedef struct sockaddr ws_sockaddr
;
62 UINT16 fd_count
; /* how many are SET? */
63 SOCKET16 fd_array
[FD_SETSIZE
]; /* an array of SOCKETs */
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 { \
74 for (__i = 0; __i < ((ws_fd_set*)(set))->fd_count ; __i++) \
76 if (((ws_fd_set*)(set))->fd_array[__i] == fd) \
78 while (__i < ((ws_fd_set*)(set))->fd_count-1) \
80 ((ws_fd_set*)(set))->fd_array[__i] = \
81 ((ws_fd_set*)(set))->fd_array[__i+1]; \
84 ((ws_fd_set*)(set))->fd_count--; \
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);\
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))
100 * Internet address (old style... should be updated)
103 typedef struct ws_addr_in
106 struct { BYTE s_b1
,s_b2
,s_b3
,s_b4
; } S_un_b
;
107 struct { UINT16 s_w1
,s_w2
; } S_un_w
;
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 */
118 typedef struct ws_sockaddr_in
122 _ws_in_addr sin_addr
;
126 #define WSADESCRIPTION_LEN 256
127 #define WSASYS_STATUS_LEN 128
129 typedef struct WSAData
{
132 char szDescription
[WSADESCRIPTION_LEN
+1];
133 char szSystemStatus
[WSASYS_STATUS_LEN
+1];
137 } WSADATA
, *LPWSADATA
;
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
);
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.
218 #ifndef MSG_DONTROUTE
219 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
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
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 */
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
,
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
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
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
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_LINEAR 0x0000
439 #define WS_DUP_NATIVE 0x0001 /* native structure format (not ws_..) */
440 #define WS_DUP_OFFSET 0x0002 /* internal pointers are offsets */
441 #define WS_DUP_SEGPTR 0x0004 /* internal pointers are SEGPTRs */
442 /* by default, internal pointers are linear */
443 /* async DNS op flags */
445 #define AOP_IO 0x0000001 /* aop_control paramaters */
447 #define AOP_CONTROL_REMOVE 0x0000000 /* aop_control return values */
448 #define AOP_CONTROL_KEEP 0x0000001
454 struct __aop
*next
, *prev
;
455 int fd
[2]; /* pipe */
456 int (*aop_control
)(struct __aop
*, int); /* SIGIO handler */
457 pid_t pid
; /* child process pid */
461 HWND16 hWnd
; /* hWnd to post */
462 UINT16 uMsg
; /* uMsg message to. */
464 SEGPTR buffer_base
; /* buffer to copy result to */
466 UINT16 flags
; /* WSMSG_ASYNC_... */
469 #define WSMSG_ASYNC_HOSTBYNAME 0x0001
470 #define WSMSG_ASYNC_HOSTBYADDR 0x0002
471 #define WSMSG_ASYNC_PROTOBYNAME 0x0010
472 #define WSMSG_ASYNC_PROTOBYNUM 0x0020
473 #define WSMSG_ASYNC_SERVBYNAME 0x0100
474 #define WSMSG_ASYNC_SERVBYPORT 0x0200
475 #define WSMSG_DEAD_AOP 0x8000
477 typedef struct __sop
/* WSAAsyncSelect() control struct */
479 struct __sop
*next
, *prev
;
486 typedef struct __ws
/* socket */
493 #define WS_MAX_SOCKETS_PER_THREAD 16
494 #define WS_MAX_UDP_DATAGRAM 1024
496 #define WSI_BLOCKINGCALL 0x00000001 /* per-thread info flags */
497 #define WSI_BLOCKINGHOOK32 0x00000002 /* 32-bit callback */
499 typedef struct _WSINFO
501 struct _WSINFO
* prev
,*next
;
504 INT32 err
; /* WSAGetLastError() return value */
505 INT16 num_startup
; /* reference counter */
507 INT16 last_free
; /* entry in the socket table */
509 char* buffer
; /* allocated from SEGPTR heap */
510 char* dbuffer
; /* buffer for dummies (32 bytes) */
512 ws_socket sock
[WS_MAX_SOCKETS_PER_THREAD
];
514 HTASK16 tid
; /* owning task id - process might be better */
517 int WS_dup_he(LPWSINFO pwsi
, struct hostent
* p_he
, int flag
);
518 int WS_dup_pe(LPWSINFO pwsi
, struct protoent
* p_pe
, int flag
);
519 int WS_dup_se(LPWSINFO pwsi
, struct servent
* p_se
, int flag
);
521 void WS_do_async_gethost(LPWSINFO
, unsigned);
522 void WS_do_async_getproto(LPWSINFO
, unsigned);
523 void WS_do_async_getserv(LPWSINFO
, unsigned);
525 int WINSOCK_async_io(int fd
, int async
);
526 int WINSOCK_unblock_io(int fd
, int noblock
);
528 int WINSOCK_check_async_op(ws_async_op
* p_aop
);
529 void WINSOCK_link_async_op(ws_async_op
* p_aop
);
530 void WINSOCK_unlink_async_op(ws_async_op
* p_aop
);
531 int WINSOCK_cancel_async_op(ws_async_op
* p_aop
);
533 void WINSOCK_cancel_task_aops(HTASK16
, void (*__memfree
)(void*) );
535 BOOL32
WINSOCK_HandleIO(int* fd_max
, int num_pending
, fd_set io_set
[3] );
536 void WINSOCK_Shutdown(void);
537 UINT16
wsaErrno(void);
538 UINT16
wsaHerrno(void);
540 #endif /* _WINSOCKAPI_ */