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
;
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 */
34 typedef struct ws_protoent
36 SEGPTR p_name
; /* official protocol name */
37 SEGPTR p_aliases
; /* alias list */
38 INT16 p_proto
; /* protocol # */
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 */
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 # */
57 typedef struct sockaddr ws_sockaddr
;
61 UINT16 fd_count
; /* how many are SET? */
62 SOCKET16 fd_array
[FD_SETSIZE
]; /* an array of SOCKETs */
65 /* ws_fd_set operations */
67 INT16
__WSAFDIsSet( SOCKET16
, ws_fd_set
* );
69 #define WS_FD_CLR(fd, set) do { \
71 for (__i = 0; __i < ((ws_fd_set*)(set))->fd_count ; __i++) \
73 if (((ws_fd_set*)(set))->fd_array[__i] == fd) \
75 while (__i < ((ws_fd_set*)(set))->fd_count-1) \
77 ((ws_fd_set*)(set))->fd_array[__i] = \
78 ((ws_fd_set*)(set))->fd_array[__i+1]; \
81 ((ws_fd_set*)(set))->fd_count--; \
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);\
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))
97 * Internet address (old style... should be updated)
100 typedef struct ws_addr_in
103 struct { BYTE s_b1
,s_b2
,s_b3
,s_b4
; } S_un_b
;
104 struct { UINT16 s_w1
,s_w2
; } S_un_w
;
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 */
115 typedef struct ws_sockaddr_in
119 _ws_in_addr sin_addr
;
123 #define WSADESCRIPTION_LEN 256
124 #define WSASYS_STATUS_LEN 128
126 typedef struct WSAData
{
129 char szDescription
[WSADESCRIPTION_LEN
+1];
130 char szSystemStatus
[WSASYS_STATUS_LEN
+1];
134 } WSADATA
, *LPWSADATA
;
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)
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.
211 #ifndef MSG_DONTROUTE
212 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
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
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 */
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
);
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
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
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
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
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 */
448 #define WSMSG_ASYNC_SELECT 0x0000001
449 #define WSMSG_ASYNC_HOSTBYNAME 0x0000010
450 #define WSMSG_ASYNC_HOSTBYADDR 0x0000020
451 #define WSMSG_ASYNC_PROTOBYNAME 0x0000100
452 #define WSMSG_ASYNC_PROTOBYNUM 0x0000200
453 #define WSMSG_ASYNC_SERVBYNAME 0x0001000
454 #define WSMSG_ASYNC_SERVBYPORT 0x0002000
456 #define MTYPE_PARENT 0x50505357
457 #define MTYPE_CLIENT 0x50435357
462 long mtype
; /* WSMSG_... */
464 UINT32 lParam
; /* WS_FD_... event */
465 UINT16 wParam
; /* socket handle - used only for MTYPE_CLIENT messages */
468 #define MTYPE_PARENT_SIZE \
470 #define MTYPE_CLIENT_SIZE \
471 (sizeof(ipc_packet) - sizeof(long))
478 ws_async_op
* p_aop
; /* AsyncSelect() handler */
483 ws_async_op
* ws_aop
; /* init'ed for getXbyY */
484 ws_socket
* ws_sock
; /* init'ed for AsyncSelect */
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
;
507 char* buffer
; /* allocated from SEGPTR heap */
508 char* dbuffer
; /* buffer for dummies (32 bytes) */
510 ws_socket sock
[WS_MAX_SOCKETS_PER_THREAD
];
511 FARPROC16 blocking_hook
;
512 HTASK16 tid
; /* owning thread id - better switch
513 * to TLS when it gets fixed */
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 void WINSOCK_cancel_async_op(HTASK16 tid
);
531 void WINSOCK_do_async_select(void);
532 void WINSOCK_Shutdown(void);
534 UINT16
wsaErrno(void);
535 UINT16
wsaHerrno(void);
537 #endif /* _WINSOCKAPI_ */