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>
13 /* Solaris uses these macro names */
16 #include <netinet/in.h>
17 /* Restore the Windows values */
27 #ifdef HAVE_ARPA_INET_H
28 #include <arpa/inet.h>
29 #endif /* HAVE_ARPA_INET_H */
34 #endif /* HAVE_NETDB_H */
35 #ifdef HAVE_SYS_SOCKET_H
36 #include <sys/socket.h>
37 #endif /* HAVE_SYS_SOCKET_H */
38 #include <sys/ioctl.h>
39 #endif /* RC_INVOKED */
45 #endif /* defined(__cplusplus) */
47 /* no "forced" alignment of ws_XXXXent here ! */
49 typedef struct ws_hostent
51 char *h_name; /* official name of host */
52 char **h_aliases; /* alias list */
53 short h_addrtype; /* host address type */
54 short h_length; /* length of address */
55 char **h_addr_list; /* list of addresses from name server */
58 typedef struct ws_protoent
60 char *p_name; /* official protocol name */
61 char **p_aliases; /* alias list */
62 short p_proto; /* protocol # */
65 typedef struct ws_servent
67 char *s_name; /* official service name */
68 char **s_aliases; /* alias list */
69 short s_port; /* port # */
70 char *s_proto; /* protocol to use */
73 typedef struct ws_netent
75 char *n_name; /* official name of net */
76 char **n_aliases; /* alias list */
77 short n_addrtype; /* net address type */
78 u_long n_net; /* network # */
85 typedef struct sockaddr ws_sockaddr;
87 typedef struct ws_fd_set32_struct
89 UINT fd_count; /* how many are SET? */
90 SOCKET fd_array[FD_SETSIZE]; /* an array of SOCKETs */
94 /* ws_fd_set operations */
96 INT WINAPI __WSAFDIsSet( SOCKET, ws_fd_set32 * );
98 #define __WS_FD_CLR(fd, set, cast) do { \
100 for (__i = 0; __i < ((cast*)(set))->fd_count ; __i++) \
102 if (((cast*)(set))->fd_array[__i] == fd) \
104 while (__i < ((cast*)(set))->fd_count-1) \
106 ((cast*)(set))->fd_array[__i] = \
107 ((cast*)(set))->fd_array[__i+1]; \
110 ((cast*)(set))->fd_count--; \
115 #define WS_FD_CLR(fd, set) __WS_FD_CLR((fd),(set), ws_fd_set32)
117 #define __WS_FD_SET(fd, set, cast) do { \
118 if (((cast*)(set))->fd_count < FD_SETSIZE) \
119 ((cast*)(set))->fd_array[((cast*)(set))->fd_count++]=(fd);\
121 #define WS_FD_SET(fd, set) __WS_FD_SET((fd),(set), ws_fd_set32)
122 #define WS_FD_ZERO(set) (((ws_fd_set32*)(set))->fd_count=0)
123 #define WS_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (ws_fd_set32*)(set))
126 * Internet address (old style... should be updated)
132 struct { BYTE s_b1,s_b2,s_b3,s_b4; } S_un_b;
133 struct { WORD s_w1,s_w2; } S_un_w;
136 #define ws_addr S_un.S_addr /* can be used for most tcp & ip code */
137 #define ws_host S_un.S_un_b.s_b2 /* host on imp */
138 #define ws_net S_un.S_un_b.s_b1 /* network */
139 #define ws_imp S_un.S_un_w.s_w2 /* imp */
140 #define ws_impno S_un.S_un_b.s_b4 /* imp # */
141 #define ws_lh S_un.S_un_b.s_b3 /* logical host */
144 struct ws_sockaddr_in
148 struct ws_in_addr sin_addr;
152 #define WSADESCRIPTION_LEN 256
153 #define WSASYS_STATUS_LEN 128
155 typedef struct WSAData {
158 char szDescription[WSADESCRIPTION_LEN+1];
159 char szSystemStatus[WSASYS_STATUS_LEN+1];
163 } WSADATA, *LPWSADATA;
168 * This is used instead of -1, since the
169 * SOCKET type is unsigned.
171 #define INVALID_SOCKET (~0)
172 #define SOCKET_ERROR (-1)
178 #define WS_SOCK_STREAM 1 /* stream socket */
179 #define WS_SOCK_DGRAM 2 /* datagram socket */
180 #define WS_SOCK_RAW 3 /* raw-protocol interface */
181 #define WS_SOCK_RDM 4 /* reliably-delivered message */
182 #define WS_SOCK_SEQPACKET 5 /* sequenced packet stream */
184 #define WS_SOL_SOCKET 0xffff
185 #define WS_IPPROTO_TCP 6
188 * Option flags per-socket.
190 #define WS_SO_DEBUG 0x0001 /* turn on debugging info recording */
191 #define WS_SO_ACCEPTCONN 0x0002 /* socket has had listen() */
192 #define WS_SO_REUSEADDR 0x0004 /* allow local address reuse */
193 #define WS_SO_KEEPALIVE 0x0008 /* keep connections alive */
194 #define WS_SO_DONTROUTE 0x0010 /* just use interface addresses */
195 #define WS_SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
196 #define WS_SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
197 #define WS_SO_LINGER 0x0080 /* linger on close if data present */
198 #define WS_SO_OOBINLINE 0x0100 /* leave received OOB data in line */
200 #define WS_SO_DONTLINGER (UINT)(~WS_SO_LINGER)
203 * Additional options.
205 #define WS_SO_SNDBUF 0x1001 /* send buffer size */
206 #define WS_SO_RCVBUF 0x1002 /* receive buffer size */
207 #define WS_SO_SNDLOWAT 0x1003 /* send low-water mark */
208 #define WS_SO_RCVLOWAT 0x1004 /* receive low-water mark */
209 #define WS_SO_SNDTIMEO 0x1005 /* send timeout */
210 #define WS_SO_RCVTIMEO 0x1006 /* receive timeout */
211 #define WS_SO_ERROR 0x1007 /* get error status and clear */
212 #define WS_SO_TYPE 0x1008 /* get socket type */
214 #define WS_IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
215 #define WS_IOC_VOID 0x20000000 /* no parameters */
216 #define WS_IOC_OUT 0x40000000 /* copy out parameters */
217 #define WS_IOC_IN 0x80000000 /* copy in parameters */
218 #define WS_IOC_INOUT (WS_IOC_IN|WS_IOC_OUT)
219 #define WS_IOR(x,y,t) (WS_IOC_OUT|(((UINT)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
220 #define WS_IOW(x,y,t) (WS_IOC_IN|(((UINT)sizeof(t)&WS_IOCPARM_MASK)<<16)|((x)<<8)|(y))
222 /* IPPROTO_TCP options */
223 #define WS_TCP_NODELAY 1 /* do not apply nagle algorithm */
226 * Socket I/O flags (supported by spec 1.1)
229 #define WS_FIONREAD WS_IOR('f', 127, u_long)
230 #define WS_FIONBIO WS_IOW('f', 126, u_long)
232 #define WS_SIOCATMARK WS_IOR('s', 7, u_long)
235 * Maximum queue length specifiable by listen.
242 #ifndef MSG_DONTROUTE
243 #define MSG_DONTROUTE 0x4 /* send without using routing tables */
245 #define MSG_MAXIOVLEN 16
248 #define MSG_PARTIAL 0x8000 /* partial send or recv (WSARecvEx) */
252 * Define constant based on rfc883, used by gethostbyxxxx() calls.
254 #define MAXGETHOSTSTRUCT 1024
257 * Define flags to be used with the WSAAsyncSelect() call.
259 #define FD_READ WS_FD_READ
260 #define FD_WRITE WS_FD_WRITE
261 #define FD_OOB WS_FD_OOB
262 #define FD_ACCEPT WS_FD_ACCEPT
263 #define FD_CONNECT WS_FD_CONNECT
264 #define FD_CLOSE WS_FD_CLOSE
265 #define WS_FD_READ 0x0001
266 #define WS_FD_WRITE 0x0002
267 #define WS_FD_OOB 0x0004
268 #define WS_FD_ACCEPT 0x0008
269 #define WS_FD_CONNECT 0x0010
270 #define WS_FD_CLOSE 0x0020
272 #define WS_FD_LISTENING 0x10000000 /* internal per-socket flags */
273 #define WS_FD_NONBLOCKING 0x20000000
274 #define WS_FD_CONNECTED 0x40000000
275 #define WS_FD_RAW 0x80000000
276 #define WS_FD_SERVEVENT 0x01000000
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 int WINAPI closesocket(SOCKET s);
380 INT WINAPI WSAStartup(UINT wVersionRequired, LPWSADATA lpWSAData);
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 INT WINAPI WSAUnhookBlockingHook(void);
387 FARPROC WINAPI WSASetBlockingHook(FARPROC lpBlockFunc);
388 HANDLE WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name, LPCSTR proto,
389 LPSTR sbuf, INT buflen);
390 HANDLE WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
391 LPCSTR proto, LPSTR sbuf, INT buflen);
392 HANDLE WINAPI WSAAsyncGetProtoByName(HWND hWnd, UINT uMsg,
393 LPCSTR name, LPSTR sbuf, INT buflen);
394 HANDLE WINAPI WSAAsyncGetProtoByNumber(HWND hWnd, UINT uMsg,
395 INT number, LPSTR sbuf, INT buflen);
396 HANDLE WINAPI WSAAsyncGetHostByName(HWND hWnd, UINT uMsg,
397 LPCSTR name, LPSTR sbuf, INT buflen);
398 HANDLE WINAPI WSAAsyncGetHostByAddr(HWND hWnd, UINT uMsg, LPCSTR addr,
399 INT len, INT type, LPSTR sbuf, INT buflen);
400 INT WINAPI WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
401 INT WINAPI WSAAsyncSelect(SOCKET s, HWND hWnd, UINT uMsg, LONG lEvent);
402 INT WINAPI WSARecvEx(SOCKET s, char *buf, INT len, INT *flags);
407 #define WS_AF_UNSPEC 0 /* unspecified */
408 #define WS_AF_UNIX 1 /* local to host (pipes, portals) */
409 #define WS_AF_INET 2 /* internetwork: UDP, TCP, etc. */
410 #define WS_AF_IMPLINK 3 /* arpanet imp addresses */
411 #define WS_AF_PUP 4 /* pup protocols: e.g. BSP */
412 #define WS_AF_CHAOS 5 /* mit CHAOS protocols */
413 #define WS_AF_NS 6 /* XEROX NS protocols */
414 #define WS_AF_IPX WS_AF_NS /* IPX protocols: IPX, SPX, etc. */
415 #define WS_AF_ISO 7 /* ISO protocols */
416 #define WS_AF_OSI AF_ISO /* OSI is ISO */
417 #define WS_AF_ECMA 8 /* european computer manufacturers */
418 #define WS_AF_DATAKIT 9 /* datakit protocols */
419 #define WS_AF_CCITT 10 /* CCITT protocols, X.25 etc */
420 #define WS_AF_SNA 11 /* IBM SNA */
421 #define WS_AF_DECnet 12 /* DECnet */
422 #define WS_AF_DLI 13 /* Direct data link interface */
423 #define WS_AF_LAT 14 /* LAT */
424 #define WS_AF_HYLINK 15 /* NSC Hyperchannel */
425 #define WS_AF_APPLETALK 16 /* AppleTalk */
426 #define WS_AF_NETBIOS 17 /* NetBios-style addresses */
427 #define WS_AF_VOICEVIEW 18 /* VoiceView */
428 #define WS_AF_FIREFOX 19 /* Protocols from Firefox */
429 #define WS_AF_UNKNOWN1 20 /* Somebody is using this! */
430 #define WS_AF_BAN 21 /* Banyan */
431 #define WS_AF_ATM 22 /* Native ATM Services */
432 #define WS_AF_INET6 23 /* Internetwork Version 6 */
433 #define WS_AF_CLUSTER 24 /* Microsoft Wolfpack */
434 #define WS_AF_12844 25 /* IEEE 1284.4 WG AF */
435 #define WS_AF_IRDA 26 /* IrDA */
439 #include "pshpack1.h"
441 struct ws_sockaddr_ipx
455 /* Microsoft Windows Extended data types */
456 typedef struct sockaddr SOCKADDR, *PSOCKADDR, *LPSOCKADDR;
457 typedef struct sockaddr_in SOCKADDR_IN, *PSOCKADDR_IN, *LPSOCKADDR_IN;
458 typedef struct linger LINGER, *PLINGER, *LPLINGER;
459 typedef struct in_addr IN_ADDR, *PIN_ADDR, *LPIN_ADDR;
460 typedef struct ws_fd_set32_struct FD_SET, *PFD_SET, *LPFD_SET;
461 typedef struct hostent HOSTENT, *PHOSTENT, *LPHOSTENT;
462 typedef struct servent SERVENT, *PSERVENT, *LPSERVENT;
463 typedef struct protoent PROTOENT, *PPROTOENT, *LPPROTOENT;
464 typedef struct timeval TIMEVAL, *PTIMEVAL, *LPTIMEVAL;
467 * Windows message parameter composition and decomposition
470 * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
471 * when constructing the response to a WSAAsyncGetXByY() routine.
473 #define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
475 * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
476 * when constructing the response to WSAAsyncSelect().
478 #define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
480 * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
481 * to extract the buffer length from the lParam in the response
484 #define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
486 * WSAGETASYNCERROR is intended for use by the Windows Sockets application
487 * to extract the error code from the lParam in the response
490 #define WSAGETASYNCERROR(lParam) HIWORD(lParam)
492 * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
493 * to extract the event code from the lParam in the response
494 * to a WSAAsyncSelect().
496 #define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
498 * WSAGETSELECTERROR is intended for use by the Windows Sockets application
499 * to extract the error code from the lParam in the response
500 * to a WSAAsyncSelect().
502 #define WSAGETSELECTERROR(lParam) HIWORD(lParam)
506 #endif /* defined(__cplusplus) */
508 #endif /* _WINSOCKAPI_ */