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.

873 lines
30 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. /*
  300. * Definitions related to sockets: types, address families, options,
  301. * taken from the BSD file sys/socket.h.
  302. */
  303. /*
  304. * This is used instead of -1, since the
  305. * SOCKET type is unsigned.
  306. */
  307. #define INVALID_SOCKET (SOCKET)(~0)
  308. #define SOCKET_ERROR (-1)
  309. /*
  310. * Types
  311. */
  312. #define SOCK_STREAM 1 /* stream socket */
  313. #define SOCK_DGRAM 2 /* datagram socket */
  314. #define SOCK_RAW 3 /* raw-protocol interface */
  315. #define SOCK_RDM 4 /* reliably-delivered message */
  316. #define SOCK_SEQPACKET 5 /* sequenced packet stream */
  317. /*
  318. * Option flags per-socket.
  319. */
  320. #define SO_DEBUG 0x0001 /* turn on debugging info recording */
  321. #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
  322. #define SO_REUSEADDR 0x0004 /* allow local address reuse */
  323. #define SO_KEEPALIVE 0x0008 /* keep connections alive */
  324. #define SO_DONTROUTE 0x0010 /* just use interface addresses */
  325. #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
  326. #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
  327. #define SO_LINGER 0x0080 /* linger on close if data present */
  328. #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
  329. #define SO_DONTLINGER (u_int)(~SO_LINGER)
  330. /*
  331. * Additional options.
  332. */
  333. #define SO_SNDBUF 0x1001 /* send buffer size */
  334. #define SO_RCVBUF 0x1002 /* receive buffer size */
  335. #define SO_SNDLOWAT 0x1003 /* send low-water mark */
  336. #define SO_RCVLOWAT 0x1004 /* receive low-water mark */
  337. #define SO_SNDTIMEO 0x1005 /* send timeout */
  338. #define SO_RCVTIMEO 0x1006 /* receive timeout */
  339. #define SO_ERROR 0x1007 /* get error status and clear */
  340. #define SO_TYPE 0x1008 /* get socket type */
  341. /*
  342. * Options for connect and disconnect data and options. Used only by
  343. * non-TCP/IP transports such as DECNet, OSI TP4, etc.
  344. */
  345. #define SO_CONNDATA 0x7000
  346. #define SO_CONNOPT 0x7001
  347. #define SO_DISCDATA 0x7002
  348. #define SO_DISCOPT 0x7003
  349. #define SO_CONNDATALEN 0x7004
  350. #define SO_CONNOPTLEN 0x7005
  351. #define SO_DISCDATALEN 0x7006
  352. #define SO_DISCOPTLEN 0x7007
  353. /*
  354. * TCP options.
  355. */
  356. #define TCP_NODELAY 0x0001
  357. /*
  358. * Address families.
  359. */
  360. #define AF_UNSPEC 0 /* unspecified */
  361. #define AF_UNIX 1 /* local to host (pipes, portals) */
  362. #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
  363. #define AF_IMPLINK 3 /* arpanet imp addresses */
  364. #define AF_PUP 4 /* pup protocols: e.g. BSP */
  365. #define AF_CHAOS 5 /* mit CHAOS protocols */
  366. #define AF_IPX 6 /* IPX and SPX */
  367. #define AF_NS 6 /* XEROX NS protocols */
  368. #define AF_ISO 7 /* ISO protocols */
  369. #define AF_OSI AF_ISO /* OSI is ISO */
  370. #define AF_ECMA 8 /* european computer manufacturers */
  371. #define AF_DATAKIT 9 /* datakit protocols */
  372. #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
  373. #define AF_SNA 11 /* IBM SNA */
  374. #define AF_DECnet 12 /* DECnet */
  375. #define AF_DLI 13 /* Direct data link interface */
  376. #define AF_LAT 14 /* LAT */
  377. #define AF_HYLINK 15 /* NSC Hyperchannel */
  378. #define AF_APPLETALK 16 /* AppleTalk */
  379. #define AF_NETBIOS 17 /* NetBios-style addresses */
  380. #define AF_MAX 18
  381. /*
  382. * Structure used by kernel to store most
  383. * addresses.
  384. */
  385. struct sockaddr {
  386. u_short sa_family; /* address family */
  387. char sa_data[14]; /* up to 14 bytes of direct address */
  388. };
  389. /*
  390. * Structure used by kernel to pass protocol
  391. * information in raw sockets.
  392. */
  393. struct sockproto {
  394. u_short sp_family; /* address family */
  395. u_short sp_protocol; /* protocol */
  396. };
  397. /*
  398. * Protocol families, same as address families for now.
  399. */
  400. #define PF_UNSPEC AF_UNSPEC
  401. #define PF_UNIX AF_UNIX
  402. #define PF_INET AF_INET
  403. #define PF_IMPLINK AF_IMPLINK
  404. #define PF_PUP AF_PUP
  405. #define PF_CHAOS AF_CHAOS
  406. #define PF_NS AF_NS
  407. #define PF_IPX AF_IPX
  408. #define PF_ISO AF_ISO
  409. #define PF_OSI AF_OSI
  410. #define PF_ECMA AF_ECMA
  411. #define PF_DATAKIT AF_DATAKIT
  412. #define PF_CCITT AF_CCITT
  413. #define PF_SNA AF_SNA
  414. #define PF_DECnet AF_DECnet
  415. #define PF_DLI AF_DLI
  416. #define PF_LAT AF_LAT
  417. #define PF_HYLINK AF_HYLINK
  418. #define PF_APPLETALK AF_APPLETALK
  419. #define PF_MAX AF_MAX
  420. /*
  421. * Structure used for manipulating linger option.
  422. */
  423. struct linger {
  424. u_short l_onoff; /* option on/off */
  425. u_short l_linger; /* linger time */
  426. };
  427. /*
  428. * Level number for (get/set)sockopt() to apply to socket itself.
  429. */
  430. #define SOL_SOCKET 0xffff /* options for socket level */
  431. /*
  432. * Maximum queue length specifiable by listen.
  433. */
  434. #define SOMAXCONN 5
  435. #define MSG_OOB 0x1 /* process out-of-band data */
  436. #define MSG_PEEK 0x2 /* peek at incoming message */
  437. #define MSG_DONTROUTE 0x4 /* send without using routing tables */
  438. #define MSG_MAXIOVLEN 16
  439. #define MSG_PARTIAL 0x8000 /* partial send or recv for message xport */
  440. /*
  441. * Define constant based on rfc883, used by gethostbyxxxx() calls.
  442. */
  443. #define MAXGETHOSTSTRUCT 1024
  444. /*
  445. * Define flags to be used with the WSAAsyncSelect() call.
  446. */
  447. #define FD_READ 0x01
  448. #define FD_WRITE 0x02
  449. #define FD_OOB 0x04
  450. #define FD_ACCEPT 0x08
  451. #define FD_CONNECT 0x10
  452. #define FD_CLOSE 0x20
  453. /*
  454. * All Windows Sockets error constants are biased by WSABASEERR from
  455. * the "normal"
  456. */
  457. #define WSABASEERR 10000
  458. /*
  459. * Windows Sockets definitions of regular Microsoft C error constants
  460. */
  461. #define WSAEINTR (WSABASEERR+4)
  462. #define WSAEBADF (WSABASEERR+9)
  463. #define WSAEACCES (WSABASEERR+13)
  464. #define WSAEFAULT (WSABASEERR+14)
  465. #define WSAEINVAL (WSABASEERR+22)
  466. #define WSAEMFILE (WSABASEERR+24)
  467. /*
  468. * Windows Sockets definitions of regular Berkeley error constants
  469. */
  470. #define WSAEWOULDBLOCK (WSABASEERR+35)
  471. #define WSAEINPROGRESS (WSABASEERR+36)
  472. #define WSAEALREADY (WSABASEERR+37)
  473. #define WSAENOTSOCK (WSABASEERR+38)
  474. #define WSAEDESTADDRREQ (WSABASEERR+39)
  475. #define WSAEMSGSIZE (WSABASEERR+40)
  476. #define WSAEPROTOTYPE (WSABASEERR+41)
  477. #define WSAENOPROTOOPT (WSABASEERR+42)
  478. #define WSAEPROTONOSUPPORT (WSABASEERR+43)
  479. #define WSAESOCKTNOSUPPORT (WSABASEERR+44)
  480. #define WSAEOPNOTSUPP (WSABASEERR+45)
  481. #define WSAEPFNOSUPPORT (WSABASEERR+46)
  482. #define WSAEAFNOSUPPORT (WSABASEERR+47)
  483. #define WSAEADDRINUSE (WSABASEERR+48)
  484. #define WSAEADDRNOTAVAIL (WSABASEERR+49)
  485. #define WSAENETDOWN (WSABASEERR+50)
  486. #define WSAENETUNREACH (WSABASEERR+51)
  487. #define WSAENETRESET (WSABASEERR+52)
  488. #define WSAECONNABORTED (WSABASEERR+53)
  489. #define WSAECONNRESET (WSABASEERR+54)
  490. #define WSAENOBUFS (WSABASEERR+55)
  491. #define WSAEISCONN (WSABASEERR+56)
  492. #define WSAENOTCONN (WSABASEERR+57)
  493. #define WSAESHUTDOWN (WSABASEERR+58)
  494. #define WSAETOOMANYREFS (WSABASEERR+59)
  495. #define WSAETIMEDOUT (WSABASEERR+60)
  496. #define WSAECONNREFUSED (WSABASEERR+61)
  497. #define WSAELOOP (WSABASEERR+62)
  498. #define WSAENAMETOOLONG (WSABASEERR+63)
  499. #define WSAEHOSTDOWN (WSABASEERR+64)
  500. #define WSAEHOSTUNREACH (WSABASEERR+65)
  501. #define WSAENOTEMPTY (WSABASEERR+66)
  502. #define WSAEPROCLIM (WSABASEERR+67)
  503. #define WSAEUSERS (WSABASEERR+68)
  504. #define WSAEDQUOT (WSABASEERR+69)
  505. #define WSAESTALE (WSABASEERR+70)
  506. #define WSAEREMOTE (WSABASEERR+71)
  507. #define WSAEDISCON (WSABASEERR+101)
  508. /*
  509. * Extended Windows Sockets error constant definitions
  510. */
  511. #define WSASYSNOTREADY (WSABASEERR+91)
  512. #define WSAVERNOTSUPPORTED (WSABASEERR+92)
  513. #define WSANOTINITIALISED (WSABASEERR+93)
  514. /*
  515. * Error return codes from gethostbyname() and gethostbyaddr()
  516. * (when using the resolver). Note that these errors are
  517. * retrieved via WSAGetLastError() and must therefore follow
  518. * the rules for avoiding clashes with error numbers from
  519. * specific implementations or language run-time systems.
  520. * For this reason the codes are based at WSABASEERR+1001.
  521. * Note also that [WSA]NO_ADDRESS is defined only for
  522. * compatibility purposes.
  523. */
  524. #define h_errno WSAGetLastError()
  525. /* Authoritative Answer: Host not found */
  526. #define WSAHOST_NOT_FOUND (WSABASEERR+1001)
  527. #define HOST_NOT_FOUND WSAHOST_NOT_FOUND
  528. /* Non-Authoritative: Host not found, or SERVERFAIL */
  529. #define WSATRY_AGAIN (WSABASEERR+1002)
  530. #define TRY_AGAIN WSATRY_AGAIN
  531. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  532. #define WSANO_RECOVERY (WSABASEERR+1003)
  533. #define NO_RECOVERY WSANO_RECOVERY
  534. /* Valid name, no data record of requested type */
  535. #define WSANO_DATA (WSABASEERR+1004)
  536. #define NO_DATA WSANO_DATA
  537. /* no address, look for MX record */
  538. #define WSANO_ADDRESS WSANO_DATA
  539. #define NO_ADDRESS WSANO_ADDRESS
  540. /*
  541. * Windows Sockets errors redefined as regular Berkeley error constants.
  542. * These are commented out in Windows NT to avoid conflicts with errno.h.
  543. * Use the WSA constants instead.
  544. */
  545. #if 0
  546. #define EWOULDBLOCK WSAEWOULDBLOCK
  547. #define EINPROGRESS WSAEINPROGRESS
  548. #define EALREADY WSAEALREADY
  549. #define ENOTSOCK WSAENOTSOCK
  550. #define EDESTADDRREQ WSAEDESTADDRREQ
  551. #define EMSGSIZE WSAEMSGSIZE
  552. #define EPROTOTYPE WSAEPROTOTYPE
  553. #define ENOPROTOOPT WSAENOPROTOOPT
  554. #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
  555. #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
  556. #define EOPNOTSUPP WSAEOPNOTSUPP
  557. #define EPFNOSUPPORT WSAEPFNOSUPPORT
  558. #define EAFNOSUPPORT WSAEAFNOSUPPORT
  559. #define EADDRINUSE WSAEADDRINUSE
  560. #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
  561. #define ENETDOWN WSAENETDOWN
  562. #define ENETUNREACH WSAENETUNREACH
  563. #define ENETRESET WSAENETRESET
  564. #define ECONNABORTED WSAECONNABORTED
  565. #define ECONNRESET WSAECONNRESET
  566. #define ENOBUFS WSAENOBUFS
  567. #define EISCONN WSAEISCONN
  568. #define ENOTCONN WSAENOTCONN
  569. #define ESHUTDOWN WSAESHUTDOWN
  570. #define ETOOMANYREFS WSAETOOMANYREFS
  571. #define ETIMEDOUT WSAETIMEDOUT
  572. #define ECONNREFUSED WSAECONNREFUSED
  573. #define ELOOP WSAELOOP
  574. #define ENAMETOOLONG WSAENAMETOOLONG
  575. #define EHOSTDOWN WSAEHOSTDOWN
  576. #define EHOSTUNREACH WSAEHOSTUNREACH
  577. #define ENOTEMPTY WSAENOTEMPTY
  578. #define EPROCLIM WSAEPROCLIM
  579. #define EUSERS WSAEUSERS
  580. #define EDQUOT WSAEDQUOT
  581. #define ESTALE WSAESTALE
  582. #define EREMOTE WSAEREMOTE
  583. #endif
  584. /* Socket function prototypes */
  585. #ifdef __cplusplus
  586. extern "C" {
  587. #endif
  588. SOCKET PASCAL FAR accept (SOCKET s, struct sockaddr FAR *addr,
  589. int FAR *addrlen);
  590. int PASCAL FAR bind (SOCKET s, const struct sockaddr FAR *addr, int namelen);
  591. int PASCAL FAR closesocket (SOCKET s);
  592. int PASCAL FAR connect (SOCKET s, const struct sockaddr FAR *name, int namelen);
  593. int PASCAL FAR ioctlsocket (SOCKET s, long cmd, u_long FAR *argp);
  594. int PASCAL FAR getpeername (SOCKET s, struct sockaddr FAR *name,
  595. int FAR * namelen);
  596. int PASCAL FAR getsockname (SOCKET s, struct sockaddr FAR *name,
  597. int FAR * namelen);
  598. int PASCAL FAR getsockopt (SOCKET s, int level, int optname,
  599. char FAR * optval, int FAR *optlen);
  600. u_long PASCAL FAR htonl (u_long hostlong);
  601. u_short PASCAL FAR htons (u_short hostshort);
  602. unsigned long PASCAL FAR inet_addr (const char FAR * cp);
  603. char FAR * PASCAL FAR inet_ntoa (struct in_addr in);
  604. int PASCAL FAR listen (SOCKET s, int backlog);
  605. u_long PASCAL FAR ntohl (u_long netlong);
  606. u_short PASCAL FAR ntohs (u_short netshort);
  607. int PASCAL FAR recv (SOCKET s, char FAR * buf, int len, int flags);
  608. int PASCAL FAR recvfrom (SOCKET s, char FAR * buf, int len, int flags,
  609. struct sockaddr FAR *from, int FAR * fromlen);
  610. int PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set FAR *writefds,
  611. fd_set FAR *exceptfds, const struct timeval FAR *timeout);
  612. int PASCAL FAR send (SOCKET s, const char FAR * buf, int len, int flags);
  613. int PASCAL FAR sendto (SOCKET s, const char FAR * buf, int len, int flags,
  614. const struct sockaddr FAR *to, int tolen);
  615. int PASCAL FAR setsockopt (SOCKET s, int level, int optname,
  616. const char FAR * optval, int optlen);
  617. int PASCAL FAR shutdown (SOCKET s, int how);
  618. SOCKET PASCAL FAR socket (int af, int type, int protocol);
  619. /* Database function prototypes */
  620. struct hostent FAR * PASCAL FAR gethostbyaddr(const char FAR * addr,
  621. int len, int type);
  622. struct hostent FAR * PASCAL FAR gethostbyname(const char FAR * name);
  623. int PASCAL FAR gethostname (char FAR * name, int namelen);
  624. struct servent FAR * PASCAL FAR getservbyport(int port, const char FAR * proto);
  625. struct servent FAR * PASCAL FAR getservbyname(const char FAR * name,
  626. const char FAR * proto);
  627. struct protoent FAR * PASCAL FAR getprotobynumber(int proto);
  628. struct protoent FAR * PASCAL FAR getprotobyname(const char FAR * name);
  629. /* Microsoft Windows Extension function prototypes */
  630. int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
  631. int PASCAL FAR WSACleanup(void);
  632. void PASCAL FAR WSASetLastError(int iError);
  633. int PASCAL FAR WSAGetLastError(void);
  634. BOOL PASCAL FAR WSAIsBlocking(void);
  635. int PASCAL FAR WSAUnhookBlockingHook(void);
  636. FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc);
  637. int PASCAL FAR WSACancelBlockingCall(void);
  638. HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
  639. const char FAR * name,
  640. const char FAR * proto,
  641. char FAR * buf, int buflen);
  642. HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
  643. const char FAR * proto, char FAR * buf,
  644. int buflen);
  645. HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
  646. const char FAR * name, char FAR * buf,
  647. int buflen);
  648. HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
  649. int number, char FAR * buf,
  650. int buflen);
  651. HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
  652. const char FAR * name, char FAR * buf,
  653. int buflen);
  654. HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
  655. const char FAR * addr, int len, int type,
  656. char FAR * buf, int buflen);
  657. int PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
  658. int PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
  659. long lEvent);
  660. int PASCAL FAR WSARecvEx (SOCKET s, char FAR * buf, int len, int FAR *flags);
  661. #ifdef __cplusplus
  662. }
  663. #endif
  664. /* Microsoft Windows Extended data types */
  665. typedef struct sockaddr SOCKADDR;
  666. typedef struct sockaddr *PSOCKADDR;
  667. typedef struct sockaddr FAR *LPSOCKADDR;
  668. typedef struct sockaddr_in SOCKADDR_IN;
  669. typedef struct sockaddr_in *PSOCKADDR_IN;
  670. typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
  671. typedef struct linger LINGER;
  672. typedef struct linger *PLINGER;
  673. typedef struct linger FAR *LPLINGER;
  674. typedef struct in_addr IN_ADDR;
  675. typedef struct in_addr *PIN_ADDR;
  676. typedef struct in_addr FAR *LPIN_ADDR;
  677. typedef struct fd_set FD_SET;
  678. typedef struct fd_set *PFD_SET;
  679. typedef struct fd_set FAR *LPFD_SET;
  680. typedef struct hostent HOSTENT;
  681. typedef struct hostent *PHOSTENT;
  682. typedef struct hostent FAR *LPHOSTENT;
  683. typedef struct servent SERVENT;
  684. typedef struct servent *PSERVENT;
  685. typedef struct servent FAR *LPSERVENT;
  686. typedef struct protoent PROTOENT;
  687. typedef struct protoent *PPROTOENT;
  688. typedef struct protoent FAR *LPPROTOENT;
  689. typedef struct timeval TIMEVAL;
  690. typedef struct timeval *PTIMEVAL;
  691. typedef struct timeval FAR *LPTIMEVAL;
  692. /*
  693. * Windows message parameter composition and decomposition
  694. * macros.
  695. *
  696. * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  697. * when constructing the response to a WSAAsyncGetXByY() routine.
  698. */
  699. #define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
  700. /*
  701. * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  702. * when constructing the response to WSAAsyncSelect().
  703. */
  704. #define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
  705. /*
  706. * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  707. * to extract the buffer length from the lParam in the response
  708. * to a WSAGetXByY().
  709. */
  710. #define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
  711. /*
  712. * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  713. * to extract the error code from the lParam in the response
  714. * to a WSAGetXByY().
  715. */
  716. #define WSAGETASYNCERROR(lParam) HIWORD(lParam)
  717. /*
  718. * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  719. * to extract the event code from the lParam in the response
  720. * to a WSAAsyncSelect().
  721. */
  722. #define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
  723. /*
  724. * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  725. * to extract the error code from the lParam in the response
  726. * to a WSAAsyncSelect().
  727. */
  728. #define WSAGETSELECTERROR(lParam) HIWORD(lParam)
  729. #endif /* _WINSOCKAPI_ */