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.

1087 lines
37 KiB

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