Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

905 lines
31 KiB

  1. /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
  2. *
  3. * This header file corresponds to version 1.1 of the Windows Sockets specification.
  4. *
  5. * This file includes parts which are Copyright (c) 1982-1986 Regents
  6. * of the University of California. All rights reserved. The
  7. * Berkeley Software License Agreement specifies the terms and
  8. * conditions for redistribution.
  9. *
  10. * Change log:
  11. *
  12. * Fri Apr 23 16:31:01 1993 Mark Towfiq (towfiq@Microdyne.COM)
  13. * New version from David Treadwell which adds extern "C" around
  14. * __WSAFDIsSet() and removes "const" from buf param of
  15. * WSAAsyncGetHostByAddr(). Added change log.
  16. *
  17. * Sat May 15 10:55:00 1993 David Treadwell (davidtr@microsoft.com)
  18. * Fix the IN_CLASSC macro to account for class-D multicasts.
  19. * Add AF_IPX == AF_NS.
  20. *
  21. */
  22. #ifndef _WINSOCKAPI_
  23. #define _WINSOCKAPI_
  24. /*
  25. * Pull in WINDOWS.H if necessary
  26. */
  27. #ifndef _INC_WINDOWS
  28. #include <windows.h>
  29. #endif /* _INC_WINDOWS */
  30. /*
  31. * Basic system type definitions, taken from the BSD file sys/types.h.
  32. */
  33. typedef unsigned char u_char;
  34. typedef unsigned short u_short;
  35. typedef unsigned int u_int;
  36. typedef unsigned long u_long;
  37. /*
  38. * The new type to be used in all
  39. * instances which refer to sockets.
  40. */
  41. typedef u_int SOCKET;
  42. /*
  43. * Select uses arrays of SOCKETs. These macros manipulate such
  44. * arrays. FD_SETSIZE may be defined by the user before including
  45. * this file, but the default here should be >= 64.
  46. *
  47. * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  48. * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
  49. */
  50. #ifndef FD_SETSIZE
  51. #define FD_SETSIZE 64
  52. #endif /* FD_SETSIZE */
  53. typedef struct fd_set {
  54. u_int fd_count; /* how many are SET? */
  55. SOCKET fd_array[FD_SETSIZE]; /* an array of SOCKETs */
  56. } fd_set;
  57. #ifdef __cplusplus
  58. extern "C" {
  59. #endif
  60. extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #define FD_CLR(fd, set) do { \
  65. u_int __i; \
  66. for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
  67. if (((fd_set FAR *)(set))->fd_array[__i] == fd) { \
  68. while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
  69. ((fd_set FAR *)(set))->fd_array[__i] = \
  70. ((fd_set FAR *)(set))->fd_array[__i+1]; \
  71. __i++; \
  72. } \
  73. ((fd_set FAR *)(set))->fd_count--; \
  74. break; \
  75. } \
  76. } \
  77. } while(0)
  78. #define FD_SET(fd, set) do { \
  79. if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
  80. ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=(fd);\
  81. } while(0)
  82. #define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
  83. #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set FAR *)(set))
  84. /*
  85. * Structure used in select() call, taken from the BSD file sys/time.h.
  86. */
  87. struct timeval {
  88. long tv_sec; /* seconds */
  89. long tv_usec; /* and microseconds */
  90. };
  91. /*
  92. * Operations on timevals.
  93. *
  94. * NB: timercmp does not work for >= or <=.
  95. */
  96. #define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
  97. #define timercmp(tvp, uvp, cmp) \
  98. ((tvp)->tv_sec cmp (uvp)->tv_sec || \
  99. (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
  100. #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
  101. /*
  102. * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
  103. *
  104. *
  105. * Ioctl's have the command encoded in the lower word,
  106. * and the size of any in or out parameters in the upper
  107. * word. The high 2 bits of the upper word are used
  108. * to encode the in/out status of the parameter; for now
  109. * we restrict parameters to at most 128 bytes.
  110. */
  111. #define IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
  112. #define IOC_VOID 0x20000000 /* no parameters */
  113. #define IOC_OUT 0x40000000 /* copy out parameters */
  114. #define IOC_IN 0x80000000 /* copy in parameters */
  115. #define IOC_INOUT (IOC_IN|IOC_OUT)
  116. /* 0x20000000 distinguishes new &
  117. old ioctl's */
  118. #define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
  119. #define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  120. #define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  121. #define FIONREAD _IOR('f', 127, u_long) /* get # bytes to read */
  122. #define FIONBIO _IOW('f', 126, u_long) /* set/clear non-blocking i/o */
  123. #define FIOASYNC _IOW('f', 125, u_long) /* set/clear async i/o */
  124. /* Socket I/O Controls */
  125. #define SIOCSHIWAT _IOW('s', 0, u_long) /* set high watermark */
  126. #define SIOCGHIWAT _IOR('s', 1, u_long) /* get high watermark */
  127. #define SIOCSLOWAT _IOW('s', 2, u_long) /* set low watermark */
  128. #define SIOCGLOWAT _IOR('s', 3, u_long) /* get low watermark */
  129. #define SIOCATMARK _IOR('s', 7, u_long) /* at oob mark? */
  130. /*
  131. * Structures returned by network data base library, taken from the
  132. * BSD file netdb.h. All addresses are supplied in host order, and
  133. * returned in network order (suitable for use in system calls).
  134. */
  135. struct hostent {
  136. char FAR * h_name; /* official name of host */
  137. char FAR * FAR * h_aliases; /* alias list */
  138. short h_addrtype; /* host address type */
  139. short h_length; /* length of address */
  140. char FAR * FAR * h_addr_list; /* list of addresses */
  141. #define h_addr h_addr_list[0] /* address, for backward compat */
  142. };
  143. /*
  144. * It is assumed here that a network number
  145. * fits in 32 bits.
  146. */
  147. struct netent {
  148. char FAR * n_name; /* official name of net */
  149. char FAR * FAR * n_aliases; /* alias list */
  150. short n_addrtype; /* net address type */
  151. u_long n_net; /* network # */
  152. };
  153. struct servent {
  154. char FAR * s_name; /* official service name */
  155. char FAR * FAR * s_aliases; /* alias list */
  156. short s_port; /* port # */
  157. char FAR * s_proto; /* protocol to use */
  158. };
  159. struct protoent {
  160. char FAR * p_name; /* official protocol name */
  161. char FAR * FAR * p_aliases; /* alias list */
  162. short p_proto; /* protocol # */
  163. };
  164. /*
  165. * Constants and structures defined by the internet system,
  166. * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
  167. */
  168. /*
  169. * Protocols
  170. */
  171. #define IPPROTO_IP 0 /* dummy for IP */
  172. #define IPPROTO_ICMP 1 /* control message protocol */
  173. #define IPPROTO_GGP 2 /* gateway^2 (deprecated) */
  174. #define IPPROTO_TCP 6 /* tcp */
  175. #define IPPROTO_PUP 12 /* pup */
  176. #define IPPROTO_UDP 17 /* user datagram protocol */
  177. #define IPPROTO_IDP 22 /* xns idp */
  178. #define IPPROTO_ND 77 /* UNOFFICIAL net disk proto */
  179. #define IPPROTO_RAW 255 /* raw IP packet */
  180. #define IPPROTO_MAX 256
  181. /*
  182. * Port/socket numbers: network standard functions
  183. */
  184. #define IPPORT_ECHO 7
  185. #define IPPORT_DISCARD 9
  186. #define IPPORT_SYSTAT 11
  187. #define IPPORT_DAYTIME 13
  188. #define IPPORT_NETSTAT 15
  189. #define IPPORT_FTP 21
  190. #define IPPORT_TELNET 23
  191. #define IPPORT_SMTP 25
  192. #define IPPORT_TIMESERVER 37
  193. #define IPPORT_NAMESERVER 42
  194. #define IPPORT_WHOIS 43
  195. #define IPPORT_MTP 57
  196. /*
  197. * Port/socket numbers: host specific functions
  198. */
  199. #define IPPORT_TFTP 69
  200. #define IPPORT_RJE 77
  201. #define IPPORT_FINGER 79
  202. #define IPPORT_TTYLINK 87
  203. #define IPPORT_SUPDUP 95
  204. /*
  205. * UNIX TCP sockets
  206. */
  207. #define IPPORT_EXECSERVER 512
  208. #define IPPORT_LOGINSERVER 513
  209. #define IPPORT_CMDSERVER 514
  210. #define IPPORT_EFSSERVER 520
  211. /*
  212. * UNIX UDP sockets
  213. */
  214. #define IPPORT_BIFFUDP 512
  215. #define IPPORT_WHOSERVER 513
  216. #define IPPORT_ROUTESERVER 520
  217. /* 520+1 also used */
  218. /*
  219. * Ports < IPPORT_RESERVED are reserved for
  220. * privileged processes (e.g. root).
  221. */
  222. #define IPPORT_RESERVED 1024
  223. /*
  224. * Link numbers
  225. */
  226. #define IMPLINK_IP 155
  227. #define IMPLINK_LOWEXPER 156
  228. #define IMPLINK_HIGHEXPER 158
  229. /*
  230. * Internet address (old style... should be updated)
  231. */
  232. struct in_addr {
  233. union {
  234. struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  235. struct { u_short s_w1,s_w2; } S_un_w;
  236. u_long S_addr;
  237. } S_un;
  238. #define s_addr S_un.S_addr
  239. /* can be used for most tcp & ip code */
  240. #define s_host S_un.S_un_b.s_b2
  241. /* host on imp */
  242. #define s_net S_un.S_un_b.s_b1
  243. /* network */
  244. #define s_imp S_un.S_un_w.s_w2
  245. /* imp */
  246. #define s_impno S_un.S_un_b.s_b4
  247. /* imp # */
  248. #define s_lh S_un.S_un_b.s_b3
  249. /* logical host */
  250. };
  251. /*
  252. * Definitions of bits in internet address integers.
  253. * On subnets, the decomposition of addresses to host and net parts
  254. * is done according to subnet mask, not the masks here.
  255. */
  256. #define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
  257. #define IN_CLASSA_NET 0xff000000
  258. #define IN_CLASSA_NSHIFT 24
  259. #define IN_CLASSA_HOST 0x00ffffff
  260. #define IN_CLASSA_MAX 128
  261. #define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000)
  262. #define IN_CLASSB_NET 0xffff0000
  263. #define IN_CLASSB_NSHIFT 16
  264. #define IN_CLASSB_HOST 0x0000ffff
  265. #define IN_CLASSB_MAX 65536
  266. #define IN_CLASSC(i) (((long)(i) & 0xe0000000) == 0xc0000000)
  267. #define IN_CLASSC_NET 0xffffff00
  268. #define IN_CLASSC_NSHIFT 8
  269. #define IN_CLASSC_HOST 0x000000ff
  270. #define INADDR_ANY (u_long)0x00000000
  271. #define INADDR_LOOPBACK 0x7f000001
  272. #define INADDR_BROADCAST (u_long)0xffffffff
  273. #define INADDR_NONE 0xffffffff
  274. /*
  275. * Socket address, internet style.
  276. */
  277. struct sockaddr_in {
  278. short sin_family;
  279. u_short sin_port;
  280. struct in_addr sin_addr;
  281. char sin_zero[8];
  282. };
  283. #define WSADESCRIPTION_LEN 256
  284. #define WSASYS_STATUS_LEN 128
  285. typedef struct WSAData {
  286. WORD wVersion;
  287. WORD wHighVersion;
  288. char szDescription[WSADESCRIPTION_LEN+1];
  289. char szSystemStatus[WSASYS_STATUS_LEN+1];
  290. unsigned short iMaxSockets;
  291. unsigned short iMaxUdpDg;
  292. char FAR * lpVendorInfo;
  293. } WSADATA;
  294. typedef WSADATA FAR *LPWSADATA;
  295. /*
  296. * Options for use with [gs]etsockopt at the IP level.
  297. */
  298. #define IP_OPTIONS 1 /* set/get IP per-packet options */
  299. #define IP_MULTICAST_IF 2 /* set/get IP multicast interface */
  300. #define IP_MULTICAST_TTL 3 /* set/get IP multicast timetolive */
  301. #define IP_MULTICAST_LOOP 4 /* set/get IP multicast loopback */
  302. #define IP_ADD_MEMBERSHIP 5 /* add an IP group membership */
  303. #define IP_DROP_MEMBERSHIP 6 /* drop an IP group membership */
  304. #define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */
  305. #define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
  306. #define IP_MAX_MEMBERSHIPS 20 /* per socket; must fit in one mbuf */
  307. /*
  308. * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
  309. */
  310. struct ip_mreq {
  311. struct in_addr imr_multiaddr; /* IP multicast address of group */
  312. struct in_addr imr_interface; /* local IP address of interface */
  313. };
  314. /*
  315. * Definitions related to sockets: types, address families, options,
  316. * taken from the BSD file sys/socket.h.
  317. */
  318. /*
  319. * This is used instead of -1, since the
  320. * SOCKET type is unsigned.
  321. */
  322. #define INVALID_SOCKET (SOCKET)(~0)
  323. #define SOCKET_ERROR (-1)
  324. /*
  325. * Types
  326. */
  327. #define SOCK_STREAM 1 /* stream socket */
  328. #define SOCK_DGRAM 2 /* datagram socket */
  329. #define SOCK_RAW 3 /* raw-protocol interface */
  330. #define SOCK_RDM 4 /* reliably-delivered message */
  331. #define SOCK_SEQPACKET 5 /* sequenced packet stream */
  332. /*
  333. * Option flags per-socket.
  334. */
  335. #define SO_DEBUG 0x0001 /* turn on debugging info recording */
  336. #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
  337. #define SO_REUSEADDR 0x0004 /* allow local address reuse */
  338. #define SO_KEEPALIVE 0x0008 /* keep connections alive */
  339. #define SO_DONTROUTE 0x0010 /* just use interface addresses */
  340. #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
  341. #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
  342. #define SO_LINGER 0x0080 /* linger on close if data present */
  343. #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
  344. #define SO_DONTLINGER (u_int)(~SO_LINGER)
  345. /*
  346. * Additional options.
  347. */
  348. #define SO_SNDBUF 0x1001 /* send buffer size */
  349. #define SO_RCVBUF 0x1002 /* receive buffer size */
  350. #define SO_SNDLOWAT 0x1003 /* send low-water mark */
  351. #define SO_RCVLOWAT 0x1004 /* receive low-water mark */
  352. #define SO_SNDTIMEO 0x1005 /* send timeout */
  353. #define SO_RCVTIMEO 0x1006 /* receive timeout */
  354. #define SO_ERROR 0x1007 /* get error status and clear */
  355. #define SO_TYPE 0x1008 /* get socket type */
  356. /*
  357. * Options for connect and disconnect data and options. Used only by
  358. * non-TCP/IP transports such as DECNet, OSI TP4, etc.
  359. */
  360. #define SO_CONNDATA 0x7000
  361. #define SO_CONNOPT 0x7001
  362. #define SO_DISCDATA 0x7002
  363. #define SO_DISCOPT 0x7003
  364. #define SO_CONNDATALEN 0x7004
  365. #define SO_CONNOPTLEN 0x7005
  366. #define SO_DISCDATALEN 0x7006
  367. #define SO_DISCOPTLEN 0x7007
  368. /*
  369. * Option for opening sockets for synchronous access.
  370. */
  371. #define SO_OPENTYPE 0x7008
  372. #define SO_SYNCHRONOUS_ALERT 0x10
  373. #define SO_SYNCHRONOUS_NONALERT 0x20
  374. /*
  375. * Other NT-specific options.
  376. */
  377. #define SO_MAXDG 0x7009
  378. #define SO_MAXPATHDG 0x700A
  379. /*
  380. * TCP options.
  381. */
  382. #define TCP_NODELAY 0x0001
  383. #define TCP_BSDURGENT 0x7000
  384. /*
  385. * Address families.
  386. */
  387. #define AF_UNSPEC 0 /* unspecified */
  388. #define AF_UNIX 1 /* local to host (pipes, portals) */
  389. #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
  390. #define AF_IMPLINK 3 /* arpanet imp addresses */
  391. #define AF_PUP 4 /* pup protocols: e.g. BSP */
  392. #define AF_CHAOS 5 /* mit CHAOS protocols */
  393. #define AF_IPX 6 /* IPX and SPX */
  394. #define AF_NS 6 /* XEROX NS protocols */
  395. #define AF_ISO 7 /* ISO protocols */
  396. #define AF_OSI AF_ISO /* OSI is ISO */
  397. #define AF_ECMA 8 /* european computer manufacturers */
  398. #define AF_DATAKIT 9 /* datakit protocols */
  399. #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
  400. #define AF_SNA 11 /* IBM SNA */
  401. #define AF_DECnet 12 /* DECnet */
  402. #define AF_DLI 13 /* Direct data link interface */
  403. #define AF_LAT 14 /* LAT */
  404. #define AF_HYLINK 15 /* NSC Hyperchannel */
  405. #define AF_APPLETALK 16 /* AppleTalk */
  406. #define AF_NETBIOS 17 /* NetBios-style addresses */
  407. #define AF_MAX 18
  408. /*
  409. * Structure used by kernel to store most
  410. * addresses.
  411. */
  412. struct sockaddr {
  413. u_short sa_family; /* address family */
  414. char sa_data[14]; /* up to 14 bytes of direct address */
  415. };
  416. /*
  417. * Structure used by kernel to pass protocol
  418. * information in raw sockets.
  419. */
  420. struct sockproto {
  421. u_short sp_family; /* address family */
  422. u_short sp_protocol; /* protocol */
  423. };
  424. /*
  425. * Protocol families, same as address families for now.
  426. */
  427. #define PF_UNSPEC AF_UNSPEC
  428. #define PF_UNIX AF_UNIX
  429. #define PF_INET AF_INET
  430. #define PF_IMPLINK AF_IMPLINK
  431. #define PF_PUP AF_PUP
  432. #define PF_CHAOS AF_CHAOS
  433. #define PF_NS AF_NS
  434. #define PF_IPX AF_IPX
  435. #define PF_ISO AF_ISO
  436. #define PF_OSI AF_OSI
  437. #define PF_ECMA AF_ECMA
  438. #define PF_DATAKIT AF_DATAKIT
  439. #define PF_CCITT AF_CCITT
  440. #define PF_SNA AF_SNA
  441. #define PF_DECnet AF_DECnet
  442. #define PF_DLI AF_DLI
  443. #define PF_LAT AF_LAT
  444. #define PF_HYLINK AF_HYLINK
  445. #define PF_APPLETALK AF_APPLETALK
  446. #define PF_MAX AF_MAX
  447. /*
  448. * Structure used for manipulating linger option.
  449. */
  450. struct linger {
  451. u_short l_onoff; /* option on/off */
  452. u_short l_linger; /* linger time */
  453. };
  454. /*
  455. * Level number for (get/set)sockopt() to apply to socket itself.
  456. */
  457. #define SOL_SOCKET 0xffff /* options for socket level */
  458. /*
  459. * Maximum queue length specifiable by listen.
  460. */
  461. #define SOMAXCONN 5
  462. #define MSG_OOB 0x1 /* process out-of-band data */
  463. #define MSG_PEEK 0x2 /* peek at incoming message */
  464. #define MSG_DONTROUTE 0x4 /* send without using routing tables */
  465. #define MSG_MAXIOVLEN 16
  466. #define MSG_PARTIAL 0x8000 /* partial send or recv for message xport */
  467. /*
  468. * Define constant based on rfc883, used by gethostbyxxxx() calls.
  469. */
  470. #define MAXGETHOSTSTRUCT 1024
  471. /*
  472. * Define flags to be used with the WSAAsyncSelect() call.
  473. */
  474. #define FD_READ 0x01
  475. #define FD_WRITE 0x02
  476. #define FD_OOB 0x04
  477. #define FD_ACCEPT 0x08
  478. #define FD_CONNECT 0x10
  479. #define FD_CLOSE 0x20
  480. /*
  481. * All Windows Sockets error constants are biased by WSABASEERR from
  482. * the "normal"
  483. */
  484. #define WSABASEERR 10000
  485. /*
  486. * Windows Sockets definitions of regular Microsoft C error constants
  487. */
  488. #define WSAEINTR (WSABASEERR+4)
  489. #define WSAEBADF (WSABASEERR+9)
  490. #define WSAEACCES (WSABASEERR+13)
  491. #define WSAEFAULT (WSABASEERR+14)
  492. #define WSAEINVAL (WSABASEERR+22)
  493. #define WSAEMFILE (WSABASEERR+24)
  494. /*
  495. * Windows Sockets definitions of regular Berkeley error constants
  496. */
  497. #define WSAEWOULDBLOCK (WSABASEERR+35)
  498. #define WSAEINPROGRESS (WSABASEERR+36)
  499. #define WSAEALREADY (WSABASEERR+37)
  500. #define WSAENOTSOCK (WSABASEERR+38)
  501. #define WSAEDESTADDRREQ (WSABASEERR+39)
  502. #define WSAEMSGSIZE (WSABASEERR+40)
  503. #define WSAEPROTOTYPE (WSABASEERR+41)
  504. #define WSAENOPROTOOPT (WSABASEERR+42)
  505. #define WSAEPROTONOSUPPORT (WSABASEERR+43)
  506. #define WSAESOCKTNOSUPPORT (WSABASEERR+44)
  507. #define WSAEOPNOTSUPP (WSABASEERR+45)
  508. #define WSAEPFNOSUPPORT (WSABASEERR+46)
  509. #define WSAEAFNOSUPPORT (WSABASEERR+47)
  510. #define WSAEADDRINUSE (WSABASEERR+48)
  511. #define WSAEADDRNOTAVAIL (WSABASEERR+49)
  512. #define WSAENETDOWN (WSABASEERR+50)
  513. #define WSAENETUNREACH (WSABASEERR+51)
  514. #define WSAENETRESET (WSABASEERR+52)
  515. #define WSAECONNABORTED (WSABASEERR+53)
  516. #define WSAECONNRESET (WSABASEERR+54)
  517. #define WSAENOBUFS (WSABASEERR+55)
  518. #define WSAEISCONN (WSABASEERR+56)
  519. #define WSAENOTCONN (WSABASEERR+57)
  520. #define WSAESHUTDOWN (WSABASEERR+58)
  521. #define WSAETOOMANYREFS (WSABASEERR+59)
  522. #define WSAETIMEDOUT (WSABASEERR+60)
  523. #define WSAECONNREFUSED (WSABASEERR+61)
  524. #define WSAELOOP (WSABASEERR+62)
  525. #define WSAENAMETOOLONG (WSABASEERR+63)
  526. #define WSAEHOSTDOWN (WSABASEERR+64)
  527. #define WSAEHOSTUNREACH (WSABASEERR+65)
  528. #define WSAENOTEMPTY (WSABASEERR+66)
  529. #define WSAEPROCLIM (WSABASEERR+67)
  530. #define WSAEUSERS (WSABASEERR+68)
  531. #define WSAEDQUOT (WSABASEERR+69)
  532. #define WSAESTALE (WSABASEERR+70)
  533. #define WSAEREMOTE (WSABASEERR+71)
  534. #define WSAEDISCON (WSABASEERR+101)
  535. /*
  536. * Extended Windows Sockets error constant definitions
  537. */
  538. #define WSASYSNOTREADY (WSABASEERR+91)
  539. #define WSAVERNOTSUPPORTED (WSABASEERR+92)
  540. #define WSANOTINITIALISED (WSABASEERR+93)
  541. /*
  542. * Error return codes from gethostbyname() and gethostbyaddr()
  543. * (when using the resolver). Note that these errors are
  544. * retrieved via WSAGetLastError() and must therefore follow
  545. * the rules for avoiding clashes with error numbers from
  546. * specific implementations or language run-time systems.
  547. * For this reason the codes are based at WSABASEERR+1001.
  548. * Note also that [WSA]NO_ADDRESS is defined only for
  549. * compatibility purposes.
  550. */
  551. #define h_errno WSAGetLastError()
  552. /* Authoritative Answer: Host not found */
  553. #define WSAHOST_NOT_FOUND (WSABASEERR+1001)
  554. #define HOST_NOT_FOUND WSAHOST_NOT_FOUND
  555. /* Non-Authoritative: Host not found, or SERVERFAIL */
  556. #define WSATRY_AGAIN (WSABASEERR+1002)
  557. #define TRY_AGAIN WSATRY_AGAIN
  558. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  559. #define WSANO_RECOVERY (WSABASEERR+1003)
  560. #define NO_RECOVERY WSANO_RECOVERY
  561. /* Valid name, no data record of requested type */
  562. #define WSANO_DATA (WSABASEERR+1004)
  563. #define NO_DATA WSANO_DATA
  564. /* no address, look for MX record */
  565. #define WSANO_ADDRESS WSANO_DATA
  566. #define NO_ADDRESS WSANO_ADDRESS
  567. /*
  568. * Windows Sockets errors redefined as regular Berkeley error constants.
  569. * These are commented out in Windows NT to avoid conflicts with errno.h.
  570. * Use the WSA constants instead.
  571. */
  572. #if 0
  573. #define EWOULDBLOCK WSAEWOULDBLOCK
  574. #define EINPROGRESS WSAEINPROGRESS
  575. #define EALREADY WSAEALREADY
  576. #define ENOTSOCK WSAENOTSOCK
  577. #define EDESTADDRREQ WSAEDESTADDRREQ
  578. #define EMSGSIZE WSAEMSGSIZE
  579. #define EPROTOTYPE WSAEPROTOTYPE
  580. #define ENOPROTOOPT WSAENOPROTOOPT
  581. #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
  582. #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
  583. #define EOPNOTSUPP WSAEOPNOTSUPP
  584. #define EPFNOSUPPORT WSAEPFNOSUPPORT
  585. #define EAFNOSUPPORT WSAEAFNOSUPPORT
  586. #define EADDRINUSE WSAEADDRINUSE
  587. #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
  588. #define ENETDOWN WSAENETDOWN
  589. #define ENETUNREACH WSAENETUNREACH
  590. #define ENETRESET WSAENETRESET
  591. #define ECONNABORTED WSAECONNABORTED
  592. #define ECONNRESET WSAECONNRESET
  593. #define ENOBUFS WSAENOBUFS
  594. #define EISCONN WSAEISCONN
  595. #define ENOTCONN WSAENOTCONN
  596. #define ESHUTDOWN WSAESHUTDOWN
  597. #define ETOOMANYREFS WSAETOOMANYREFS
  598. #define ETIMEDOUT WSAETIMEDOUT
  599. #define ECONNREFUSED WSAECONNREFUSED
  600. #define ELOOP WSAELOOP
  601. #define ENAMETOOLONG WSAENAMETOOLONG
  602. #define EHOSTDOWN WSAEHOSTDOWN
  603. #define EHOSTUNREACH WSAEHOSTUNREACH
  604. #define ENOTEMPTY WSAENOTEMPTY
  605. #define EPROCLIM WSAEPROCLIM
  606. #define EUSERS WSAEUSERS
  607. #define EDQUOT WSAEDQUOT
  608. #define ESTALE WSAESTALE
  609. #define EREMOTE WSAEREMOTE
  610. #endif
  611. /* Socket function prototypes */
  612. #ifdef __cplusplus
  613. extern "C" {
  614. #endif
  615. SOCKET PASCAL FAR accept (SOCKET s, struct sockaddr FAR *addr,
  616. int FAR *addrlen);
  617. int PASCAL FAR bind (SOCKET s, const struct sockaddr FAR *addr, int namelen);
  618. int PASCAL FAR closesocket (SOCKET s);
  619. int PASCAL FAR connect (SOCKET s, const struct sockaddr FAR *name, int namelen);
  620. int PASCAL FAR ioctlsocket (SOCKET s, long cmd, u_long FAR *argp);
  621. int PASCAL FAR getpeername (SOCKET s, struct sockaddr FAR *name,
  622. int FAR * namelen);
  623. int PASCAL FAR getsockname (SOCKET s, struct sockaddr FAR *name,
  624. int FAR * namelen);
  625. int PASCAL FAR getsockopt (SOCKET s, int level, int optname,
  626. char FAR * optval, int FAR *optlen);
  627. u_long PASCAL FAR htonl (u_long hostlong);
  628. u_short PASCAL FAR htons (u_short hostshort);
  629. unsigned long PASCAL FAR inet_addr (const char FAR * cp);
  630. char FAR * PASCAL FAR inet_ntoa (struct in_addr in);
  631. int PASCAL FAR listen (SOCKET s, int backlog);
  632. u_long PASCAL FAR ntohl (u_long netlong);
  633. u_short PASCAL FAR ntohs (u_short netshort);
  634. int PASCAL FAR recv (SOCKET s, char FAR * buf, int len, int flags);
  635. int PASCAL FAR recvfrom (SOCKET s, char FAR * buf, int len, int flags,
  636. struct sockaddr FAR *from, int FAR * fromlen);
  637. int PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set FAR *writefds,
  638. fd_set FAR *exceptfds, const struct timeval FAR *timeout);
  639. int PASCAL FAR send (SOCKET s, const char FAR * buf, int len, int flags);
  640. int PASCAL FAR sendto (SOCKET s, const char FAR * buf, int len, int flags,
  641. const struct sockaddr FAR *to, int tolen);
  642. int PASCAL FAR setsockopt (SOCKET s, int level, int optname,
  643. const char FAR * optval, int optlen);
  644. int PASCAL FAR shutdown (SOCKET s, int how);
  645. SOCKET PASCAL FAR socket (int af, int type, int protocol);
  646. /* Database function prototypes */
  647. struct hostent FAR * PASCAL FAR gethostbyaddr(const char FAR * addr,
  648. int len, int type);
  649. struct hostent FAR * PASCAL FAR gethostbyname(const char FAR * name);
  650. int PASCAL FAR gethostname (char FAR * name, int namelen);
  651. struct servent FAR * PASCAL FAR getservbyport(int port, const char FAR * proto);
  652. struct servent FAR * PASCAL FAR getservbyname(const char FAR * name,
  653. const char FAR * proto);
  654. struct protoent FAR * PASCAL FAR getprotobynumber(int proto);
  655. struct protoent FAR * PASCAL FAR getprotobyname(const char FAR * name);
  656. /* Microsoft Windows Extension function prototypes */
  657. int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
  658. int PASCAL FAR WSACleanup(void);
  659. void PASCAL FAR WSASetLastError(int iError);
  660. int PASCAL FAR WSAGetLastError(void);
  661. BOOL PASCAL FAR WSAIsBlocking(void);
  662. int PASCAL FAR WSAUnhookBlockingHook(void);
  663. FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc);
  664. int PASCAL FAR WSACancelBlockingCall(void);
  665. HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
  666. const char FAR * name,
  667. const char FAR * proto,
  668. char FAR * buf, int buflen);
  669. HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
  670. const char FAR * proto, char FAR * buf,
  671. int buflen);
  672. HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
  673. const char FAR * name, char FAR * buf,
  674. int buflen);
  675. HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
  676. int number, char FAR * buf,
  677. int buflen);
  678. HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
  679. const char FAR * name, char FAR * buf,
  680. int buflen);
  681. HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
  682. const char FAR * addr, int len, int type,
  683. char FAR * buf, int buflen);
  684. int PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
  685. int PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
  686. long lEvent);
  687. int PASCAL FAR WSARecvEx (SOCKET s, char FAR * buf, int len, int FAR *flags);
  688. #ifdef __cplusplus
  689. }
  690. #endif
  691. /* Microsoft Windows Extended data types */
  692. typedef struct sockaddr SOCKADDR;
  693. typedef struct sockaddr *PSOCKADDR;
  694. typedef struct sockaddr FAR *LPSOCKADDR;
  695. typedef struct sockaddr_in SOCKADDR_IN;
  696. typedef struct sockaddr_in *PSOCKADDR_IN;
  697. typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
  698. typedef struct linger LINGER;
  699. typedef struct linger *PLINGER;
  700. typedef struct linger FAR *LPLINGER;
  701. typedef struct in_addr IN_ADDR;
  702. typedef struct in_addr *PIN_ADDR;
  703. typedef struct in_addr FAR *LPIN_ADDR;
  704. typedef struct fd_set FD_SET;
  705. typedef struct fd_set *PFD_SET;
  706. typedef struct fd_set FAR *LPFD_SET;
  707. typedef struct hostent HOSTENT;
  708. typedef struct hostent *PHOSTENT;
  709. typedef struct hostent FAR *LPHOSTENT;
  710. typedef struct servent SERVENT;
  711. typedef struct servent *PSERVENT;
  712. typedef struct servent FAR *LPSERVENT;
  713. typedef struct protoent PROTOENT;
  714. typedef struct protoent *PPROTOENT;
  715. typedef struct protoent FAR *LPPROTOENT;
  716. typedef struct timeval TIMEVAL;
  717. typedef struct timeval *PTIMEVAL;
  718. typedef struct timeval FAR *LPTIMEVAL;
  719. /*
  720. * Windows message parameter composition and decomposition
  721. * macros.
  722. *
  723. * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  724. * when constructing the response to a WSAAsyncGetXByY() routine.
  725. */
  726. #define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
  727. /*
  728. * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  729. * when constructing the response to WSAAsyncSelect().
  730. */
  731. #define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
  732. /*
  733. * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  734. * to extract the buffer length from the lParam in the response
  735. * to a WSAGetXByY().
  736. */
  737. #define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
  738. /*
  739. * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  740. * to extract the error code from the lParam in the response
  741. * to a WSAGetXByY().
  742. */
  743. #define WSAGETASYNCERROR(lParam) HIWORD(lParam)
  744. /*
  745. * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  746. * to extract the event code from the lParam in the response
  747. * to a WSAAsyncSelect().
  748. */
  749. #define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
  750. /*
  751. * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  752. * to extract the error code from the lParam in the response
  753. * to a WSAAsyncSelect().
  754. */
  755. #define WSAGETSELECTERROR(lParam) HIWORD(lParam)
  756. #endif /* _WINSOCKAPI_ */
  757.