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>
19 # include <netipx/ipx.h>
24 # include <asm/types.h>
25 # include <linux/ipx.h>
34 #endif /* defined(__cplusplus) */
38 /* Win16 socket-related types */
40 typedef UINT16 SOCKET16;
43 typedef struct ws_hostent
45 SEGPTR h_name; /* official name of host */
46 SEGPTR h_aliases; /* alias list */
47 INT16 h_addrtype; /* host address type */
48 INT16 h_length; /* length of address */
49 SEGPTR h_addr_list; /* list of addresses from name server */
52 typedef struct ws_protoent
54 SEGPTR p_name; /* official protocol name */
55 SEGPTR p_aliases; /* alias list */
56 INT16 p_proto; /* protocol # */
59 typedef struct ws_servent
61 SEGPTR s_name; /* official service name */
62 SEGPTR s_aliases; /* alias list */
63 INT16 s_port; /* port # */
64 SEGPTR s_proto; /* protocol to use */
67 typedef struct ws_netent
69 SEGPTR n_name; /* official name of net */
70 SEGPTR n_aliases; /* alias list */
71 INT16 n_addrtype; /* net address type */
72 INT n_net; /* network # */
75 typedef struct sockaddr ws_sockaddr;
79 UINT16 fd_count; /* how many are SET? */
80 SOCKET16 fd_array[FD_SETSIZE]; /* an array of SOCKETs */
85 UINT fd_count; /* how many are SET? */
86 SOCKET fd_array[FD_SETSIZE]; /* an array of SOCKETs */
89 /* ws_fd_set operations */
91 INT16 WINAPI __WSAFDIsSet16( SOCKET16, ws_fd_set16 * );
92 INT WINAPI __WSAFDIsSet( SOCKET, ws_fd_set32 * );
94 #define __WS_FD_CLR(fd, set, cast) do { \
96 for (__i = 0; __i < ((cast*)(set))->fd_count ; __i++) \
98 if (((cast*)(set))->fd_array[__i] == fd) \
100 while (__i < ((cast*)(set))->fd_count-1) \
102 ((cast*)(set))->fd_array[__i] = \
103 ((cast*)(set))->fd_array[__i+1]; \
106 ((cast*)(set))->fd_count--; \
111 #define WS_FD_CLR16(fd, set) __WS_FD_CLR((fd),(set), ws_fd_set16)
112 #define WS_FD_CLR(fd, set) __WS_FD_CLR((fd),(set), ws_fd_set32)
114 #define __WS_FD_SET(fd, set, cast) do { \
115 if (((cast*)(set))->fd_count < FD_SETSIZE) \
116 ((cast*)(set))->fd_array[((cast*)(set))->fd_count++]=(fd);\
118 #define WS_FD_SET16(fd, set) __WS_FD_SET((fd),(set), ws_fd_set16)
119 #define WS_FD_SET(fd, set) __WS_FD_SET((fd),(set), ws_fd_set32)
121 #define WS_FD_ZERO16(set) (((ws_fd_set16*)(set))->fd_count=0)
122 #define WS_FD_ZERO(set) (((ws_fd_set32*)(set))->fd_count=0)
124 #define WS_FD_ISSET16(fd, set) __WSAFDIsSet16((SOCKET16)(fd), (ws_fd_set16*)(set))
125 #define WS_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (ws_fd_set32*)(set))
128 * Internet address (old style... should be updated)
134 struct { BYTE s_b1,s_b2,s_b3,s_b4; } S_un_b;
135 struct { UINT16 s_w1,s_w2; } S_un_w;
138 #define ws_addr S_un.S_addr /* can be used for most tcp & ip code */
139 #define ws_host S_un.S_un_b.s_b2 /* host on imp */
140 #define ws_net S_un.S_un_b.s_b1 /* network */
141 #define ws_imp S_un.S_un_w.s_w2 /* imp */
142 #define ws_impno S_un.S_un_b.s_b4 /* imp # */
143 #define ws_lh S_un.S_un_b.s_b3 /* logical host */
146 struct ws_sockaddr_in
150 struct ws_in_addr sin_addr;
154 #define WSADESCRIPTION_LEN 256
155 #define WSASYS_STATUS_LEN 128
157 typedef struct WSAData {
160 char szDescription[WSADESCRIPTION_LEN+1];
161 char szSystemStatus[WSASYS_STATUS_LEN+1];
165 } WSADATA, *LPWSADATA;
169 /* ----------------------------------- no Win16 structure defs beyond this line! */
172 * This is used instead of -1, since the
173 * SOCKET type is unsigned.
175 #define INVALID_SOCKET16 (~0)
176 #define INVALID_SOCKET (~0)
177 #define SOCKET_ERROR (-1)
183 #define WS_SOCK_STREAM 1 /* stream socket */
184 #define WS_SOCK_DGRAM 2 /* datagram socket */
185 #define WS_SOCK_RAW 3 /* raw-protocol interface */
186 #define WS_SOCK_RDM 4 /* reliably-delivered message */
187 #define WS_SOCK_SEQPACKET 5 /* sequenced packet stream */
189 #define WS_SOL_SOCKET 0xffff
190 #define WS_IPPROTO_TCP 6
193 * Option flags per-socket.
195 #define WS_SO_DEBUG 0x0001 /* turn on debugging info recording */
196 #define WS_SO_ACCEPTCONN 0x0002 /* socket has had listen() */
197 #define WS_SO_REUSEADDR 0x0004 /* allow local address reuse */
198 #define WS_SO_KEEPALIVE 0x0008 /* keep connections alive */
199 #define WS_SO_DONTROUTE 0x0010 /* just use interface addresses */
200 #define WS_SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
201 #define WS_SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
202 #define WS_SO_LINGER 0x0080 /* linger on close if data present */
203 #define WS_SO_OOBINLINE 0x0100 /* leave received OOB data in line */
205 #define WS_SO_DONTLINGER (UINT)(~WS_SO_LINGER)
208 * Additional options.
210 #define WS_SO_SNDBUF 0x1001 /* send buffer size */
211 #define WS_SO_RCVBUF 0x1002 /* receive buffer size */
212 #define WS_SO_SNDLOWAT 0x1003 /* send low-water mark */
213 #define WS_SO_RCVLOWAT 0x1004 /* receive low-water mark */
214 #define WS_SO_SNDTIMEO 0x1005 /* send timeout */
215 #define WS_SO_RCVTIMEO 0x1006 /* receive timeout */
216 #define WS_SO_ERROR 0x1007 /* get error status and clear */
217 #define WS_SO_TYPE 0x1008 /* get socket type */
219 #define WS_IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
220 #define WS_IOC_VOID 0x20000000 /* no parameters */
221 #define WS_IOC_OUT 0x40000000 /* copy out parameters */
222 #define WS_IOC_IN 0x80000000 /* copy in parameters */
223 #define WS_IOC_INOUT (WS_IOC_IN|WS_IOC_OUT)
224 #define WS_IOR(x,y,t) (WS_IOC_OUT|(((UINT)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
225 #define WS_IOW(x,y,t) (WS_IOC_IN|(((UINT)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
227 /* IPPROTO_TCP options */
228 #define WS_TCP_NODELAY 1 /* do not apply nagle algorithm */
231 * Socket I/O flags (supported by spec 1.1)
234 #define WS_FIONREAD WS_IOR('f', 127, u_long)
235 #define WS_FIONBIO WS_IOW('f', 126, u_long)
237 #define WS_SIOCATMARK WS_IOR('s', 7, u_long)
240 * Maximum queue length specifiable by listen.
247 #ifndef MSG_DONTROUTE
248 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
250 #define MSG_MAXIOVLEN 16
253 * Define constant based on rfc883, used by gethostbyxxxx() calls.
255 #define MAXGETHOSTSTRUCT 1024
258 * Define flags to be used with the WSAAsyncSelect() call.
260 #define FD_READ WS_FD_READ
261 #define FD_WRITE WS_FD_WRITE
262 #define FD_OOB WS_FD_OOB
263 #define FD_ACCEPT WS_FD_ACCEPT
264 #define FD_CONNECT WS_FD_CONNECT
265 #define FD_CLOSE WS_FD_CLOSE
266 #define WS_FD_READ 0x0001
267 #define WS_FD_WRITE 0x0002
268 #define WS_FD_OOB 0x0004
269 #define WS_FD_ACCEPT 0x0008
270 #define WS_FD_CONNECT 0x0010
271 #define WS_FD_CLOSE 0x0020
273 #define WS_FD_LISTENING 0x10000000 /* internal per-socket flags */
274 #define WS_FD_INACTIVE 0x20000000
275 #define WS_FD_CONNECTED 0x40000000
276 #define WS_FD_RAW 0x80000000
277 #define WS_FD_INTERNAL 0xFFFF0000
280 * All Windows Sockets error constants are biased by WSABASEERR from
283 #define WSABASEERR 10000
285 * Windows Sockets definitions of regular Microsoft C error constants
287 #define WSAEINTR (WSABASEERR+4)
288 #define WSAEBADF (WSABASEERR+9)
289 #define WSAEACCES (WSABASEERR+13)
290 #define WSAEFAULT (WSABASEERR+14)
291 #define WSAEINVAL (WSABASEERR+22)
292 #define WSAEMFILE (WSABASEERR+24)
295 * Windows Sockets definitions of regular Berkeley error constants
297 #define WSAEWOULDBLOCK (WSABASEERR+35)
298 #define WSAEINPROGRESS (WSABASEERR+36)
299 #define WSAEALREADY (WSABASEERR+37)
300 #define WSAENOTSOCK (WSABASEERR+38)
301 #define WSAEDESTADDRREQ (WSABASEERR+39)
302 #define WSAEMSGSIZE (WSABASEERR+40)
303 #define WSAEPROTOTYPE (WSABASEERR+41)
304 #define WSAENOPROTOOPT (WSABASEERR+42)
305 #define WSAEPROTONOSUPPORT (WSABASEERR+43)
306 #define WSAESOCKTNOSUPPORT (WSABASEERR+44)
307 #define WSAEOPNOTSUPP (WSABASEERR+45)
308 #define WSAEPFNOSUPPORT (WSABASEERR+46)
309 #define WSAEAFNOSUPPORT (WSABASEERR+47)
310 #define WSAEADDRINUSE (WSABASEERR+48)
311 #define WSAEADDRNOTAVAIL (WSABASEERR+49)
312 #define WSAENETDOWN (WSABASEERR+50)
313 #define WSAENETUNREACH (WSABASEERR+51)
314 #define WSAENETRESET (WSABASEERR+52)
315 #define WSAECONNABORTED (WSABASEERR+53)
316 #define WSAECONNRESET (WSABASEERR+54)
317 #define WSAENOBUFS (WSABASEERR+55)
318 #define WSAEISCONN (WSABASEERR+56)
319 #define WSAENOTCONN (WSABASEERR+57)
320 #define WSAESHUTDOWN (WSABASEERR+58)
321 #define WSAETOOMANYREFS (WSABASEERR+59)
322 #define WSAETIMEDOUT (WSABASEERR+60)
323 #define WSAECONNREFUSED (WSABASEERR+61)
324 #define WSAELOOP (WSABASEERR+62)
325 #define WSAENAMETOOLONG (WSABASEERR+63)
326 #define WSAEHOSTDOWN (WSABASEERR+64)
327 #define WSAEHOSTUNREACH (WSABASEERR+65)
328 #define WSAENOTEMPTY (WSABASEERR+66)
329 #define WSAEPROCLIM (WSABASEERR+67)
330 #define WSAEUSERS (WSABASEERR+68)
331 #define WSAEDQUOT (WSABASEERR+69)
332 #define WSAESTALE (WSABASEERR+70)
333 #define WSAEREMOTE (WSABASEERR+71)
336 * Extended Windows Sockets error constant definitions
338 #define WSASYSNOTREADY (WSABASEERR+91)
339 #define WSAVERNOTSUPPORTED (WSABASEERR+92)
340 #define WSANOTINITIALISED (WSABASEERR+93)
343 * Error return codes from gethostbyname() and gethostbyaddr()
344 * (when using the resolver). Note that these errors are
345 * retrieved via WSAGetLastError() and must therefore follow
346 * the rules for avoiding clashes with error numbers from
347 * specific implementations or language run-time systems.
348 * For this reason the codes are based at WSABASEERR+1001.
349 * Note also that [WSA]NO_ADDRESS is defined only for
350 * compatibility purposes.
353 /* #define h_errno WSAGetLastError() */
355 /* Authoritative Answer: Host not found */
356 #define WSAHOST_NOT_FOUND (WSABASEERR+1001)
358 /* Non-Authoritative: Host not found, or SERVERFAIL */
359 #define WSATRY_AGAIN (WSABASEERR+1002)
361 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
362 #define WSANO_RECOVERY (WSABASEERR+1003)
364 /* Valid name, no data record of requested type */
365 #define WSANO_DATA (WSABASEERR+1004)
367 /* no address, look for MX record */
368 #define WSANO_ADDRESS WSANO_DATA
370 /* Socket function prototypes */
376 /* Microsoft Windows Extension function prototypes */
378 INT16 WINAPI WSAStartup16(UINT16 wVersionRequired, LPWSADATA lpWSAData);
379 INT WINAPI WSAStartup(UINT wVersionRequired, LPWSADATA lpWSAData);
380 void WINAPI WSASetLastError16(INT16 iError);
381 void WINAPI WSASetLastError(INT iError);
382 INT WINAPI WSACleanup(void);
383 INT WINAPI WSAGetLastError(void);
384 BOOL WINAPI WSAIsBlocking(void);
385 INT WINAPI WSACancelBlockingCall(void);
386 INT16 WINAPI WSAUnhookBlockingHook16(void);
387 INT WINAPI WSAUnhookBlockingHook(void);
388 FARPROC16 WINAPI WSASetBlockingHook16(FARPROC16 lpBlockFunc);
389 FARPROC WINAPI WSASetBlockingHook(FARPROC lpBlockFunc);
391 HANDLE16 WINAPI WSAAsyncGetServByName16(HWND16 hWnd, UINT16 wMsg, LPCSTR name, LPCSTR proto,
392 SEGPTR buf, INT16 buflen);
393 HANDLE WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name, LPCSTR proto,
394 LPSTR sbuf, INT buflen);
396 HANDLE16 WINAPI WSAAsyncGetServByPort16(HWND16 hWnd, UINT16 wMsg, INT16 port,
397 LPCSTR proto, SEGPTR buf, INT16 buflen);
398 HANDLE WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
399 LPCSTR proto, LPSTR sbuf, INT buflen);
401 HANDLE16 WINAPI WSAAsyncGetProtoByName16(HWND16 hWnd, UINT16 wMsg,
402 LPCSTR name, SEGPTR buf, INT16 buflen);
403 HANDLE WINAPI WSAAsyncGetProtoByName(HWND hWnd, UINT uMsg,
404 LPCSTR name, LPSTR sbuf, INT buflen);
406 HANDLE16 WINAPI WSAAsyncGetProtoByNumber16(HWND16 hWnd, UINT16 wMsg,
407 INT16 number, SEGPTR buf, INT16 buflen);
408 HANDLE WINAPI WSAAsyncGetProtoByNumber(HWND hWnd, UINT uMsg,
409 INT number, LPSTR sbuf, INT buflen);
411 HANDLE16 WINAPI WSAAsyncGetHostByName16(HWND16 hWnd, UINT16 wMsg,
412 LPCSTR name, SEGPTR buf, INT16 buflen);
413 HANDLE WINAPI WSAAsyncGetHostByName(HWND hWnd, UINT uMsg,
414 LPCSTR name, LPSTR sbuf, INT buflen);
416 HANDLE16 WINAPI WSAAsyncGetHostByAddr16(HWND16 hWnd, UINT16 wMsg, LPCSTR addr,
417 INT16 len, INT16 type, SEGPTR buf, INT16 buflen);
418 HANDLE WINAPI WSAAsyncGetHostByAddr(HWND hWnd, UINT uMsg, LPCSTR addr,
419 INT len, INT type, LPSTR sbuf, INT buflen);
421 INT16 WINAPI WSACancelAsyncRequest16(HANDLE16 hAsyncTaskHandle);
422 INT WINAPI WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
424 INT16 WINAPI WSAAsyncSelect16(SOCKET16 s, HWND16 hWnd, UINT16 wMsg, UINT lEvent);
425 INT WINAPI WSAAsyncSelect(SOCKET s, HWND hWnd, UINT uMsg, UINT lEvent);
431 #define WS_AF_UNSPEC 0 /* unspecified */
432 #define WS_AF_UNIX 1 /* local to host (pipes, portals) */
433 #define WS_AF_INET 2 /* internetwork: UDP, TCP, etc. */
434 #define WS_AF_IMPLINK 3 /* arpanet imp addresses */
435 #define WS_AF_PUP 4 /* pup protocols: e.g. BSP */
436 #define WS_AF_CHAOS 5 /* mit CHAOS protocols */
437 #define WS_AF_NS 6 /* XEROX NS protocols */
438 #define WS_AF_IPX WS_AF_NS /* IPX protocols: IPX, SPX, etc. */
439 #define WS_AF_ISO 7 /* ISO protocols */
440 #define WS_AF_OSI AF_ISO /* OSI is ISO */
441 #define WS_AF_ECMA 8 /* european computer manufacturers */
442 #define WS_AF_DATAKIT 9 /* datakit protocols */
443 #define WS_AF_CCITT 10 /* CCITT protocols, X.25 etc */
444 #define WS_AF_SNA 11 /* IBM SNA */
445 #define WS_AF_DECnet 12 /* DECnet */
446 #define WS_AF_DLI 13 /* Direct data link interface */
447 #define WS_AF_LAT 14 /* LAT */
448 #define WS_AF_HYLINK 15 /* NSC Hyperchannel */
449 #define WS_AF_APPLETALK 16 /* AppleTalk */
450 #define WS_AF_NETBIOS 17 /* NetBios-style addresses */
451 #define WS_AF_VOICEVIEW 18 /* VoiceView */
452 #define WS_AF_FIREFOX 19 /* Protocols from Firefox */
453 #define WS_AF_UNKNOWN1 20 /* Somebody is using this! */
454 #define WS_AF_BAN 21 /* Banyan */
455 #define WS_AF_ATM 22 /* Native ATM Services */
456 #define WS_AF_INET6 23 /* Internetwork Version 6 */
457 #define WS_AF_CLUSTER 24 /* Microsoft Wolfpack */
458 #define WS_AF_12844 25 /* IEEE 1284.4 WG AF */
459 #define WS_AF_IRDA 26 /* IrDA */
463 #include "pshpack1.h"
465 struct ws_sockaddr_ipx
479 /* Microsoft Windows Extended data types */
480 typedef struct sockaddr SOCKADDR, *PSOCKADDR, *LPSOCKADDR;
481 typedef struct sockaddr_in SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN;
482 typedef struct linger LINGER, *PLINGER, *LPLINGER;
483 typedef struct in_addr IN_ADDR, *PIN_ADDR, *LPIN_ADDR;
484 typedef struct fd_set FD_SET, *PFD_SET, *LPFD_SET;
485 typedef struct hostent HOSTENT, *PHOSTENT, *LPHOSTENT;
486 typedef struct servent SERVENT, *PSERVENT, *LPSERVENT;
487 typedef struct protoent PROTOENT, *PPROTOENT, *LPPROTOENT;
488 typedef struct timeval TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
491 * Windows message parameter composition and decomposition
494 * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
495 * when constructing the response to a WSAAsyncGetXByY() routine.
497 #define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
499 * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
500 * when constructing the response to WSAAsyncSelect().
502 #define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
504 * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
505 * to extract the buffer length from the lParam in the response
508 #define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
510 * WSAGETASYNCERROR is intended for use by the Windows Sockets application
511 * to extract the error code from the lParam in the response
514 #define WSAGETASYNCERROR(lParam) HIWORD(lParam)
516 * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
517 * to extract the event code from the lParam in the response
518 * to a WSAAsyncSelect().
520 #define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
522 * WSAGETSELECTERROR is intended for use by the Windows Sockets application
523 * to extract the error code from the lParam in the response
524 * to a WSAAsyncSelect().
526 #define WSAGETSELECTERROR(lParam) HIWORD(lParam)
528 /* ----------------------------------- internal structures */
530 /* ws_... struct conversion flags */
532 #define WS_DUP_LINEAR 0x0001
533 #define WS_DUP_NATIVE 0x0000 /* not used anymore */
534 #define WS_DUP_OFFSET 0x0002 /* internal pointers are offsets */
535 #define WS_DUP_SEGPTR 0x0004 /* internal pointers are SEGPTRs */
536 /* by default, internal pointers are linear */
538 typedef struct __sop /* WSAAsyncSelect() control struct */
540 struct __sop *next, *prev;
547 typedef struct __ws /* socket */
554 #define WS_MAX_SOCKETS_PER_PROCESS 16
555 #define WS_MAX_UDP_DATAGRAM 1024
557 #define WSI_BLOCKINGCALL 0x00000001 /* per-thread info flags */
558 #define WSI_BLOCKINGHOOK 0x00000002 /* 32-bit callback */
560 typedef struct _WSINFO
562 struct _WSINFO* prev,*next;
565 INT16 num_startup; /* reference counter */
567 INT16 last_free; /* entry in the socket table */
569 char* buffer; /* allocated from SEGPTR heap */
570 struct ws_hostent *he;
572 struct ws_servent *se;
574 struct ws_protoent *pe;
576 char* dbuffer; /* buffer for dummies (32 bytes) */
578 ws_socket sock[WS_MAX_SOCKETS_PER_PROCESS];
580 HTASK16 tid; /* owning task id - process might be better */
583 /* function prototypes */
584 int WS_dup_he(LPWSINFO pwsi, struct hostent* p_he, int flag);
585 int WS_dup_pe(LPWSINFO pwsi, struct protoent* p_pe, int flag);
586 int WS_dup_se(LPWSINFO pwsi, struct servent* p_se, int flag);
588 BOOL WINSOCK_Init(void);
589 void WINSOCK_Shutdown(void);
590 UINT16 wsaErrno(void);
591 UINT16 wsaHerrno(void);
593 extern INT WINSOCK_DeleteTaskWSI( TDB* pTask, struct _WSINFO* );
597 #endif /* defined(__cplusplus) */
599 #endif /* _WINSOCKAPI_ */