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