1 /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
3 * This header file corresponds to version 1.1 of the Windows Sockets
11 #include <sys/types.h>
14 #if defined(__svr4__) || defined(__NetBSD__) || defined(__FreeBSD__)
15 #ifndef HAVE_SYS_SOCKET_H
16 #define HAVE_SYS_SOCKET_H
17 #endif /* HAVE_SYS_SOCKET_H */
18 #endif /* __svr4__ || __NetBSD__ || __FreeBSD__ */
21 /* Solaris uses these macro names */
24 #include <netinet/in.h>
25 /* Restore the Windows values */
35 #ifdef HAVE_ARPA_INET_H
36 #include <arpa/inet.h>
37 #endif /* HAVE_ARPA_INET_H */
42 #endif /* HAVE_NETDB_H */
43 #ifdef HAVE_SYS_SOCKET_H
44 #include <sys/socket.h>
45 #endif /* HAVE_SYS_SOCKET_H */
46 #include <sys/ioctl.h>
47 #endif /* RC_INVOKED */
53 #endif /* defined(__cplusplus) */
55 /* no "forced" alignment of ws_XXXXent here ! */
57 typedef struct ws_hostent
59 char *h_name; /* official name of host */
60 char **h_aliases; /* alias list */
61 short h_addrtype; /* host address type */
62 short h_length; /* length of address */
63 char **h_addr_list; /* list of addresses from name server */
66 typedef struct ws_protoent
68 char *p_name; /* official protocol name */
69 char **p_aliases; /* alias list */
70 short p_proto; /* protocol # */
73 typedef struct ws_servent
75 char *s_name; /* official service name */
76 char **s_aliases; /* alias list */
77 short s_port; /* port # */
78 char *s_proto; /* protocol to use */
81 typedef struct ws_netent
83 char *n_name; /* official name of net */
84 char **n_aliases; /* alias list */
85 short n_addrtype; /* net address type */
86 u_long n_net; /* network # */
93 typedef struct sockaddr ws_sockaddr;
95 typedef struct ws_fd_set32_struct
97 UINT fd_count; /* how many are SET? */
98 SOCKET fd_array[FD_SETSIZE]; /* an array of SOCKETs */
102 /* ws_fd_set operations */
104 INT WINAPI __WSAFDIsSet( SOCKET, ws_fd_set32 * );
106 #define __WS_FD_CLR(fd, set, cast) do { \
108 for (__i = 0; __i < ((cast*)(set))->fd_count ; __i++) \
110 if (((cast*)(set))->fd_array[__i] == fd) \
112 while (__i < ((cast*)(set))->fd_count-1) \
114 ((cast*)(set))->fd_array[__i] = \
115 ((cast*)(set))->fd_array[__i+1]; \
118 ((cast*)(set))->fd_count--; \
123 #define WS_FD_CLR(fd, set) __WS_FD_CLR((fd),(set), ws_fd_set32)
125 #define __WS_FD_SET(fd, set, cast) do { \
126 if (((cast*)(set))->fd_count < FD_SETSIZE) \
127 ((cast*)(set))->fd_array[((cast*)(set))->fd_count++]=(fd);\
129 #define WS_FD_SET(fd, set) __WS_FD_SET((fd),(set), ws_fd_set32)
130 #define WS_FD_ZERO(set) (((ws_fd_set32*)(set))->fd_count=0)
131 #define WS_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (ws_fd_set32*)(set))
134 * Internet address (old style... should be updated)
140 struct { BYTE s_b1,s_b2,s_b3,s_b4; } S_un_b;
141 struct { WORD s_w1,s_w2; } S_un_w;
144 #define ws_addr S_un.S_addr /* can be used for most tcp & ip code */
145 #define ws_host S_un.S_un_b.s_b2 /* host on imp */
146 #define ws_net S_un.S_un_b.s_b1 /* network */
147 #define ws_imp S_un.S_un_w.s_w2 /* imp */
148 #define ws_impno S_un.S_un_b.s_b4 /* imp # */
149 #define ws_lh S_un.S_un_b.s_b3 /* logical host */
152 struct ws_sockaddr_in
156 struct ws_in_addr sin_addr;
160 #define WSADESCRIPTION_LEN 256
161 #define WSASYS_STATUS_LEN 128
163 typedef struct WSAData {
166 char szDescription[WSADESCRIPTION_LEN+1];
167 char szSystemStatus[WSASYS_STATUS_LEN+1];
171 } WSADATA, *LPWSADATA;
176 * This is used instead of -1, since the
177 * SOCKET type is unsigned.
179 #define INVALID_SOCKET (~0)
180 #define SOCKET_ERROR (-1)
186 #define WS_SOCK_STREAM 1 /* stream socket */
187 #define WS_SOCK_DGRAM 2 /* datagram socket */
188 #define WS_SOCK_RAW 3 /* raw-protocol interface */
189 #define WS_SOCK_RDM 4 /* reliably-delivered message */
190 #define WS_SOCK_SEQPACKET 5 /* sequenced packet stream */
192 #define WS_SOL_SOCKET 0xffff
193 #define WS_IPPROTO_TCP 6
196 * Option flags per-socket.
198 #define WS_SO_DEBUG 0x0001 /* turn on debugging info recording */
199 #define WS_SO_ACCEPTCONN 0x0002 /* socket has had listen() */
200 #define WS_SO_REUSEADDR 0x0004 /* allow local address reuse */
201 #define WS_SO_KEEPALIVE 0x0008 /* keep connections alive */
202 #define WS_SO_DONTROUTE 0x0010 /* just use interface addresses */
203 #define WS_SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
204 #define WS_SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
205 #define WS_SO_LINGER 0x0080 /* linger on close if data present */
206 #define WS_SO_OOBINLINE 0x0100 /* leave received OOB data in line */
208 #define WS_SO_DONTLINGER (UINT)(~WS_SO_LINGER)
211 * Additional options.
213 #define WS_SO_SNDBUF 0x1001 /* send buffer size */
214 #define WS_SO_RCVBUF 0x1002 /* receive buffer size */
215 #define WS_SO_SNDLOWAT 0x1003 /* send low-water mark */
216 #define WS_SO_RCVLOWAT 0x1004 /* receive low-water mark */
217 #define WS_SO_SNDTIMEO 0x1005 /* send timeout */
218 #define WS_SO_RCVTIMEO 0x1006 /* receive timeout */
219 #define WS_SO_ERROR 0x1007 /* get error status and clear */
220 #define WS_SO_TYPE 0x1008 /* get socket type */
222 #define WS_IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
223 #define WS_IOC_VOID 0x20000000 /* no parameters */
224 #define WS_IOC_OUT 0x40000000 /* copy out parameters */
225 #define WS_IOC_IN 0x80000000 /* copy in parameters */
226 #define WS_IOC_INOUT (WS_IOC_IN|WS_IOC_OUT)
227 #define WS_IOR(x,y,t) (WS_IOC_OUT|(((UINT)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
228 #define WS_IOW(x,y,t) (WS_IOC_IN|(((UINT)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
230 /* IPPROTO_TCP options */
231 #define WS_TCP_NODELAY 1 /* do not apply nagle algorithm */
234 * Socket I/O flags (supported by spec 1.1)
237 #define WS_FIONREAD WS_IOR('f', 127, u_long)
238 #define WS_FIONBIO WS_IOW('f', 126, u_long)
240 #define WS_SIOCATMARK WS_IOR('s', 7, u_long)
243 * Maximum queue length specifiable by listen.
250 #ifndef MSG_DONTROUTE
251 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
253 #define MSG_MAXIOVLEN 16
256 #define MSG_PARTIAL 0x8000 /* partial send or recv (WSARecvEx) */
260 * Define constant based on rfc883, used by gethostbyxxxx() calls.
262 #define MAXGETHOSTSTRUCT 1024
265 * Define flags to be used with the WSAAsyncSelect() call.
267 #define FD_READ 0x00000001
268 #define FD_WRITE 0x00000002
269 #define FD_OOB 0x00000004
270 #define FD_ACCEPT 0x00000008
271 #define FD_CONNECT 0x00000010
272 #define FD_CLOSE 0x00000020
274 /* internal per-socket flags */
276 #define FD_WINE_LISTENING 0x10000000
277 #define FD_WINE_NONBLOCKING 0x20000000
278 #define FD_WINE_CONNECTED 0x40000000
279 #define FD_WINE_RAW 0x80000000
280 #define FD_WINE_SERVEVENT 0x01000000
281 #define FD_WINE_INTERNAL 0xFFFF0000
285 * All Windows Sockets error constants are biased by WSABASEERR from
288 #define WSABASEERR 10000
290 * Windows Sockets definitions of regular Microsoft C error constants
292 #define WSAEINTR (WSABASEERR+4)
293 #define WSAEBADF (WSABASEERR+9)
294 #define WSAEACCES (WSABASEERR+13)
295 #define WSAEFAULT (WSABASEERR+14)
296 #define WSAEINVAL (WSABASEERR+22)
297 #define WSAEMFILE (WSABASEERR+24)
300 * Windows Sockets definitions of regular Berkeley error constants
302 #define WSAEWOULDBLOCK (WSABASEERR+35)
303 #define WSAEINPROGRESS (WSABASEERR+36)
304 #define WSAEALREADY (WSABASEERR+37)
305 #define WSAENOTSOCK (WSABASEERR+38)
306 #define WSAEDESTADDRREQ (WSABASEERR+39)
307 #define WSAEMSGSIZE (WSABASEERR+40)
308 #define WSAEPROTOTYPE (WSABASEERR+41)
309 #define WSAENOPROTOOPT (WSABASEERR+42)
310 #define WSAEPROTONOSUPPORT (WSABASEERR+43)
311 #define WSAESOCKTNOSUPPORT (WSABASEERR+44)
312 #define WSAEOPNOTSUPP (WSABASEERR+45)
313 #define WSAEPFNOSUPPORT (WSABASEERR+46)
314 #define WSAEAFNOSUPPORT (WSABASEERR+47)
315 #define WSAEADDRINUSE (WSABASEERR+48)
316 #define WSAEADDRNOTAVAIL (WSABASEERR+49)
317 #define WSAENETDOWN (WSABASEERR+50)
318 #define WSAENETUNREACH (WSABASEERR+51)
319 #define WSAENETRESET (WSABASEERR+52)
320 #define WSAECONNABORTED (WSABASEERR+53)
321 #define WSAECONNRESET (WSABASEERR+54)
322 #define WSAENOBUFS (WSABASEERR+55)
323 #define WSAEISCONN (WSABASEERR+56)
324 #define WSAENOTCONN (WSABASEERR+57)
325 #define WSAESHUTDOWN (WSABASEERR+58)
326 #define WSAETOOMANYREFS (WSABASEERR+59)
327 #define WSAETIMEDOUT (WSABASEERR+60)
328 #define WSAECONNREFUSED (WSABASEERR+61)
329 #define WSAELOOP (WSABASEERR+62)
330 #define WSAENAMETOOLONG (WSABASEERR+63)
331 #define WSAEHOSTDOWN (WSABASEERR+64)
332 #define WSAEHOSTUNREACH (WSABASEERR+65)
333 #define WSAENOTEMPTY (WSABASEERR+66)
334 #define WSAEPROCLIM (WSABASEERR+67)
335 #define WSAEUSERS (WSABASEERR+68)
336 #define WSAEDQUOT (WSABASEERR+69)
337 #define WSAESTALE (WSABASEERR+70)
338 #define WSAEREMOTE (WSABASEERR+71)
341 * Extended Windows Sockets error constant definitions
343 #define WSASYSNOTREADY (WSABASEERR+91)
344 #define WSAVERNOTSUPPORTED (WSABASEERR+92)
345 #define WSANOTINITIALISED (WSABASEERR+93)
348 * Error return codes from gethostbyname() and gethostbyaddr()
349 * (when using the resolver). Note that these errors are
350 * retrieved via WSAGetLastError() and must therefore follow
351 * the rules for avoiding clashes with error numbers from
352 * specific implementations or language run-time systems.
353 * For this reason the codes are based at WSABASEERR+1001.
354 * Note also that [WSA]NO_ADDRESS is defined only for
355 * compatibility purposes.
358 /* #define h_errno WSAGetLastError() */
360 /* Authoritative Answer: Host not found */
361 #define WSAHOST_NOT_FOUND (WSABASEERR+1001)
363 /* Non-Authoritative: Host not found, or SERVERFAIL */
364 #define WSATRY_AGAIN (WSABASEERR+1002)
366 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
367 #define WSANO_RECOVERY (WSABASEERR+1003)
369 /* Valid name, no data record of requested type */
370 #define WSANO_DATA (WSABASEERR+1004)
372 /* no address, look for MX record */
373 #define WSANO_ADDRESS WSANO_DATA
375 /* Socket function prototypes */
381 /* Microsoft Windows Extension function prototypes */
383 int WINAPI closesocket(SOCKET s);
385 int WINAPI WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
386 void WINAPI WSASetLastError(INT iError);
387 INT WINAPI WSACleanup(void);
388 INT WINAPI WSAGetLastError(void);
389 BOOL WINAPI WSAIsBlocking(void);
390 INT WINAPI WSACancelBlockingCall(void);
391 INT WINAPI WSAUnhookBlockingHook(void);
392 FARPROC WINAPI WSASetBlockingHook(FARPROC lpBlockFunc);
393 HANDLE WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name, LPCSTR proto,
394 LPSTR sbuf, INT buflen);
395 HANDLE WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
396 LPCSTR proto, LPSTR sbuf, INT buflen);
397 HANDLE WINAPI WSAAsyncGetProtoByName(HWND hWnd, UINT uMsg,
398 LPCSTR name, LPSTR sbuf, INT buflen);
399 HANDLE WINAPI WSAAsyncGetProtoByNumber(HWND hWnd, UINT uMsg,
400 INT number, LPSTR sbuf, INT buflen);
401 HANDLE WINAPI WSAAsyncGetHostByName(HWND hWnd, UINT uMsg,
402 LPCSTR name, LPSTR sbuf, INT buflen);
403 HANDLE WINAPI WSAAsyncGetHostByAddr(HWND hWnd, UINT uMsg, LPCSTR addr,
404 INT len, INT type, LPSTR sbuf, INT buflen);
405 INT WINAPI WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
406 INT WINAPI WSAAsyncSelect(SOCKET s, HWND hWnd, UINT uMsg, LONG lEvent);
407 INT WINAPI WSARecvEx(SOCKET s, char *buf, INT len, INT *flags);
412 #define WS_AF_UNSPEC 0 /* unspecified */
413 #define WS_AF_UNIX 1 /* local to host (pipes, portals) */
414 #define WS_AF_INET 2 /* internetwork: UDP, TCP, etc. */
415 #define WS_AF_IMPLINK 3 /* arpanet imp addresses */
416 #define WS_AF_PUP 4 /* pup protocols: e.g. BSP */
417 #define WS_AF_CHAOS 5 /* mit CHAOS protocols */
418 #define WS_AF_NS 6 /* XEROX NS protocols */
419 #define WS_AF_IPX WS_AF_NS /* IPX protocols: IPX, SPX, etc. */
420 #define WS_AF_ISO 7 /* ISO protocols */
421 #define WS_AF_OSI AF_ISO /* OSI is ISO */
422 #define WS_AF_ECMA 8 /* european computer manufacturers */
423 #define WS_AF_DATAKIT 9 /* datakit protocols */
424 #define WS_AF_CCITT 10 /* CCITT protocols, X.25 etc */
425 #define WS_AF_SNA 11 /* IBM SNA */
426 #define WS_AF_DECnet 12 /* DECnet */
427 #define WS_AF_DLI 13 /* Direct data link interface */
428 #define WS_AF_LAT 14 /* LAT */
429 #define WS_AF_HYLINK 15 /* NSC Hyperchannel */
430 #define WS_AF_APPLETALK 16 /* AppleTalk */
431 #define WS_AF_NETBIOS 17 /* NetBios-style addresses */
432 #define WS_AF_VOICEVIEW 18 /* VoiceView */
433 #define WS_AF_FIREFOX 19 /* Protocols from Firefox */
434 #define WS_AF_UNKNOWN1 20 /* Somebody is using this! */
435 #define WS_AF_BAN 21 /* Banyan */
436 #define WS_AF_ATM 22 /* Native ATM Services */
437 #define WS_AF_INET6 23 /* Internetwork Version 6 */
438 #define WS_AF_CLUSTER 24 /* Microsoft Wolfpack */
439 #define WS_AF_12844 25 /* IEEE 1284.4 WG AF */
440 #define WS_AF_IRDA 26 /* IrDA */
449 /* Microsoft Windows Extended data types */
450 typedef struct sockaddr SOCKADDR, *PSOCKADDR, *LPSOCKADDR;
451 typedef struct sockaddr_in SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN;
452 typedef struct linger LINGER, *PLINGER, *LPLINGER;
453 typedef struct in_addr IN_ADDR, *PIN_ADDR, *LPIN_ADDR;
454 typedef struct ws_fd_set32_struct FD_SET, *PFD_SET, *LPFD_SET;
455 typedef struct hostent HOSTENT, *PHOSTENT, *LPHOSTENT;
456 typedef struct servent SERVENT, *PSERVENT, *LPSERVENT;
457 typedef struct protoent PROTOENT, *PPROTOENT, *LPPROTOENT;
458 typedef struct timeval TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
461 * Windows message parameter composition and decomposition
464 * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
465 * when constructing the response to a WSAAsyncGetXByY() routine.
467 #define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
469 * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
470 * when constructing the response to WSAAsyncSelect().
472 #define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
474 * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
475 * to extract the buffer length from the lParam in the response
478 #define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
480 * WSAGETASYNCERROR is intended for use by the Windows Sockets application
481 * to extract the error code from the lParam in the response
484 #define WSAGETASYNCERROR(lParam) HIWORD(lParam)
486 * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
487 * to extract the event code from the lParam in the response
488 * to a WSAAsyncSelect().
490 #define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
492 * WSAGETSELECTERROR is intended for use by the Windows Sockets application
493 * to extract the error code from the lParam in the response
494 * to a WSAAsyncSelect().
496 #define WSAGETSELECTERROR(lParam) HIWORD(lParam)
500 #endif /* defined(__cplusplus) */
502 #endif /* _WINSOCKAPI_ */