home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / winsoc11.zip / winsoc11.inf (.txt)
OS/2 Help File  |  1999-05-12  |  185KB  |  7,228 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. Windows Sockets ΓòÉΓòÉΓòÉ
  3.  
  4.  An Open Interface for 
  5.  
  6. Network Programming under 
  7.  
  8. Microsoft Windows 
  9.  
  10. Version 1.1
  11.  
  12. 20 January 1993 
  13.  
  14.  
  15. ΓòÉΓòÉΓòÉ 2. Authors and Copyright ΓòÉΓòÉΓòÉ
  16.  
  17. Martin Hall 
  18. Mark Towfiq 
  19. Geoff Arnold 
  20. David Treadwell 
  21. Henry Sanders 
  22.  
  23. Copyright (c) 1992 by Martin Hall, Mark Towfiq 
  24. Geoff Arnold, David Treadwell and Henry Sanders 
  25. All rights reserved. 
  26.  
  27. This document may be freely redistributed in any form, electronic or otherwise, 
  28. provided that it is distributed in its entirety and that the copyright and this 
  29. notice are included.  Comments or questions may be submitted via electronic 
  30. mail to WinSock@MailBag.Intel.Com.  Requests to be added to the Windows Sockets 
  31. mailing list should be addressed to MajorDomo@MailBag.Intel.Com. This 
  32. specification, archives of the mailing list, and other information on Windows 
  33. Sockets are available via anonymous FTP from the host SunSite.UNC.Edu, 
  34. directory /pub/micro/pc-stuff/ms-windows/winsock. Questions about products 
  35. conforming to this specification should be addressed to the vendors of the 
  36. products. 
  37.  
  38.  
  39. ΓòÉΓòÉΓòÉ 3. Acknowledgments ΓòÉΓòÉΓòÉ
  40.  
  41. The authors would like to thank their companies for allowing them the time and 
  42. resources to make this specification possible:  JSB Corporation, Microdyne 
  43. Corporation, FTP Software, Sun Microsystems, and Microsoft Corporation. 
  44.  
  45. Special thanks should also be extended to the other efforts contributing to the 
  46. success of Windows Sockets. The original draft was heavily influenced by 
  47. existing specifications offered and detailed by JSB Corporation and NetManage, 
  48. Inc. The "version 1.0 debate" hosted by Microsoft in Seattle allowed many of 
  49. the members of the working group to hash out final details for 1.0 vis-a-vis. 
  50.  
  51. Sun Microsystems was kind enough to allow first time implementors to "plug and 
  52. play" beta software during the first Windows Sock-A-Thon of  Windows Sockets 
  53. applications and implementations at Interop Fall '92.  Microsoft has shared 
  54. WSAT (the Windows Sockets API Tester) with other Windows Sockets implementors 
  55. as a standard Windows Sockets test suite to aid in testing their 
  56. implementations. Finally, Sun Microsystems and FTP Software plan to host the 
  57. Windows Sock-A-Thon II in Boston February '93. 
  58.  
  59. Without the contributions of the individuals and corporations involved in the 
  60. working group, Windows Sockets would never have been as thoroughly reviewed and 
  61. completed as quickly. In just one year, several competitors in the networking 
  62. business developed a useful specification with something to show for it] Many 
  63. thanks to all which participated, either in person or on e-mail to the Windows 
  64. Sockets effort. The authors would like to thank everyone who participated in 
  65. any way, and apologize in advance for anyone we have omitted. 
  66.  
  67. List of contributors: 
  68.  
  69. Martin Hall     (Chairman)      JSB Corporation         martinh@jsbus.com
  70. Mark Towfiq     (Coordinator)   Microdyne Corporation   towfiq@microdyne.com
  71. Geoff Arnold    (Editor 1.0)    Sun Microsystems        geoff@east.sun.com
  72. David Treadwell (Editor 1.1)    Microsoft Corporation   davidtr@microsoft.com
  73. Henry Sanders                   Microsoft Corporation   henrysa@microsoft.com
  74.  
  75. J. Allard                       Microsoft Corporation   jallard@microsoft.com
  76. Chris Arap-Bologna              Distinct                chris@distinct.com
  77. Larry Backman                   FTP Software            backman@ftp.com
  78. Alistair Banks                  Microsoft Corporation   alistair@microsoft.com
  79. Rob Barrow                      JSB Corporation         robb@jsb.co.uk
  80. Carl Beame                      Beame & Whiteside   beame@mcmaster.ca
  81. Dave Beaver                     Microsoft Corporation   dbeaver@microsoft.com
  82. Amatzia BenArtzi                NetManage, Inc.         amatzia@netmanage.com
  83. Mark Beyer                      Ungermann-Bass          mbeyer@ub.com
  84. Nelson Bolyard                  Silicon Graphics, Inc.  nelson@sgi.com
  85. Pat Bonner                      Hewlett-Packard         p_bonner@cnd.hp.com
  86. Derek Brown                     FTP Software            db@wco.ftp.com
  87. Malcolm Butler                  ICL                     mcab@oasis.icl.co.uk
  88. Mike Calbaum                    Frontier Technologies   mike@frontiertech.com
  89. Isaac Chan                      Microsoft Corporation   isaacc@microsoft.com
  90. Khoji Darbani                   Informix                khoji@informix.com
  91. Nestor Fesas                    Hughes LAN Systems      nestor@hls.com
  92. Karanja Gakio                   FTP Software            karanja@ftp.com
  93. Vikas Garg                      Distinct                vikas@distinct.com
  94. Gary Gere                       Gupta                   ggere@gupta.com
  95. Jim Gilroy                      Microsoft Corporation   jamesg@microsoft.com
  96. Bill Hayes                      Hewlett-Packard         billh@hpchdpc.cnd.hp.com
  97. Paul Hill                       MIT                     pbh@athena.mit.edu
  98. Tmima Koren                     NetManage, Inc.         tmima@netmanage.com
  99. Hoek Law                        Citicorp                law@dcc.tti.com
  100. Graeme Le Roux                  Moresdawn P/L           -
  101. Kevin Lewis                     Novell                  kevinl@novell.com
  102. Roger Lin                       3Com                    roger_lin@3mail.3com.com
  103. Terry Lister                    Hewlett-Packard         tel@cnd.hp.com
  104. Jeng Long Jiang                 Wollongong              long@twg.com
  105. Lee Murach                      Network Research        lee@nrc.com
  106. Pete Ostenson                   Microsoft Corporation   peteo@microsoft.com
  107. David Pool                      Spry, Inc.              dave@spry.com
  108. Bob Quinn                       FTP Software            rcq@ftp.com
  109. Glenn Reitsma                   Hughes LAN Systems      glennr@hls.com
  110. Brad Rice                       Age                     rice@age.com
  111. Allen Rochkind                  3Com                    -
  112. Jonathan Rosen                  IBM                     jrosen@vnet.ibm.com
  113. Steve Stokes                    Novell                  stoke@novell.com
  114. Joseph Tsai                     3Com                    joe_tsai@3mail.3com.com
  115. James Van Bokkelen              FTP Software            jbvb@ftp.com
  116. Miles Wu                        Wollongong              wu@twg.com
  117. Boris Yanovsky                  NetManage, Inc.         boris@netmanage.com
  118.  
  119.  
  120. ΓòÉΓòÉΓòÉ 4. Introduction ΓòÉΓòÉΓòÉ
  121.  
  122.  
  123. ΓòÉΓòÉΓòÉ 4.1. What is Windows Sockets ΓòÉΓòÉΓòÉ
  124.  
  125. The Windows Sockets specification defines a network programming interface for 
  126. Microsoft Windows which is based on the "socket" paradigm popularized in the 
  127. Berkeley Software Distribution (BSD) from the University of California at 
  128. Berkeley.  It encompasses both familiar Berkeley socket style routines and a 
  129. set of Windows-specific extensions designed to allow the programmer to take 
  130. advantage of the message-driven nature of Windows. 
  131.  
  132. The Windows Sockets Specification is intended to provide a single API to which 
  133. application developers can program and multiple network software vendors can 
  134. conform.  Furthermore, in the context of a particular version of Microsoft 
  135. Windows, it defines a binary interface (ABI) such that an application written 
  136. to the Windows Sockets API can work with a conformant protocol implementation 
  137. from any network software vendor.  This specification thus defines the library 
  138. calls and associated semantics to which an application developer can program 
  139. and which a network software vendor can implement. 
  140.  
  141. Network software which conforms to this Windows Sockets specification will be 
  142. considered "Windows Sockets Compliant".  Suppliers of interfaces which are 
  143. "Windows Sockets Compliant" shall be referred to as "Windows Sockets 
  144. Suppliers".  To be Windows Sockets Compliant, a vendor must implement 100% of 
  145. this Windows Sockets specification. 
  146.  
  147. Applications which are capable of operating with any "Windows Sockets 
  148. Compliant" protocol implementation will be considered as having a "Windows 
  149. Sockets Interface" and will be referred to as "Windows Sockets Applications". 
  150.  
  151. This version of the Windows Sockets specification defines and documents the use 
  152. of the API in conjunction with the Internet Protocol Suite (IPS, generally 
  153. referred to as TCP/IP).  Specifically, all Windows Sockets implementations 
  154. support both stream (TCP) and datagram (UDP) sockets. 
  155.  
  156. While the use of this API with alternative protocol stacks is not precluded 
  157. (and is expected to be the subject of future revisions of the specification), 
  158. such usage is beyond the scope of this version of the specification. 
  159.  
  160.  
  161. ΓòÉΓòÉΓòÉ 4.2. Berkeley Sockets ΓòÉΓòÉΓòÉ
  162.  
  163. The Windows Sockets Specification has been built upon the Berkeley Sockets 
  164. programming model which is the de facto standard for TCP/IP networking.  It is 
  165. intended to provide a high degree of familiarity for programmers who are used 
  166. to programming with sockets in UNIX and other environments, and to simplify the 
  167. task of porting existing sockets-based source code.  The Windows Sockets API is 
  168. consistent with release 4.3 of the Berkeley Software Distribution (4.3BSD). 
  169.  
  170. Portions of the Windows Sockets specification are derived from material which 
  171. is Copyright (c) 1982-1986 by the Regents of the University of California.  All 
  172. rights are reserved.  The Berkeley Software License Agreement specifies the 
  173. terms and conditions for redistribution. 
  174.  
  175.  
  176. ΓòÉΓòÉΓòÉ 4.3. Microsoft Windows and Windows-specific extensions ΓòÉΓòÉΓòÉ
  177.  
  178. This API is intended to be usable within all implementations and versions of 
  179. Microsoft Windows from Microsoft Windows Version 3.0 onwards.  It thus provides 
  180. for Windows Sockets implementations and Windows Sockets applications in both 16 
  181. and 32 bit operating environments. 
  182.  
  183. Windows Sockets makes provisions for multithreaded Windows processes.  A 
  184. process contains one or more threads of execution.  In the Windows 3.1 
  185. non-multithreaded world, a task corresponds to a process with a single thread. 
  186. All references to threads in this document refer to actual "threads" in 
  187. multithreaded Windows environments.  In non multithreaded environments (such as 
  188. Windows 3.0), use of the term thread refers to a Windows process. 
  189.  
  190. The Microsoft Windows extensions included in Windows Sockets are provided to 
  191. allow application developers to create software which conforms to the Windows 
  192. programming model.  It is expected that this will facilitate the creation of 
  193. robust and high-performance applications, and will improve the cooperative 
  194. multitasking of applications within non-preemptive versions of Windows.  With 
  195. the exception of WSAStartup() and WSACleanup() their use is not mandatory. 
  196.  
  197.  
  198. ΓòÉΓòÉΓòÉ 4.4. The Status of this Specification ΓòÉΓòÉΓòÉ
  199.  
  200. Windows Sockets is an independent specification which was created and exists 
  201. for the benefit of application developers and network vendors and, indirectly, 
  202. computer users. Each published (non-draft) version of this specification 
  203. represents a fully workable API for implementation by network vendors and 
  204. programming use by application developers. Discussion of this specification and 
  205. suggested improvements continue and are welcomed. Such discussion occurs mainly 
  206. via the Internet electronic mail forum winsock@microdyne.com. Meetings of 
  207. interested parties occur on an irregular basis. Details of these meetings are 
  208. publicized to the electronic mail forum. 
  209.  
  210.  
  211. ΓòÉΓòÉΓòÉ 4.5. Revision History ΓòÉΓòÉΓòÉ
  212.  
  213.  
  214. ΓòÉΓòÉΓòÉ 4.5.1. Windows Sockets Version 1.0 ΓòÉΓòÉΓòÉ
  215.  
  216. Windows Sockets Version 1.0 represented the results of considerable work within 
  217. the vendor and user community as discussed in "Origins of Windows Sockets". 
  218. This version of  the specification was released in order that network software 
  219. suppliers and  application developers could begin to construct implementations 
  220. and applications  which conformed to the Windows Sockets standard. 
  221.  
  222.  
  223. ΓòÉΓòÉΓòÉ 4.5.2. Windows Sockets Version 1.1 ΓòÉΓòÉΓòÉ
  224.  
  225. Windows Sockets Version 1.1 follows the guidelines and structure laid out by 
  226. version 1.0, making changes only where absolutely necessary as indicated by the 
  227. experiences of a number of companies that created Windows Sockets 
  228. implementations based on the version 1.0 specification.  Version 1.1 contains 
  229. several clarifications and minor fixes to version 1.0.  Additionally, the 
  230. following more significant changes were incorporated into version 1.1: 
  231.  
  232.      Inclusion of the gethostname() routine to simplify retrieval of the 
  233.       host's name and address. 
  234.  
  235.      Definition of DLL ordinal values below 1000 as reserved for Windows 
  236.       Sockets and ordinals above 1000 as unrestricted.  This allows Windows 
  237.       Sockets vendors to include private interfaces to their DLLs without 
  238.       risking that the ordinals choosen will conflict with a future version of 
  239.       Windows Sockets. 
  240.  
  241.      Addition of a reference count to WSAStartup() and WSACleanup(), requiring 
  242.       correspondences between the calls.  This allows applications and 
  243.       third-party DLLs to make use of a Windows Sockets implementation without 
  244.       being concerned about the calls to these APIs made by the other. 
  245.  
  246.      Change of return type of inet_addr() from struct in_addr to unsigned 
  247.       long.  This was required due to different handling of four-byte structure 
  248.       returns between the Microsoft and Borland C compilers. 
  249.  
  250.      Change of WSAAsyncSelect() semantics from "edge-triggerred" to 
  251.       "level-triggerred".  The level-triggerred semantics significantly 
  252.       simplify an application's use of this routine. 
  253.  
  254.      Change the ioctlsocket() FIONBIO semantics to fail if a WSAAsyncSelect() 
  255.       call is outstanding on the socket. 
  256.  
  257.      Addition of the TCP_NODELAY socket option for RFC 1122 conformance. 
  258.  
  259.  
  260. ΓòÉΓòÉΓòÉ 5. Programming with Sockets ΓòÉΓòÉΓòÉ
  261.  
  262.  
  263. ΓòÉΓòÉΓòÉ 5.1. Windows Sockets Stack Installation Checking ΓòÉΓòÉΓòÉ
  264.  
  265. To detect the presence of one (or many) Windows Sockets implementations on a 
  266. system, an application which has been linked with the Windows Sockets Import 
  267. Library may simply call the WSAStartup() routine.  If an application wishes to 
  268. be a little more sophisticated it can examine the $PATH environment variable 
  269. and search for instances of Windows Sockets implementations (WINSOCK.DLL).  For 
  270. each instance it can issue a LoadLibrary() call and use the WSAStartup() 
  271. routine to discover implementation specific data. 
  272.  
  273. This version of the Windows Sockets specification does not attempt to address 
  274. explicitly the issue of multiple concurrent Windows Sockets implementations. 
  275. Nothing in the specification should be interpreted as restricting multiple 
  276. Windows Sockets DLLs from being present and used concurrently by one or more 
  277. Windows Sockets applications. 
  278.  
  279. For further details of where to obtain Windows Sockets components, see "Windows 
  280. Sockets Components". 
  281.  
  282.  
  283. ΓòÉΓòÉΓòÉ 5.2. Sockets ΓòÉΓòÉΓòÉ
  284.  
  285. The following material is derived from the document "An Advanced 4.3BSD 
  286. Interprocess Communication Tutorial" by Samuel J. Leffler, Robert S. Fabry, 
  287. William N. Joy, Phil Lapsley, Steve Miller, and Chris Torek. 
  288.  
  289.  
  290. ΓòÉΓòÉΓòÉ 5.2.1. Basic concepts ΓòÉΓòÉΓòÉ
  291.  
  292. The basic building block for communication is the socket.  A socket is an 
  293. endpoint of communication to which a name may be bound.  Each socket in use has 
  294. a type and an associated process.  Sockets exist within communication domains. 
  295. A communication domain is an abstraction introduced to bundle common properties 
  296. of threads communicating through sockets.  Sockets normally exchange data only 
  297. with sockets in the same domain (it may be possible to cross domain boundaries, 
  298. but only if some translation process is performed).  The Windows Sockets 
  299. facilities support a single communication domain: the Internet domain, which is 
  300. used by processes which communicate using the Internet Protocol Suite.  (Future 
  301. versions of this specification may include additional domains.) 
  302.  
  303. Sockets are typed according to the communication properties visible to a user. 
  304. Applications are presumed to communicate only between sockets of the same type, 
  305. although there is nothing that prevents communication between sockets of 
  306. different types should the underlying communication protocols support this. 
  307.  
  308. Two types of sockets currently are available to a user.  A stream socket 
  309. provides for the bi-directional, reliable, sequenced, and unduplicated flow of 
  310. data without record boundaries. 
  311.  
  312. A datagram socket supports bi-directional flow of data which is not promised to 
  313. be sequenced, reliable, or unduplicated.  That is, a process receiving messages 
  314. on a datagram socket may find messages duplicated, and, possibly, in an order 
  315. different from the order in which it was sent.  An important characteristic of 
  316. a datagram socket is that record boundaries in data are preserved.  Datagram 
  317. sockets closely model the facilities found in many contemporary packet switched 
  318. networks such as Ethernet. 
  319.  
  320.  
  321. ΓòÉΓòÉΓòÉ 5.2.2. Client-server model ΓòÉΓòÉΓòÉ
  322.  
  323. The most commonly used paradigm in constructing distributed applications is the 
  324. client/server model.  In this scheme client applications request services from 
  325. a server application.  This implies an asymmetry in establishing communication 
  326. between the client and server. 
  327.  
  328. The client and server require a well-known set of conventions before service 
  329. may be rendered (and accepted).  This set of conventions comprises a protocol 
  330. which must be implemented at both ends of a connection.  Depending on the 
  331. situation, the protocol may be symmetric or asymmetric.  In a symmetric 
  332. protocol, either side may play the master or slave roles.  In an asymmetric 
  333. protocol, one side is immutably recognized as the master, with the other as the 
  334. slave.  An example of a symmetric protocol is the TELNET protocol used in the 
  335. Internet for remote terminal emulation.  An example of an asymmetric protocol 
  336. is the Internet file transfer protocol, FTP.  No matter whether the specific 
  337. protocol used in obtaining a service is symmetric or asymmetric, when accessing 
  338. a service there is a "client process" and a "server process". 
  339.  
  340. A server application normally listens at a well-known address for service 
  341. requests.  That is, the server process remains dormant until a connection is 
  342. requested by a client's connection to the server's address.  At such a time the 
  343. server process "wakes up" and services the client, performing whatever 
  344. appropriate actions the client requests of it.  While connection-based services 
  345. are the norm, some services are based on the use of datagram sockets. 
  346.  
  347.  
  348. ΓòÉΓòÉΓòÉ 5.2.3. Out-of-band data ΓòÉΓòÉΓòÉ
  349.  
  350. Note: The following discussion of out-of-band data, also referred to as TCP 
  351. Urgent data,  follows the model used in the Berkeley software distribution. 
  352. Users and implementors should be aware of the fact that there are at present 
  353. two conflicting interpretations of RFC 793 (in which the concept is 
  354. introduced), and that the implementation of out-of-band data in the Berkeley 
  355. Software Distribution does not conform to the Host Requirements laid down in 
  356. RFC 1122.  To minimize interoperability problems, applications writers are 
  357. advised not to use out-of-band data unless this is required in order to 
  358. interoperate with an existing service.  Windows Sockets suppliers are urged to 
  359. document the out-of-band semantics (BSD or RFC 1122) which their product 
  360. implements.  It is beyond the scope of this specification to mandate a 
  361. particular set of semantics for out-of-band data handling. 
  362.  
  363. The stream socket abstraction includes the notion of "out of band" data. 
  364. Out-of-band data is a logically independent transmission channel associated 
  365. with each pair of connected stream sockets.  Out-of-band data is delivered to 
  366. the user independently of normal data.  The abstraction defines that the 
  367. out-of-band data facilities must support the reliable delivery of at least one 
  368. out-of-band message at a time.  This message may contain at least one byte of 
  369. data, and at least one message may be pending delivery to the user at any one 
  370. time.  For communications protocols which support only in-band signaling (i.e. 
  371. the urgent data is delivered in sequence with the normal data), the system 
  372. normally extracts the data from the normal data stream and stores it 
  373. separately.  This allows users to choose between receiving the urgent data in 
  374. order and receiving it out of sequence without having to buffer all the 
  375. intervening data.  It is possible to "peek" at out-of-band data. 
  376.  
  377. An application may prefer to process out-of-band data "in-line", as part of the 
  378. normal data stream.  This is achieved by setting the socket option SO_OOBINLINE 
  379. (see setsockopt()). In this case, the application may wish to determine whether 
  380. any of the unread data is "urgent" (the term usually applied to in-line 
  381. out-of-band data).  To facilitate this, the Windows Sockets implementation will 
  382. maintain a logical "mark" in the data stream to indicate the point at which the 
  383. out-of-band data was sent.  An application can use the SIOCATMARK ioctlsocket() 
  384. command to determine whether there is any unread data preceding the mark.  For 
  385. example, it might use this to resynchronize with its peer by ensuring that all 
  386. data up to the mark in the data stream is discarded when appropriate. 
  387.  
  388. The WSAAsyncSelect() routine is particularly well suited to handling 
  389. notification of the presence of out-of-band-data. 
  390.  
  391.  
  392. ΓòÉΓòÉΓòÉ 5.2.4. Broadcasting ΓòÉΓòÉΓòÉ
  393.  
  394. By using a datagram socket, it is possible to send broadcast packets on many 
  395. networks supported by the system.  The network itself must support broadcast: 
  396. the system provides no simulation of broadcast in software.  Broadcast messages 
  397. can place a high load on a network, since they force every host on the network 
  398. to service them.  Consequently, the ability to send broadcast packets has been 
  399. limited to sockets which are explicitly marked as allowing broadcasting. 
  400. Broadcast is typically used for one of two reasons: it is desired to find a 
  401. resource on a local network without prior knowledge of its address, or 
  402. important functions such as routing require that information be sent to all 
  403. accessible neighbors. 
  404.  
  405. The destination address of the message to be broadcast depends on the 
  406. network(s) on which the message is to be broadcast.  The Internet domain 
  407. supports a shorthand notation for broadcast on the local network, the address 
  408. INADDR_BROADCAST.  Received broadcast messages contain the senders address and 
  409. port, as datagram sockets must be bound before use. 
  410.  
  411. Some types of network support the notion of different types of broadcast.  For 
  412. example, the IEEE 802.5 token ring architecture supports the use of link-level 
  413. broadcast indicators, which control whether broadcasts are forwarded by 
  414. bridges.  The Windows Sockets specification does not provide any mechanism 
  415. whereby an application can determine the type of underlying network, nor any 
  416. way to control the semantics of broadcasting. 
  417.  
  418.  
  419. ΓòÉΓòÉΓòÉ 5.3. Byte Ordering ΓòÉΓòÉΓòÉ
  420.  
  421. The Intel byte ordering is like that of the DEC VAX, and therefore differs from 
  422. the Internet and 68000-type processor byte ordering.  Thus care must be taken 
  423. to ensure correct orientation. 
  424.  
  425. Any reference to IP addresses or port numbers passed to or from a Windows 
  426. Sockets routine must be in network order.  This includes the IP address and 
  427. port fields of a struct sockaddr_in (but not the sin_family field). 
  428.  
  429. Consider an application which normally contacts a server on the TCP port 
  430. corresponding to the "time" service, but which provides a mechanism for the 
  431. user to specify that an alternative port is to be used.  The port number 
  432. returned by getservbyname() is already in network order, which is the format 
  433. required constructing an address, so no translation is required.  However if 
  434. the user elects to use a different port, entered as an integer, the application 
  435. must convert this from host to network order (using the htons() function) 
  436. before using it to construct an address.  Conversely, if the application wishes 
  437. to display the number of the port within an address (returned via, e.g., 
  438. getpeername()), the port number must be converted from network to host order 
  439. (using ntohs()) before it can be displayed. 
  440.  
  441. Since the Intel and Internet byte orders are different, the conversions 
  442. described above are unavoidable.  Application writers are cautioned that they 
  443. should use the standard conversion functions provided as part of the Windows 
  444. Sockets API rather than writing their own conversion code, since future 
  445. implementations of Windows Sockets are likely to run on systems for which the 
  446. host order is identical to the network byte order.  Only applications which use 
  447. the standard conversion functions are likely to be portable. 
  448.  
  449.  
  450. ΓòÉΓòÉΓòÉ 5.4. Socket Options ΓòÉΓòÉΓòÉ
  451.  
  452. The socket options supported by Windows Sockets are listed in the pages 
  453. describing setsockopt() and getsockopt(). A Windows Sockets implementation must 
  454. recognize all of these options, and (for getsockopt()) return plausible values 
  455. for each.  The default value for each option is shown in the following table. 
  456.  
  457. Value           Type            Meaning                 Default         Note
  458. SO_ACCEPTCON    BOOL            Socket is listen()ing.
  459.                                 FALSE unless a listen()
  460.                                 has been performed
  461.  
  462. SO_BROADCAST    BOOL            Socket is configured    FALSE
  463.                                 for the transmission of
  464.                                 broadcast messages.
  465.  
  466. SO_DEBUG        BOOL            Debugging is enabled.   FALSE           (i)
  467.  
  468. SO_DONTLINGER   BOOL            If true, the SO_LINGER  TRUE
  469.                                 option is disabled.
  470.  
  471. SO_DONTROUTE    BOOL            Routing is disabled.    FALSE           (i)
  472.  
  473. SO_ERROR        int             Retrieve error status   0
  474.                                 and clear.
  475.  
  476. SO_KEEPALIVE    BOOL            Keepalives are being    FALSE
  477.                                 sent.
  478.  
  479. SO_LINGER       struct linger   Returns the current     l_onoff is 0
  480.                 FAR *           linger options.
  481.  
  482. SO_OOBINLINE    BOOL            Out-of-band data is     FALSE
  483.                                 being received in the
  484.                                 normal data stream.
  485.  
  486. SO_RCVBUF       int             Buffer size for         Implementation  (i)
  487.                                 receives                dependant.
  488.  
  489. SO_REUSEADDR    BOOL            The address to which    FALSE
  490.                                 this socket is bound
  491.                                 can be used by others.
  492.  
  493. SO_SNDBUF       int             Buffer size for sends   Implementation  (i)
  494.                                                         dependant.
  495.  
  496. SO_TYPE         int             The type of the socket  As created
  497.                                 (e.g. SOCK_STREAM).     via socket()
  498.  
  499. TCP_NODELAY     BOOL            Disables the Nagle      Implementation
  500.                                 algorithm for send      dependant.
  501.                                 coalescing.
  502.  
  503. Notes: 
  504.  
  505. (i)   An implementation may silently ignore this option on setsockopt() and 
  506. return a constant value for getsockopt(), or it may accept a value for 
  507. setsockopt() and return the corresponding value in getsockopt() without using 
  508. the value in any way. 
  509.  
  510.  
  511. ΓòÉΓòÉΓòÉ 5.5. Database Files ΓòÉΓòÉΓòÉ
  512.  
  513. The getXbyY() and WSAAsyncGetXByY() classes of routines are provided for 
  514. retrieving network specific information. The getXbyY() routines were originally 
  515. designed (in the first Berkeley UNIX releases) as mechanisms for looking up 
  516. information in text databases. Although the information may be retrieved by the 
  517. Windows Sockets implementation in different ways, a Windows Sockets application 
  518. requests such information in a consistent manner through either the getXbyY() 
  519. or the WSAAsyncGetXByY() class of routines. 
  520.  
  521.  
  522. ΓòÉΓòÉΓòÉ 5.6. Deviation from Berkeley Sockets ΓòÉΓòÉΓòÉ
  523.  
  524. There are a few limited instances where the Windows Sockets API has had to 
  525. divert from strict adherence to the Berkeley conventions, usually because of 
  526. difficulties of implementation in a Windows environment. 
  527.  
  528. socket data type and error values 
  529.  
  530. select() and FD_* 
  531.  
  532. Error codes -- errno, h_errno & WSAGetLastError() 
  533.  
  534. Pointers 
  535.  
  536. Renamed functions 
  537.  
  538. Blocking routines & EINPROGRESS 
  539.  
  540. Maximum number of sockets supported 
  541.  
  542. Include files 
  543.  
  544. Return values on API failure 
  545.  
  546.  
  547. ΓòÉΓòÉΓòÉ 5.6.1. socket data type and error values ΓòÉΓòÉΓòÉ
  548.  
  549. A new data type, SOCKET, has been defined.  The definition of this type was 
  550. necessary for future enhancements to the Windows Sockets specification, such as 
  551. being able to use sockets as file handles in Windows NT.  Definition of this 
  552. type also facilitates porting of applications to a Win/32 environment, as the 
  553. type will automatically be promoted from 16 to 32 bits. 
  554.  
  555. In UNIX, all handles, including socket handles, are small, non-negative 
  556. intergers, and some applications make assumptions that this will be true. 
  557. Windows Sockets handles have no restrictions, other than that the value 
  558. INVALID_SOCKET is not a valid socket.  Socket handles may take any value in the 
  559. range 0 to INVALID_SOCKET-1. 
  560.  
  561. Because the SOCKET type is unsigned, compiling existing source code from, for 
  562. example, a UNIX environment may lead to compiler warnings about signed/unsigned 
  563. data type mismatches. 
  564.  
  565. This means, for example, that checking for errors when the socket() and 
  566. accept() routines return should not be done by comparing the return value with 
  567. -1, or seeing if the value is negative (both common, and legal, approaches in 
  568. BSD).  Instead, an application should use the manifest constant INVALID_SOCKET 
  569. as defined in winsock.h. For example: 
  570.  
  571. TYPICAL BSD STYLE: 
  572.  
  573. s = socket(...);
  574. if (s == -1)    /* or s < 0 */
  575.         {...}
  576.  
  577. PREFERRED STYLE: 
  578.  
  579. s = socket(...);
  580. if (s == INVALID_SOCKET)
  581.         {...}
  582.  
  583.  
  584. ΓòÉΓòÉΓòÉ 5.6.2. select() and FD_* ΓòÉΓòÉΓòÉ
  585.  
  586. Because a SOCKET is no longer represented by the UNIX-style "small non-negative 
  587. integer", the implementation of the select() function was changed in the 
  588. Windows Sockets API.  Each set of descriptors is still represented by the 
  589. fd_set type, but instead of being stored as a bitmask the set is implemented as 
  590. an array of SOCKETs..  To avoid potential problems, applications must adhere to 
  591. the use of the FD_XXX macros to set, initialize, clear, and check the fd_set 
  592. structures. 
  593.  
  594.  
  595. ΓòÉΓòÉΓòÉ 5.6.3. Error codes -- errno, h_errno & WSAGetLastError() ΓòÉΓòÉΓòÉ
  596.  
  597. Error codes set by the Windows Sockets implementation are NOT made available 
  598. via the errno variable.  Additionally, for the getXbyY() class of functions, 
  599. error codes are NOT made available via the h_errno variable.  Instead, error 
  600. codes are accessed by using the WSAGetLastError() API.  This function is 
  601. provided in Windows Sockets as a precursor (and eventually an alias) for the 
  602. Win32 function GetLastError().  This is intended to provide a reliable way for 
  603. a thread in a multi-threaded process to obtain per-thread error information. 
  604.  
  605. For compatibility with BSD, an application may choose to include a line of the 
  606. form: 
  607.  
  608. #define errno WSAGetLastError()
  609.  
  610. This will allow networking code which was written to use the global errno to 
  611. work correctly in a single-threaded environment.  There are, obviously, some 
  612. drawbacks.  If a source file includes code which inspects errno for both socket 
  613. and non-socket functions, this mechanism cannot be used.  Furthermore, it is 
  614. not possible for an application to assign a new value to errno.  (In Windows 
  615. Sockets the function WSASetLastError() may be used for this purpose.) 
  616.  
  617. TYPICAL BSD STYLE: 
  618.  
  619. r = recv(...);
  620. if (r == -1
  621.     && errno == EWOULDBLOCK)
  622.         {...}
  623.  
  624. PREFERRED STYLE: 
  625.  
  626. r = recv(...);
  627. if (r == -1       /* (but see below) */
  628.     && WSAGetLastError() == EWOULDBLOCK)
  629.         {...}
  630.  
  631. Although error constants consistent with 4.3 Berkeley Sockets are provided for 
  632. compatibility purposes, applications should, where possible, use the "WSA" 
  633. error code definitions.  For example, a more accurate version of the above 
  634. source code fragment is: 
  635.  
  636. r = recv(...);
  637. if (r == -1
  638.     && WSAGetLastError() == WSAEWOULDBLOCK)
  639.         {...}
  640.  
  641.  
  642. ΓòÉΓòÉΓòÉ 5.6.4. Pointers ΓòÉΓòÉΓòÉ
  643.  
  644. All pointers used by applications with Windows Sockets should be FAR.  To 
  645. facilitate this, data type definitions such as LPHOSTENT are provided. 
  646.  
  647.  
  648. ΓòÉΓòÉΓòÉ 5.6.5. Renamed functions ΓòÉΓòÉΓòÉ
  649.  
  650. In two cases it was necessary to rename functions which are used in Berkeley 
  651. Sockets in order to avoid clashes with other APIs. 
  652.  
  653. close() & closesocket() In Berkeley Sockets, sockets are represented by 
  654. standard file descriptors, and so the close() function can be used to close 
  655. sockets as well as regular files.  While nothing in the Windows Sockets API 
  656. prevents an implementation from using regular file handles to identify sockets, 
  657. nothing requires it either.  Socket descriptors are not presumed to correspond 
  658. to regular file handles, and file operations such as read(), write(), and 
  659. close() cannot be assumed to work correctly when applied to socket descriptors. 
  660. Sockets must be closed by using the closesocket() routine.  Using the close() 
  661. routine to close a socket is incorrect and the effects of doing so are 
  662. undefined by this specification. 
  663.  
  664. ioctl() & ioctlsocket() 
  665.  
  666. Various C language run-time systems use the ioctl() routine for purposes 
  667. unrelated to Windows Sockets.  For this reason we have defined the routine 
  668. ioctlsocket() which is used to handle socket functions which in the Berkeley 
  669. Software Distribution are performed using ioctl() and fcntl(). 
  670.  
  671.  
  672. ΓòÉΓòÉΓòÉ 5.6.6. Blocking routines & EINPROGRESS ΓòÉΓòÉΓòÉ
  673.  
  674. Although blocking operations on sockets are supported under Windows Sockets, 
  675. their use is strongly discouraged.  Programmers who are constrained to use 
  676. blocking mode -- for example, as part of an existing application which is to be 
  677. ported -- should be aware of the semantics of blocking operations in Windows 
  678. Sockets.  See Blocking/Non blocking & Data Volatility for more details. 
  679.  
  680.  
  681. ΓòÉΓòÉΓòÉ 5.6.7. Maximum number of sockets supported ΓòÉΓòÉΓòÉ
  682.  
  683. The maximum number of sockets supported by a particular Windows Sockets 
  684. supplier is implementation specific.  An application should make no assumptions 
  685. about the availability of a certain number of sockets.  This topic is addressed 
  686. further in the section on WSAStartup(). However, independent of the number of 
  687. sockets supported by a particular implementation is the issue of the maximum 
  688. number of sockets which an application can actually make use of. 
  689.  
  690. The maximum number of sockets which a Windows Sockets application can make use 
  691. of is determined at compile time by the manifest constant FD_SETSIZE.  This 
  692. value is used in constructing the fd_set structures used in select(). The 
  693. default value in winsock.h is 64.  If an application is designed to be capable 
  694. of working with more than 64 sockets, the implementor should define the 
  695. manifest FD_SETSIZE in every source file before including winsock.h. One way of 
  696. doing this may be to include the definition within the compiler options in the 
  697. makefile, for example adding -DFD_SETSIZE=128 as an option to the compiler 
  698. command line for Microsoft C.  It must be emphasized that defining FD_SETSIZE 
  699. as a particular value has no effect on the actual number of sockets provided by 
  700. a Windows Sockets implementation. 
  701.  
  702.  
  703. ΓòÉΓòÉΓòÉ 5.6.8. Include files ΓòÉΓòÉΓòÉ
  704.  
  705. For ease of portability of existing Berkeley sockets based source code, a 
  706. number of standard Berkeley include files are supported.  However, these 
  707. Berkeley header files merely include the winsock.h include file, and it is 
  708. therefore sufficient (and recommended) that Windows Sockets application source 
  709. files should simply include winsock.h. 
  710.  
  711.  
  712. ΓòÉΓòÉΓòÉ 5.6.9. Return values on API failure ΓòÉΓòÉΓòÉ
  713.  
  714. The manifest constant SOCKET_ERROR is provided for checking API failure. 
  715. Although use of this constant is not mandatory, it is recommended.  The 
  716. following example illustrates the use of the SOCKET_ERROR constant: 
  717.  
  718. TYPICAL BSD STYLE: 
  719.  
  720. r = recv(...);
  721. if (r == -1     /* or r < 0 */
  722.     && errno == EWOULDBLOCK)
  723.         {...}
  724.  
  725. PREFERRED STYLE: 
  726.  
  727. r = recv(...);
  728. if (r == SOCKET_ERROR
  729.     && WSAGetLastError() == WSAEWOULDBLOCK)
  730.         {...}
  731.  
  732.  
  733. ΓòÉΓòÉΓòÉ 5.7. Raw Sockets ΓòÉΓòÉΓòÉ
  734.  
  735. The Windows Sockets specification does not mandate that a Windows Sockets DLL 
  736. support raw sockets, that is, sockets opened with SOCK_RAW.  However, a Windows 
  737. Sockets DLL is allowed and encouraged to supply raw socket support.  A Windows 
  738. Sockets-compliant application that wishes to use raw sockets should attempt to 
  739. open the socket with the socket() call (see section 4.1.23), and if it fails 
  740. either attempt to use another socket type or indicate the failure to the user. 
  741.  
  742.  
  743. ΓòÉΓòÉΓòÉ 5.8. Windows Sockets in Multithreaded Versions of Windows ΓòÉΓòÉΓòÉ
  744.  
  745. The Windows Sockets interface is designed to work for both single-threaded 
  746. versions of Windows (such as Windows 3.1) and future multithreaded versions of 
  747. Windows (such as Windows NT).  In a multithreaded environment the sockets 
  748. interface is basically the same, but the author of a multithreaded application 
  749. must be aware that it is the responsibility of the application, not the Windows 
  750. Sockets implementation, to synchronize access to a socket between threads. This 
  751. is the same rule as applies to other forms of I/O such as file I/O. Failure to 
  752. synchronize calls on a socket leads to unpredictable results; for example if 
  753. there are two simultaneous calls to send(), there is no guarantee as to the 
  754. order in which the data will be sent. 
  755.  
  756. Closing a socket in one thread that has an outstanding blocking call on the 
  757. same socket in another thread will cause the blocking call to fail with 
  758. WSAEINTR, just as if the operation were cancelled.  This also applies if there 
  759. is a select() call outstanding and the application closes one of the sockets 
  760. being selected. 
  761.  
  762. There is no default blocking hook installed in preemptive multithreaded 
  763. versions of Windows.  This is because the machine will not be blocked if a 
  764. single application is waiting for an operation to complete and hence not 
  765. calling PeekMessage() or GetMessage() which cause the application to yield in 
  766. nonpremptive Windows.  However, for backwards compatibility the 
  767. WSASetBlockingHook() call is implemented in multithreaded versions of Windows, 
  768. and any application whose behavior depends on the default blocking hook may 
  769. install their own blocking hook which duplicates the default hook's semantics, 
  770. if desired. 
  771.  
  772.  
  773. ΓòÉΓòÉΓòÉ 6. Socket Library Overview ΓòÉΓòÉΓòÉ
  774.  
  775.  
  776. ΓòÉΓòÉΓòÉ 6.1. Socket Functions ΓòÉΓòÉΓòÉ
  777.  
  778. The Windows Sockets specification includes the following Berkeley-style socket 
  779. routines: 
  780.  
  781. accept() An incoming connection is acknowledged and associated with an 
  782. immediately created socket.  The original socket is returned to the listening 
  783. state. 
  784.  
  785. bind() Assign a local name to an unnamed socket. 
  786.  
  787. closesocket() Remove a socket descriptor from the per-process object reference 
  788. table.  Only blocks if SO_LINGER is set. 
  789.  
  790. connect() Initiate a connection on the specified socket. 
  791.  
  792. getpeername() Retrieve the name of the peer connected to the specified socket 
  793. descriptor. 
  794.  
  795. getsockname() Retrieve the current name for the specified socket 
  796.  
  797. getsockopt() Retrieve options associated with the specified socket descriptor. 
  798.  
  799. htonl() Convert a 32-bit quantity from host byte order to network byte order. 
  800.  
  801. htons() Convert a 16-bit quantity from host byte order to network byte order. 
  802.  
  803. inet_addr() Converts a character string representing a number in the Internet 
  804. standard "." notation to an Internet address value. 
  805.  
  806. inet_ntoa() Converts an Internet address value to an ASCII string in "." 
  807. notation i.e. "a.b.c.d". 
  808.  
  809. ioctlsocket() Provide control for descriptors. 
  810.  
  811. listen() Listen for incoming connections on a specified socket. 
  812.  
  813. ntohl() Convert a 32-bit quantity from network byte order to host byte order. 
  814.  
  815. ntohs() Convert a 16-bit quantity from network byte order to host byte order. 
  816.  
  817. recv()* Receive data from a connected socket. 
  818.  
  819. recvfrom()* Receive data from either a connected or unconnected socket. 
  820.  
  821. select()* Perform synchronous I/O multiplexing. 
  822.  
  823. send()* Send data to a connected socket. 
  824.  
  825. sendto()* Send data to either a connected or unconnected socket. 
  826.  
  827. setsockopt() Store options associated with the specified socket descriptor. 
  828.  
  829. shutdown() Shut down part of a full-duplex connection. 
  830.  
  831. socket() Create an endpoint for communication and return a socket descriptor. 
  832.  
  833. * The routine can block if acting on a blocking socket. 
  834.  
  835.  
  836. ΓòÉΓòÉΓòÉ 6.1.1. Blocking/Non blocking & Data Volatility ΓòÉΓòÉΓòÉ
  837.  
  838. One major issue in porting applications from a Berkeley sockets environment to 
  839. a Windows environment involves "blocking"; that is, invoking a function which 
  840. does not return until the associated operation is completed.  The problem 
  841. arises when the operation may take an arbitrarily long time to complete: an 
  842. obvious example is a recv() which may block until data has been received from 
  843. the peer system.  The default behavior within the Berkeley sockets model is for 
  844. a socket to operate in a blocking mode unless the programmer explicitly 
  845. requests that operations be treated as non-blocking.  It is strongly 
  846. recommended that programmers use the nonblocking (asynchronous) operations if 
  847. at all possible, as they work significantly better within the nonpreemptive 
  848. Windows environment.  Use blocking operations only if absolutely necessary, and 
  849. carefully read and understand this section if you must use blocking operations. 
  850.  
  851. Even on a blocking socket, some operations (e.g. bind(), getsockopt(), 
  852. getpeername()) can be completed immediately.  For such operations there is no 
  853. difference between blocking and non-blocking operation.  Other operations (e.g. 
  854. recv()) may be completed immediately or may take an arbitrary time to complete, 
  855. depending on various transport conditions.  When applied to a blocking socket, 
  856. these operations are referred to as blocking operations.  All routines which 
  857. can block are listed with an asterisk in the tables above and below. 
  858.  
  859. Within a Windows Sockets implementation, a blocking operation which cannot be 
  860. completed immediately is handled as follows.  The DLL initiates the operation, 
  861. and then enters a loop in which it dispatches any Windows messages (yielding 
  862. the processor to another thread if necessary) and then checks for the 
  863. completion of the Windows Sockets function.  If the function has completed, or 
  864. if WSACancelBlockingCall() has been invoked, the blocking function completes 
  865. with an appropriate result. Refer to WSASetBlockingHook(), for a complete 
  866. description of this mechanism, including pseudocode for the various functions. 
  867.  
  868. If a Windows message is received for a process for which a blocking operation 
  869. is in progress, there is a risk that the application will attempt to issue 
  870. another Windows Sockets call.  Because of the difficulty of managing this 
  871. condition safely, the Windows Sockets specification does not support such 
  872. application behavior.  Two functions are provided to assist the programmer in 
  873. this situation. WSAIsBlocking() may be called to determine whether or not a 
  874. blocking Windows Sockets call is in progress. WSACancelBlockingCall() may be 
  875. called to cancel an in-progress blocking call, if any.  Any other Windows 
  876. Sockets function which is called in this situation will fail with the error 
  877. WSAEINPROGRESS.  It should be emphasized that this restriction applies to both 
  878. blocking and non-blocking operations. 
  879.  
  880. Although this mechanism is sufficient for simple applications, it cannot 
  881. support the complex message-dispatching requirements of more advanced 
  882. applications (for example, those using the MDI model).  For such applications, 
  883. the Windows Sockets API includes the function WSASetBlockingHook(), which 
  884. allows the programmer to define a special routine which will be called instead 
  885. of the default message dispatch routine described above. 
  886.  
  887. The Windows Sockets DLL will call the blocking hook function only if all of the 
  888. following are true: the routine is one which is defined as being able to block, 
  889. the specified socket is a blocking socket, and the request cannot be completed 
  890. immediately.  (A socket is set to blocking by default, but the IOCTL FIONBIO 
  891. and WSAAsyncSelect() both set a socket to nonblocking mode.)  If an application 
  892. uses only non-blocking sockets and uses the WSAAsyncSelect() and/or the 
  893. WSAAsyncGetXByY() routines instead of select() and the getXbyY() routines, then 
  894. the blocking hook will never be called and the application does not need to be 
  895. concerned with the reentrancy issues the blocking hook can introduce. 
  896.  
  897. If an application invokes an asynchronous or non-blocking operation which takes 
  898. a pointer to a memory object (e.g. a buffer, or a global variable) as an 
  899. argument, it is the responsibility of the application to ensure that the object 
  900. is available to the Windows Sockets implementation throughout the operation. 
  901. The application must not invoke any Windows function which might affect the 
  902. mapping or addressability of the memory involved.  In a multithreaded system, 
  903. the application is also responsible for coordinating access to the object using 
  904. appropriate synchronization mechanisms.  A Windows Sockets implementation 
  905. cannot, and will not, address these issues.  The possible consequences of 
  906. failing to observe these rules are beyond the scope of this specification. 
  907.  
  908.  
  909. ΓòÉΓòÉΓòÉ 6.2. Database Functions ΓòÉΓòÉΓòÉ
  910.  
  911. The Windows Sockets specification defines the following "database" routines. As 
  912. noted earlier, a Windows Sockets supplier may choose to implement these in a 
  913. manner which does not depend on local database files.  The pointer returned by 
  914. certain database routines such as gethostbyname() points to a structure which 
  915. is allocated by the Windows Sockets library.  The data which is pointed to is 
  916. volatile and is good only until the next Windows Sockets API call from that 
  917. thread.  Additionally, the application must never attempt to modify this 
  918. structure or to free any of its components.  Only one copy of this structure is 
  919. allocated for a thread, and so the application should copy any information 
  920. which it needs before issuing any other Windows Sockets API calls. 
  921.  
  922. gethostbyaddr()* Retrieve the name(s) and address corresponding to a network 
  923. address. 
  924.  
  925. gethostname() Retrieve the name of the local host. 
  926.  
  927. gethostbyname()* Retrieve the name(s) and address corresponding to a host name. 
  928.  
  929. getprotobyname()* Retrieve the protocol name and number corresponding to a 
  930. protocol name. 
  931.  
  932. getprotobynumber()* Retrieve the protocol name and number corresponding to a 
  933. protocol number. 
  934.  
  935. getservbyname()* Retrieve the service name and port corresponding to a service 
  936. name. 
  937.  
  938. getservbyport()* Retrieve the service name and port corresponding to a port. 
  939.  
  940. * The routine can block under some circumstances. 
  941.  
  942.  
  943. ΓòÉΓòÉΓòÉ 6.3. Microsoft Windows-specific Extension Functions ΓòÉΓòÉΓòÉ
  944.  
  945. The Windows Sockets specification provides a number of extensions to the 
  946. standard set of Berkeley Sockets routines.  Principally, these extended APIs 
  947. allow message-based, asynchronous access to network events.  While use of this 
  948. extended API set is not mandatory for socket-based programming (with the 
  949. exception of WSAStartup() and WSACleanup()), it is recommended for conformance 
  950. with the Microsoft Windows programming paradigm. 
  951.  
  952. Asynchronous select() Mechanism 
  953.  
  954. Asynchronous Support Routines 
  955.  
  956. Hooking Blocking Methods 
  957.  
  958. Error Handling 
  959.  
  960. Accessing a Windows Sockets DLL from an Intermediate DLL 
  961.  
  962. Internal Use of Messages by Windows Sockets Implementations 
  963.  
  964. Private API Interfaces 
  965.  
  966. WSAAsyncGetHostByAddr() A set of functions which provide asynchronous 
  967.  
  968. WSAAsyncGetHostByName() versions of the standard Berkeley 
  969.  
  970. WSAAsyncGetProtoByName() getXbyY() functions.  For example, the 
  971.  
  972. WSAAsyncGetProtoByNumber() WSAAsyncGetHostByName() function provides an 
  973. asynchronous message based 
  974.  
  975. WSAAsyncGetServByName() implementation of the standard Berkeley 
  976.  
  977. WSAAsyncGetServByPort() gethostbyname() function. 
  978.  
  979. WSAAsyncSelect() Perform asynchronous version of select() 
  980.  
  981. WSACancelAsyncRequest() Cancel an outstanding instance of a WSAAsyncGetXByY() 
  982. function. 
  983.  
  984. WSACancelBlockingCall() Cancel an outstanding "blocking" API call 
  985.  
  986. WSACleanup() Sign off from the underlying Windows Sockets DLL. 
  987.  
  988. WSAGetLastError() Obtain details of last Windows Sockets API error 
  989.  
  990. WSAIsBlocking() Determine if the underlying Windows Sockets DLL is already 
  991. blocking an existing call for this thread 
  992.  
  993. WSASetBlockingHook() "Hook" the blocking method used by the underlying Windows 
  994. Sockets implementation 
  995.  
  996. WSASetLastError() Set the error to be returned by a subsequent 
  997. WSAGetLastError() 
  998.  
  999. WSAStartup() Initialize the underlying Windows Sockets DLL. 
  1000.  
  1001. WSAUnhookBlockingHook() Restore the original blocking function 
  1002.  
  1003.  
  1004. ΓòÉΓòÉΓòÉ 6.3.1. Asynchronous select() Mechanism ΓòÉΓòÉΓòÉ
  1005.  
  1006. The WSAAsyncSelect() API allows an application to register an interest in one 
  1007. or many network events.  This API is provided to supersede the need to do 
  1008. polled network I/O. Any situation in which select() or non-blocking I/O 
  1009. routines (such as send() and recv()) are either already used or are being 
  1010. considered is usually a candidate for the WSAAsyncSelect() API.  When declaring 
  1011. interest in such condition(s), you supply a window handle to be used for 
  1012. notification.  The corresponding window then receives message-based 
  1013. notification of the conditions in which you declared an interest. 
  1014.  
  1015. WSAAsyncSelect() allows interest to be declared in the following conditions for 
  1016. a particular socket: 
  1017.  
  1018.      Socket readiness for reading 
  1019.  
  1020.      Socket readiness for writing 
  1021.  
  1022.      Out-of-band data ready for reading 
  1023.  
  1024.      Socket readiness for accepting incoming connection 
  1025.  
  1026.      Completion of non-blocking connect() 
  1027.  
  1028.      Connection closure 
  1029.  
  1030.  
  1031. ΓòÉΓòÉΓòÉ 6.3.2. Asynchronous Support Routines ΓòÉΓòÉΓòÉ
  1032.  
  1033. The asynchronous "database" functions allow applications to request information 
  1034. in an asynchronous manner.  Some network implementations and/or configurations 
  1035. perform network based operations to resolve such requests.  The 
  1036. WSAAsyncGetXByY() functions allow application developers to request services 
  1037. which would otherwise block the operation of the whole Windows environment if 
  1038. the standard Berkeley function were used.  The WSACancelAsyncRequest() function 
  1039. allows an application to cancel any outstanding asynchronous request. 
  1040.  
  1041.  
  1042. ΓòÉΓòÉΓòÉ 6.3.3. Hooking Blocking Methods ΓòÉΓòÉΓòÉ
  1043.  
  1044. As noted in Blocking/Non blocking & Data Volatility, Windows Sockets implements 
  1045. blocking operations in such a way that Windows message processing can continue, 
  1046. which may result in the application which issued the call receiving a Windows 
  1047. message.  In certain situations an application may want to influence or change 
  1048. the way in which this pseudo-blocking process is implemented.  The 
  1049. WSASetBlockingHook() provides the ability to substitute a named routine which 
  1050. the Windows Sockets implementation is to use when relinquishing the processor 
  1051. during a "blocking" operation. 
  1052.  
  1053.  
  1054. ΓòÉΓòÉΓòÉ 6.3.4. Error Handling ΓòÉΓòÉΓòÉ
  1055.  
  1056. For compatibility with thread-based environments, details of API errors are 
  1057. obtained through the WSAGetLastError() API.  Although the accepted 
  1058. "Berkeley-Style" mechanism for obtaining socket-based network errors is via 
  1059. "errno", this mechanism cannot guarantee the integrity of an error ID in a 
  1060. multi-threaded environment. WSAGetLastError() allows you to retrieve an error 
  1061. code on a per thread basis. 
  1062.  
  1063. WSAGetLastError() returns error codes which avoid conflict with standard 
  1064. Microsoft C error codes. Certain error codes returned by certain Windows 
  1065. Sockets routines fall into the standard range of error codes as defined by 
  1066. Microsoft C.  If you are NOT using an application development environment which 
  1067. defines error codes consistent with Microsoft C, you are advised to use the 
  1068. Windows Sockets error codes prefixed by "WSA" to ensure accurate error code 
  1069. detection. 
  1070.  
  1071. Note that this specification defines a recommended set of error codes, and 
  1072. lists the possible errors which may be returned as a result of each function. 
  1073. It may be the case in some implementations that other Windows Sockets error 
  1074. codes will be returned in addition to those listed, and applications should be 
  1075. prepared to handle errors other than those enumerated under each API 
  1076. description.  However a Windows Sockets implementation must not return any 
  1077. value which is not enumerated in the table of legal Windows Sockets errors 
  1078. given in Error Codes. 
  1079.  
  1080.  
  1081. ΓòÉΓòÉΓòÉ 6.3.5. Accessing a Windows Sockets DLL from an Intermediate DLL ΓòÉΓòÉΓòÉ
  1082.  
  1083. A Windows Sockets DLL may be accessed both directly from an application and 
  1084. through an "intermediate" DLL.  An example of such an intermediate DLL would be 
  1085. a virtual network API layer that supports generalized network functionality for 
  1086. applications and uses Windows Sockets.  Such a DLL could be used by several 
  1087. applications simultaneously, and the DLL must take special precautions with 
  1088. respect to the WSAStartup() and WSACleanup() calls to ensure that these 
  1089. routines are called in the context of each task that will make Windows Sockets 
  1090. calls.  This is because the Windows Sockets DLL will need a call to 
  1091. WSAStartup() for each task in order to set up task-specific data structures, 
  1092. and a call to WSACleanup() to free any resources allocated for the task. 
  1093.  
  1094. There are (at least) two ways to accomplish this.  The simplest method is for 
  1095. the intermediate DLL to have calls similiar to WSAStartup() and WSACleanup() 
  1096. that applications call as appropriate.  The DLL would then call WSAStartup() or 
  1097. WSACleanup() from within these routines.  Another mechanism is for the 
  1098. intermediate DLL to build a table of task handles, which are obtained from the 
  1099. GetCurrentTask() Windows API, and at each entry point into the intermediate DLL 
  1100. check whether WSAStartup() has been called for the current task, then call 
  1101. WSAStartup() if necessary. 
  1102.  
  1103. If a DLL makes a blocking call and does not install its own blocking hook, then 
  1104. the DLL author must be aware that control may be returned to the application 
  1105. either by an application-installed blocking hook or by the default blocking 
  1106. hook.  Thus, it is possible that the application will cancel the DLL's blocking 
  1107. operation via WSACancelBlockingCall(). If this occurs, the DLL's blocking 
  1108. operation will fail with the error code WSAEINTR, and the DLL must return 
  1109. control to the calling task as quickly as possible, as the used has likely 
  1110. pressed a cancel or close button and the task has requested control of the CPU. 
  1111. It is recommended that DLLs which make blocking calls install their own 
  1112. blocking hooks with WSASetBlockingHook() to prevent unforeseen interactions 
  1113. between the application and the DLL. 
  1114.  
  1115. Note that this is not necessary for DLLs in Windows NT because of its different 
  1116. process and DLL structure.  Under Windows NT, the intermediate DLL could simply 
  1117. call WSAStartup() in its DLL initialization routine, which is called whenever a 
  1118. new process which uses the DLL starts. 
  1119.  
  1120.  
  1121. ΓòÉΓòÉΓòÉ 6.3.6. Internal use of Messages by Windows Sockets Implementations ΓòÉΓòÉΓòÉ
  1122.  
  1123. In order to implement Windows Sockets purely as a DLL, it may be necessary for 
  1124. the DLL to post messages internally for communication and timing.  This is 
  1125. perfectly legal; however, a Windows Sockets DLL must not post messages to a 
  1126. window handle opened by a client application except for those messages 
  1127. requested by the application.  A Windows Sockets DLL that needs to use messages 
  1128. for its own purposes must open a hidden window and post any necessary messages 
  1129. to the handle for that window. 
  1130.  
  1131.  
  1132. ΓòÉΓòÉΓòÉ 6.3.7. Private API Interfaces ΓòÉΓòÉΓòÉ
  1133.  
  1134. The winsock.def file lists the ordinals defined for the Windows Sockets APIs. 
  1135. In addition to the ordinal values listed, all ordinals 999 and below are 
  1136. reserved for future Windows Sockets use.  It may be convenient for a Windows 
  1137. Sockets implementation to export additional, private interfaces from the 
  1138. Windows Sockets DLL.  This is perfectly acceptable, as long as the ordinals for 
  1139. these exports are above 1000. Note that any application that uses a particular 
  1140. Windows Sockets DLL's private APIs will most likely not work on any other 
  1141. vendor's Windows Sockets implementation.  Only the APIs defined in this 
  1142. document are guaranteed to be present in every Windows Sockets implementation. 
  1143.  
  1144. If an application uses private interfaces of a particular vendor's Windows 
  1145. Sockets DLL, it is recommended that the DLL not be statically linked with the 
  1146. application but rather dynamically loaded with the Windows routines 
  1147. LoadLibrary() and GetProcAddress().  This allows the application to give an 
  1148. informative error message if it is run on a system with a Windows Sockets DLL 
  1149. that does not support the same set of extended functionality. 
  1150.  
  1151.  
  1152. ΓòÉΓòÉΓòÉ 7. Socket Library Reference ΓòÉΓòÉΓòÉ
  1153.  
  1154.  
  1155. ΓòÉΓòÉΓòÉ 7.1. Socket Routines ΓòÉΓòÉΓòÉ
  1156.  
  1157. This chapter presents the socket library routines in alphabetical order, and 
  1158. describes each routine in detail. 
  1159.  
  1160. In each routine it is indicated that the header file winsock.h must be 
  1161. included. Header Files lists the Berkeley-compatible header files which are 
  1162. supported. These are provided for compatibility purposes only, and each of them 
  1163. will simply include winsock.h. The Windows header file windows.h is also 
  1164. needed, but winsock.h will include it if necessary. 
  1165.  
  1166.  
  1167. ΓòÉΓòÉΓòÉ 7.1.1. accept() ΓòÉΓòÉΓòÉ
  1168.  
  1169. Description 
  1170.  
  1171. Accept a connection on a socket. 
  1172.  
  1173. #include <winsock.h>
  1174.  
  1175. SOCKET PASCAL FAR accept ( SOCKET s, struct sockaddr FAR * addr, int FAR * 
  1176. addrlen); 
  1177.  
  1178.  s 
  1179.    A descriptor identifying a socket which is listening for connections after a 
  1180.    listen(). 
  1181.  
  1182.  addr 
  1183.    An optional pointer to a buffer which receives the address of the connecting 
  1184.    entity, as known to the communications layer.  The exact format of the addr 
  1185.    argument is determined by the address family established when the socket was 
  1186.    created. 
  1187.  
  1188.  addrlen 
  1189.    A optional pointer to an integer which contains the length of the address 
  1190.    addr. 
  1191.  
  1192.  Remarks 
  1193.  
  1194.  This routine extracts the first connection on the queue of pending connections 
  1195.  on s, creates a new socket with the same properties as s and returns a handle 
  1196.  to the new socket.  If no pending connections are present on the queue, and 
  1197.  the socket is not marked as non-blocking, accept() blocks the caller until a 
  1198.  connection is present.  If the socket is marked non-blocking and no pending 
  1199.  connections are present on the queue, accept() returns an error as described 
  1200.  below.  The accepted socket may not be used to accept more connections.  The 
  1201.  original socket remains open. 
  1202.  
  1203.  The argument addr is a result parameter that is filled in with the address of 
  1204.  the connecting entity, as known to the communications layer.  The exact format 
  1205.  of the addr parameter is determined by the address family in which the 
  1206.  communication is occurring.  The addrlen is a value-result parameter; it 
  1207.  should initially contain the amount of space pointed to by addr; on return it 
  1208.  will contain the actual length (in bytes) of the address returned.  This call 
  1209.  is used with connection-based socket types such as SOCK_STREAM.  If addr 
  1210.  and/or addrlen are equal to NULL, then no information about the remote address 
  1211.  of the accepted socket is returned. 
  1212.  
  1213.  Return Value 
  1214.  
  1215.  If no error occurs, accept() returns a value of type SOCKET which is a 
  1216.  descriptor for the accepted packet.  Otherwise, a value of INVALID_SOCKET is 
  1217.  returned, and a specific error code may be retrieved by calling 
  1218.  WSAGetLastError(). 
  1219.  
  1220.  The integer referred to by addrlen initially contains the amount of space 
  1221.  pointed to by addr.  On return it will contain the actual length in bytes of 
  1222.  the address returned. 
  1223.  
  1224.  Error Codes 
  1225.  
  1226.  WSANOTINITIALISED 
  1227.            A successful WSAStartup() must occur before using this API. 
  1228.  
  1229.  WSAENETDOWN 
  1230.            The Windows Sockets implementation has detected that the network 
  1231.            subsystem has failed. 
  1232.  
  1233.  WSAEFAULT 
  1234.            The addrlen argument is too small (less than the sizeof a struct 
  1235.            sockaddr). 
  1236.  
  1237.  WSAEINTR 
  1238.            The (blocking) call was canceled via WSACancelBlockingCall() 
  1239.  
  1240.  WSAEINPROGRESS 
  1241.            A blocking Windows Sockets call is in progress. 
  1242.  
  1243.  WSAEINVAL 
  1244.            listen() was not invoked prior to accept(). 
  1245.  
  1246.  WSAEMFILE 
  1247.            The queue is empty upon entry to accept() and there are no 
  1248.            descriptors available. 
  1249.  
  1250.  WSAENOBUFS 
  1251.            No buffer space is available. 
  1252.  
  1253.  WSAENOTSOCK 
  1254.            The descriptor is not a socket. 
  1255.  
  1256.  WSAEOPNOTSUPP 
  1257.            The referenced socket is not a type that supports 
  1258.            connection-oriented service. 
  1259.  
  1260.  WSAEWOULDBLOCK 
  1261.            The socket is marked as non-blocking and no connections are present 
  1262.            to be accepted. 
  1263.  
  1264.  See Also 
  1265.  
  1266.  bind(), connect(), listen(), select(), socket(), WSAAsyncSelect() 
  1267.  
  1268.  
  1269. ΓòÉΓòÉΓòÉ 7.1.2. bind() ΓòÉΓòÉΓòÉ
  1270.  
  1271. Description 
  1272.  
  1273. Associate a local address with a socket. 
  1274.  
  1275. #include <winsock.h>
  1276.  
  1277. int PASCAL FAR bind ( SOCKET s, const struct sockaddr FAR * name, int namelen); 
  1278.  
  1279.  s 
  1280.    A descriptor identifying an unbound socket. 
  1281.  
  1282.  name 
  1283.    The address to assign to the socket.  The sockaddr structure is defined as 
  1284.    follows: 
  1285.  
  1286.  
  1287.           struct sockaddr {
  1288.                   u_short sa_family;
  1289.                   char    sa_data╤ì14ΓêÖ;
  1290.           };
  1291.  
  1292.  namelen 
  1293.    The length of the name. 
  1294.  
  1295.  Remarks 
  1296.  
  1297.  This routine is used on an unconnected datagram or stream socket, before 
  1298.  subsequent connect()s or listen()s. When a socket is created with socket(), it 
  1299.  exists in a name space (address family), but it has no name assigned. bind() 
  1300.  establishes the local association (host address/port number) of the socket by 
  1301.  assigning a local name to an unnamed socket. 
  1302.  
  1303.  In the Internet address family, a name consists of several components.  For 
  1304.  SOCK_DGRAM and SOCK_STREAM, the name consists of three parts: a host address, 
  1305.  the protocol number (set implicitly to UDP or TCP, respectively), and a port 
  1306.  number which identifies the application.  If an application does not care what 
  1307.  address is assigned to it, it may specify an Internet address equal to 
  1308.  INADDR_ANY, a port equal to 0, or both.  If the Internet address is equal to 
  1309.  INADDR_ANY, any appropriate network interface will be used; this simplifies 
  1310.  application programming in the presence of multi-homed hosts.  If the port is 
  1311.  specified as 0, the Windows Sockets implementation will assign a unique port 
  1312.  to the application with a value between 1024 and 5000.  The application may 
  1313.  use getsockname() after bind() to learn the address that has been assigned to 
  1314.  it, but note that getsockname() will not necessarily fill in the Internet 
  1315.  address until the socket is connected, since several Internet addresses may be 
  1316.  valid if the host is multi-homed. 
  1317.  
  1318.  If an application desires to bind to an arbitrary port outside of the range 
  1319.  1024 to 5000, such as the case of rsh which must bind to any reserved port, 
  1320.  code similar to the following may be used: 
  1321.  
  1322.       SOCKADDR_IN sin;
  1323.       SOCKET s;
  1324.       u_short alport = IPPORT_RESERVED;
  1325.  
  1326.       sin.sin_family = AF_INET;
  1327.       sin.sin_addr.s_addr = 0;
  1328.       for (;;) {
  1329.           sin.sin_port = htons(alport);
  1330.           if (bind(s, (LPSOCKADDR)&sin, sizeof (sin)) == 0) {
  1331.               /* it worked */
  1332.           }
  1333.           if ( GetLastError() ]= WSAEADDRINUSE) {
  1334.               /* fail */
  1335.           }
  1336.           alport--;
  1337.           if (alport == IPPORT_RESERVED/2 ) {
  1338.               /* fail--all unassigned reserved ports are */
  1339.               /* in use. */
  1340.           }
  1341.       }
  1342.  
  1343.  Return Value 
  1344.  
  1345.  If no error occurs, bind() returns 0.  Otherwise, it returns SOCKET_ERROR, and 
  1346.  a specific error code may be retrieved by calling WSAGetLastError(). 
  1347.  
  1348.  Error Codes 
  1349.  
  1350.  WSANOTINITIALISED 
  1351.            A successful WSAStartup() must occur before using this API. 
  1352.  
  1353.  WSAENETDOWN 
  1354.            The Windows Sockets implementation has detected that the network 
  1355.            subsystem has failed. 
  1356.  
  1357.  WSAEADDRINUSE 
  1358.            The specified address is already in use.  (See the SO_REUSEADDR 
  1359.            socket option under setsockopt().) 
  1360.  
  1361.  WSAEFAULT 
  1362.            The namelen argument is too small (less than the size of a struct 
  1363.            sockaddr). 
  1364.  
  1365.  WSAEINTR 
  1366.            The (blocking) call was canceled via WSACancelBlockingCall() 
  1367.  
  1368.  WSAEINPROGRESS 
  1369.            A blocking Windows Sockets call is in progress. 
  1370.  
  1371.  WSAEAFNOSUPPORT 
  1372.            The specified address family is not supported by 
  1373.  
  1374.  this protocol. 
  1375.  
  1376.  WSAEINVAL 
  1377.            The socket is already bound to an address. 
  1378.  
  1379.  WSAENOBUFS 
  1380.            Not enough buffers available, too many connections. 
  1381.  
  1382.  WSAENOTSOCK 
  1383.            The descriptor is not a socket.
  1384.  
  1385.  See Also 
  1386.  
  1387.  connect(), listen(), getsockname(), setsockopt(), socket(), 
  1388.  WSACancelBlockingCall() 
  1389.  
  1390.  
  1391. ΓòÉΓòÉΓòÉ 7.1.3. closesocket() ΓòÉΓòÉΓòÉ
  1392.  
  1393. Description 
  1394.  
  1395. Close a socket. 
  1396.  
  1397. #include <winsock.h>
  1398.  
  1399. int FAR PASCAL closesocket ( SOCKET s); 
  1400.  
  1401.  s 
  1402.    A descriptor identifying a socket. 
  1403.  
  1404.  Remarks 
  1405.  
  1406.  This function closes a socket.  More precisely, it releases the socket 
  1407.  descriptor s, so that further references to s will fail with the error 
  1408.  WSAENOTSOCK.  If this is the last reference to the underlying socket, the 
  1409.  associated naming information and queued data are discarded. 
  1410.  
  1411.  The semantics of closesocket() are affected by the socket options SO_LINGER 
  1412.  and SO_DONTLINGER as follows: 
  1413.  
  1414.   Option               Interval        Type of close           Wait for close?
  1415.   --------------- --------------- ----------------------- ----------------
  1416.   SO_DONTLINGER   Don't care      Graceful                No
  1417.  
  1418.   SO_LINGER       Zero            Hard                    No
  1419.  
  1420.   SO_LINGER       Non-zero        Graceful                Yes
  1421.  
  1422.  If SO_LINGER is set (i.e. the l_onoff field of the linger structure is 
  1423.  non-zero; see Socket Options, getsockopt() and setsockopt()) with a zero 
  1424.  timeout interval (l_linger is zero), closesocket() is not blocked even if 
  1425.  queued data has not yet been sent or acknowledged.  This is called a "hard" 
  1426.  close, because the socket is closed immediately, and any unsent data is lost. 
  1427.  Any recv() call on the remote side of the circuit can fail with WSAECONNRESET. 
  1428.  
  1429.  If SO_LINGER is set with a non-zero timeout interval, the closesocket() call 
  1430.  blocks until the remaining data has been sent or until the timeout expires. 
  1431.  This is called a graceful disconnect.  Note that if the socket is set to 
  1432.  non-blocking and SO_LINGER is set to a non-zero timeout, the call to 
  1433.  closesocket() will fail with an error of WSAEWOULDBLOCK. If SO_DONTLINGER is 
  1434.  set on a stream socket (i.e. the l_onoff field of the linger structure is 
  1435.  zero; see Socket Options, getsockopt() and setsockopt()), the closesocket() 
  1436.  call will return immediately.  However, any data queued for transmission will 
  1437.  be sent if possible before the underlying socket is closed.  This is also 
  1438.  called a graceful disconnect.  Note that in this case the Windows Sockets 
  1439.  implementation may not release the socket and other resources for an arbitrary 
  1440.  period, which may affect applications which expect to use all available 
  1441.  sockets. 
  1442.  
  1443.  Return Value 
  1444.  
  1445.  If no error occurs, closesocket() returns 0. Otherwise, a value of 
  1446.  SOCKET_ERROR is returned, and a specific error code may be retrieved by 
  1447.  calling WSAGetLastError() 
  1448.  
  1449.  Error Codes 
  1450.  
  1451.  WSANOTINITIALISED 
  1452.            A successful WSAStartup() must occur before using this API. 
  1453.  
  1454.  WSAENETDOWN 
  1455.            The Windows Sockets implementation has detected that the network 
  1456.            subsystem has failed. 
  1457.  
  1458.  WSAENOTSOCK 
  1459.            The descriptor is not a socket. 
  1460.  
  1461.  WSAEINPROGRESS 
  1462.            A blocking Windows Sockets call is in progress. 
  1463.  
  1464.  WSAEINTR 
  1465.            The (blocking) call was canceled via WSACancelBlockingCall() 
  1466.  
  1467.  WSAEWOULDBLOCK 
  1468.            The socket is marked as nonblocking and SO_LINGER is set to a 
  1469.            nonzero timeout value. 
  1470.  
  1471.  See Also 
  1472.  
  1473.  accept(), socket(), ioctlsocket(), setsockopt(), WSAAsyncSelect() 
  1474.  
  1475.  
  1476. ΓòÉΓòÉΓòÉ 7.1.4. connect() ΓòÉΓòÉΓòÉ
  1477.  
  1478. Description 
  1479.  
  1480. Establish a connection to a peer. 
  1481.  
  1482. #include <winsock.h>
  1483.  
  1484. int PASCAL FAR connect ( SOCKET s, const struct sockaddr FAR * name, int 
  1485. namelen); 
  1486.  
  1487.  s 
  1488.    A descriptor identifying an unconnected socket. 
  1489.  
  1490.  name 
  1491.    The name of the peer to which the socket is to be connected. 
  1492.  
  1493.  namelen 
  1494.    The length of the name. 
  1495.  
  1496.  Remarks 
  1497.  
  1498.  This function is used to create a connection to the specified foreign 
  1499.  association.  The parameter s specifies an unconnected datagram or stream 
  1500.  socket  If the socket is unbound, unique values are assigned to the local 
  1501.  association by the system, and the socket is marked as bound.  Note that if 
  1502.  the address field of the name structure is all zeroes, connect() will return 
  1503.  the error WSAEADDRNOTAVAIL. 
  1504.  
  1505.  For stream sockets (type SOCK_STREAM), an active connection is initiated to 
  1506.  the foreign host using name (an address in the name space of the socket). When 
  1507.  the socket call completes successfully, the socket is ready to send/receive 
  1508.  data. 
  1509.  
  1510.  For a datagram socket (type SOCK_DGRAM), a default destination is set, which 
  1511.  will be used on subsequent send() and recv() calls. 
  1512.  
  1513.  On a non-blocking socket, if the return value is SOCKET_ERROR an application 
  1514.  should call WSAGetLastError() If this indicates an error code of 
  1515.  WSAEWOULDBLOCK, then your application can either: 
  1516.  
  1517.    1. Use select() to determine the completion of the connection request by 
  1518.       checking if the socket is writeable, or 
  1519.  
  1520.    2. If your application is using the message-based WSAAsyncSelect() to 
  1521.       indicate interest in connection events, then your application will 
  1522.       receive an FD_CONNECT message when the connect operation is complete. 
  1523.  
  1524.  Return Value 
  1525.  
  1526.  If no error occurs, connect() returns 0.  Otherwise, it returns SOCKET_ERROR, 
  1527.  and a specific error code may be retrieved by calling WSAGetLastError() 
  1528.  
  1529.  On a blocking socket, the return value indicates success or failure of the 
  1530.  connection attempt. 
  1531.  
  1532.  Error Codes 
  1533.  
  1534.  WSANOTINITIALISED 
  1535.            A successful WSAStartup() must occur before using this API. 
  1536.  
  1537.  WSAENETDOWN 
  1538.            The Windows Sockets implementation has detected that the network 
  1539.            subsystem has failed. 
  1540.  
  1541.  WSAEADDRINUSE 
  1542.            The specified address is already in use. 
  1543.  
  1544.  WSAEINTR 
  1545.            The (blocking) call was canceled via WSACancelBlockingCall() 
  1546.  
  1547.  WSAEINPROGRESS 
  1548.            A blocking Windows Sockets call is in progress. 
  1549.  
  1550.  WSAEADDRNOTAVAIL 
  1551.            The specified address is not available from the local machine. 
  1552.  
  1553.  WSAEAFNOSUPPORT 
  1554.            Addresses in the specified family cannot be used with this socket. 
  1555.  
  1556.  WSAECONNREFUSED 
  1557.            The attempt to connect was forcefully rejected. 
  1558.  
  1559.  WSAEDESTADDREQ 
  1560.            A destination address is required. 
  1561.  
  1562.  WSAEFAULT 
  1563.            The namelen argument is incorrect. 
  1564.  
  1565.  WSAEINVAL 
  1566.            The socket is not already bound to an address. 
  1567.  
  1568.  WSAEISCONN 
  1569.            The socket is already connected. 
  1570.  
  1571.  WSAEMFILE 
  1572.            No more file descriptors are available. 
  1573.  
  1574.  WSAENETUNREACH 
  1575.            The network can't be reached from this host at this time. 
  1576.  
  1577.  WSAENOBUFS 
  1578.            No buffer space is available.  The socket cannot be connected. 
  1579.  
  1580.  WSAENOTSOCK 
  1581.            The descriptor is not a socket. 
  1582.  
  1583.  WSAETIMEDOUT 
  1584.            Attempt to connect timed out without establishing a connection 
  1585.  
  1586.  WSAEWOULDBLOCK 
  1587.            The socket is marked as non-blocking and the connection cannot be 
  1588.            completed immediately.  It is possible to select() the socket while 
  1589.            it is connecting by select()ing it for writing.
  1590.  
  1591.  See Also 
  1592.  
  1593.  accept(), bind(), getsockname(), socket(), and WSAAsyncSelect 
  1594.  
  1595.  
  1596. ΓòÉΓòÉΓòÉ 7.1.5. getpeername() ΓòÉΓòÉΓòÉ
  1597.  
  1598. Description 
  1599.  
  1600. Get the address of the peer to which a socket is connected. 
  1601.  
  1602. #include <winsock.h>
  1603.  
  1604. int PASCAL FAR getpeername(SOCKET s, struct sockaddr FAR * name, int FAR * 
  1605. namelen); 
  1606.  
  1607.  s 
  1608.    A descriptor identifying a connected socket. 
  1609.  
  1610.  name 
  1611.    The structure which is to receive the name of the peer. 
  1612.  
  1613.  namelen 
  1614.    A pointer to the size of the name structure. 
  1615.  
  1616.  Remarks 
  1617.  
  1618.  getpeername() retrieves the name of the peer connected to the socket s and 
  1619.  stores it in the struct sockaddr identified by name.  It is used on a 
  1620.  connected datagram or stream socket. On return, the namelen argument contains 
  1621.  the actual size of the name returned in bytes. 
  1622.  
  1623.  Return Value 
  1624.  
  1625.  If no error occurs, getpeername() returns 0. Otherwise, a value of 
  1626.  SOCKET_ERROR is returned, and a specific error code may be retrieved by 
  1627.  calling WSAGetLastError() 
  1628.  
  1629.  Error Codes 
  1630.  
  1631.  WSANOTINITIALISED 
  1632.            A successful WSAStartup() must occur before using this API. 
  1633.  
  1634.  WSAENETDOWN 
  1635.            The Windows Sockets implementation has detected that the network 
  1636.            subsystem has failed. 
  1637.  
  1638.  WSAEFAULT 
  1639.            The namelen argument is not large enough. 
  1640.  
  1641.  WSAEINPROGRESS 
  1642.            A blocking Windows Sockets call is in progress. 
  1643.  
  1644.  WSAENOTCONN 
  1645.            The socket is not connected. 
  1646.  
  1647.  WSAENOTSOCK 
  1648.            The descriptor is not a socket.
  1649.  
  1650.  See Also 
  1651.  
  1652.  bind(), socket(), getsockname() 
  1653.  
  1654.  
  1655. ΓòÉΓòÉΓòÉ 7.1.6. getsockname() ΓòÉΓòÉΓòÉ
  1656.  
  1657. Description 
  1658.  
  1659. Get the local name for a socket. 
  1660.  
  1661. #include <winsock.h>
  1662.  
  1663. int PASCAL FAR getsockname(SOCKET s, struct sockaddr FAR * name, int FAR * 
  1664. namelen); 
  1665.  
  1666.  s 
  1667.    A descriptor identifying a bound socket. 
  1668.  
  1669.  name 
  1670.    Receives the address (name) of the socket. 
  1671.  
  1672.  namelen 
  1673.    The size of the name buffer. 
  1674.  
  1675.  Remarks 
  1676.  
  1677.  getsockname() retrieves the current name for the specified socket descriptor 
  1678.  in name.  It is used on a bound and/or connected socket specified by the s 
  1679.  parameter.  The local association is returned.  This call is especially useful 
  1680.  when a connect() call has been made without doing a bind() first; this call 
  1681.  provides the only means by which you can determine the local association which 
  1682.  has been set by the system. 
  1683.  
  1684.      On return, the namelen     argument contains the actual size of the name 
  1685.  returned in bytes. 
  1686.  
  1687.  If a socket was bound to INADDR_ANY, indicating that any of the host's IP 
  1688.  addresses should be used for the socket, getsockname() will not necessarily 
  1689.  return information about the host IP address, unless the socket has been 
  1690.  connected with connect() or accept() A Windows Sockets application must not 
  1691.  assume that the IP address will be changed from INADDR_ANY unless the socket 
  1692.  is connected.  This is because for a multi-homed host the IP address that will 
  1693.  be used for the socket is unknown unless the socket is connected. 
  1694.  
  1695.  Return Value 
  1696.  
  1697.  If no error occurs, getsockname() returns 0. Otherwise, a value of 
  1698.  SOCKET_ERROR is returned, and a specific error code may be retrieved by 
  1699.  calling WSAGetLastError() 
  1700.  
  1701.  Error Codes 
  1702.  
  1703.  WSANOTINITIALISED 
  1704.            A successful WSAStartup() must occur before using this API. 
  1705.  
  1706.  WSAENETDOWN 
  1707.            The Windows Sockets implementation has detected that the network 
  1708.            subsystem has failed. 
  1709.  
  1710.  WSAEFAULT 
  1711.            The namelen argument is not large enough. 
  1712.  
  1713.  WSAEINPROGRESS 
  1714.            A blocking Windows Sockets operation is in progress. 
  1715.  
  1716.  WSAENOTSOCK 
  1717.            The descriptor is not a socket. 
  1718.  
  1719.  WSAEINVAL 
  1720.            The socket has not been bound to an address with bind()
  1721.  
  1722.  See Also 
  1723.  
  1724.  bind(), socket(), getpeername() 
  1725.  
  1726.  
  1727. ΓòÉΓòÉΓòÉ 7.1.7. getsockopt() ΓòÉΓòÉΓòÉ
  1728.  
  1729. Description 
  1730.  
  1731. Retrieve a socket option. 
  1732.  
  1733. #include <winsock.h>
  1734.  
  1735. int PASCAL FAR getsockopt ( SOCKET s, int level, int optname, char FAR * 
  1736. optval, int FAR * optlen); 
  1737.  
  1738.  s 
  1739.    A descriptor identifying a socket. 
  1740.  
  1741.  level 
  1742.    The level at which the option is defined; the only supported levels are 
  1743.    SOL_SOCKET and IPPROTO_TCP. 
  1744.  
  1745.  optname 
  1746.    The socket option for which the value is to be retrieved. 
  1747.  
  1748.  optval 
  1749.    A pointer to the buffer in which the value for the requested option is to be 
  1750.    returned. 
  1751.  
  1752.  optlen 
  1753.    A pointer to the size of the optval buffer. 
  1754.  
  1755.  Remarks 
  1756.  
  1757.  getsockopt() retrieves the current value for a socket option associated with a 
  1758.  socket of any type, in any state, and stores the result in optval.  Options 
  1759.  may exist at multiple protocol levels, but they are always present at the 
  1760.  uppermost "socket" level.  Options affect socket operations, such as whether 
  1761.  an operation blocks or not, the routing of packets, out-of-band data transfer, 
  1762.  etc. The value associated  with the selected option is returned in the buffer 
  1763.  optval.  The integer pointed to by  optlen should originally contain the size 
  1764.  of this buffer; on return, it will be set to the size of the value returned. 
  1765.  For SO_LINGER, this will be the size of  a struct linger; for all other 
  1766.  options it will be the size of an integer. 
  1767.  
  1768.  If the option was never set with setsockopt(), then getsockopt() returns the 
  1769.  default value for the option. 
  1770.  
  1771.  The following options are supported for getsockopt().  The Type identifies the 
  1772.  type of data addressed by optval.  The TCP_NODELAY option uses level 
  1773.  IPPROTO_TCP, all other options use level SOL_SOCKET. 
  1774.  
  1775.   Value             Type            Meaning
  1776.   --------------- --------------- -----------------------------------------------
  1777.   SO_ACCEPTCONN   BOOL            Socket is listen()ing.
  1778.  
  1779.   SO_BROADCAST    BOOL            Socket is configured for the transmission of
  1780.                                   broadcast messages.
  1781.  
  1782.   SO_DEBUG        BOOL            Debugging is enabled.
  1783.  
  1784.   SO_DONTLINGER   BOOL            If true, the SO_LINGER option is disabled..
  1785.  
  1786.   SO_DONTROUTE    BOOL            Routing is disabled.
  1787.  
  1788.   SO_ERROR        int             Retrieve error status and clear.
  1789.  
  1790.   SO_KEEPALIVE    BOOL            Keepalives are being sent.
  1791.  
  1792.   SO_LINGER       struct linger   Returns the current linger options.
  1793.                   FAR *
  1794.  
  1795.   SO_OOBINLINE    BOOL            Out-of-band data is being received in the
  1796.                                   normal data stream.
  1797.  
  1798.   SO_RCVBUF       int             Buffer size for receives
  1799.  
  1800.   SO_REUSEADDR    BOOL            The socket may be bound to an address which
  1801.                                   is already in use.
  1802.  
  1803.   SO_SNDBUF       int             Buffer size for sends
  1804.  
  1805.   SO_TYPE         int             The type of the socket (e.g. SOCK_STREAM).
  1806.  
  1807.   TCP_NODELAY     BOOL            Disables the Nagle algorithm for send
  1808.                                   coalescing.
  1809.  
  1810.  BSD options not supported for getsockopt() are: 
  1811.  
  1812.   Value             Type            Meaning
  1813.   --------------- --------------- -----------------------------------------------
  1814.   SO_RCVLOWAT     int             Receive low water mark
  1815.  
  1816.   SO_RCVTIMEO     int             Receive timeout
  1817.  
  1818.   SO_SNDLOWAT     int             Send low water mark
  1819.  
  1820.   SO_SNDTIMEO     int             Send timeout
  1821.  
  1822.   IP_OPTIONS                      Get options in IP header.
  1823.  
  1824.   TCP_MAXSEG      int             Get TCP maximum segment size.
  1825.  
  1826.  Calling getsockopt() with an unsupported option will result in an error code 
  1827.  of WSAENOPROTOOPT being returned from WSAGetLastError(). 
  1828.  
  1829.  Return Value 
  1830.  
  1831.  If no error occurs, getsockopt() returns 0. Otherwise, a value of SOCKET_ERROR 
  1832.  is returned, and a specific error code may be retrieved by calling 
  1833.  WSAGetLastError(). 
  1834.  
  1835.  Error Codes 
  1836.  
  1837.  WSANOTINITIALISED 
  1838.            A successful WSAStartup() must occur before using this API. 
  1839.  
  1840.  WSAENETDOWN 
  1841.            The Windows Sockets implementation has detected that the network 
  1842.            subsystem has failed. 
  1843.  
  1844.  WSAEFAULT 
  1845.            The optlen argument was invalid. 
  1846.  
  1847.  WSAEINPROGRESS 
  1848.            A blocking Windows Sockets operation is in progress. 
  1849.  
  1850.  WSAENOPROTOOPT 
  1851.            The option is unknown or unsupported.  In particular, SO_BROADCAST 
  1852.            is not supported on sockets of type SOCK_STREAM, while SO_ACCEPTCON, 
  1853.            SO_DONTLINGER, SO_KEEPALIVE, SO_LINGER and SO_OOBINLINE are not 
  1854.            supported on sockets of type SOCK_DGRAM. 
  1855.  
  1856.  WSAENOPROTOOPT 
  1857.            The option is unknown or unsupported.  In particular, SO_BROADCAST 
  1858.            is not supported on sockets of type SOCK_STREAM, while 
  1859.            SO_ACCEPTCONN, SO_DONTLINGER, SO_KEEPALIVE, SO_LINGER and 
  1860.            SO_OOBINLINE are not supported on sockets of type SOCK_DGRAM. 
  1861.  
  1862.  WSAENOTSOCK 
  1863.            The descriptor is not a socket.
  1864.  
  1865.  See Also 
  1866.  
  1867.  setsockopt(), WSAAsyncSelect(), socket() 
  1868.  
  1869.  
  1870. ΓòÉΓòÉΓòÉ 7.1.8. htonl() ΓòÉΓòÉΓòÉ
  1871.  
  1872. Description 
  1873.  
  1874. Convert a u_long from host to network byte order. 
  1875.  
  1876. #include <winsock.h>
  1877.  
  1878. u_long PASCAL FAR htonl ( u_long hostlong); 
  1879.  
  1880.  hostlong 
  1881.    A 32-bit number in host byte order. 
  1882.  
  1883.  Remarks 
  1884.  
  1885.  This routine takes a 32-bit number in host byte order and returns a 32-bit 
  1886.  number in network byte order. 
  1887.  
  1888.  Return Value 
  1889.  
  1890.  htonl() returns the value in network byte order. 
  1891.  
  1892.  See Also 
  1893.  
  1894.  htons(), ntohl(), ntohs() 
  1895.  
  1896.  
  1897. ΓòÉΓòÉΓòÉ 7.1.9. htons() ΓòÉΓòÉΓòÉ
  1898.  
  1899. Description 
  1900.  
  1901. Convert a u_short from host to network byte order. 
  1902.  
  1903. #include <winsock.h>
  1904.  
  1905. u_short PASCAL FAR htons ( u_short hostshort ); 
  1906.  
  1907.  hostshort 
  1908.    A 16-bit number in host byte order. 
  1909.  
  1910.  Remarks 
  1911.  
  1912.  This routine takes a 16-bit number in host byte order and returns a 16-bit 
  1913.  number in network byte order. 
  1914.  
  1915.  Return Value 
  1916.  
  1917.  htons() returns the value in network byte order. 
  1918.  
  1919.  See Also 
  1920.  
  1921.  htonl(), ntohl(), ntohs() 
  1922.  
  1923.  
  1924. ΓòÉΓòÉΓòÉ 7.1.10. inet_addr() ΓòÉΓòÉΓòÉ
  1925.  
  1926. Description 
  1927.  
  1928. Convert a string containing a dotted address into an in_addr. 
  1929.  
  1930. #include <winsock.h>
  1931.  
  1932. unsigned long PASCAL FAR inet_addr ( const char FAR * cp ); 
  1933.  
  1934.  cp 
  1935.    A character string representing a number expressed in the Internet standard 
  1936.    "." notation. 
  1937.  
  1938.  Remarks 
  1939.  
  1940.  This function interprets the character string specified by the cp parameter. 
  1941.  This string represents a numeric Internet address expressed in the Internet 
  1942.  standard "." notation.  The value returned is a number suitable for use as an 
  1943.  Internet address.  All Internet addresses are returned in network order (bytes 
  1944.  ordered from left to right).  Internet Addresses 
  1945.  
  1946.  Values specified using the "." notation take one of the following forms: 
  1947.  
  1948.      a.b.c.d 
  1949.  
  1950.      a.b.c 
  1951.  
  1952.      a.b 
  1953.  
  1954.      a 
  1955.  
  1956.  When four parts are specified, each is interpreted as a byte of data and 
  1957.  assigned, from left to right, to the four bytes of an Internet address.  Note 
  1958.  that when an Internet address is viewed as a 32-bit integer quantity on the 
  1959.  Intel architecture, the bytes referred to above appear as "d.c.b.a".  That is, 
  1960.  the bytes on an Intel processor are ordered from right to left. 
  1961.  
  1962.  Note: The following notations are only used by Berkeley, and nowhere else on 
  1963.  the Internet.  In the interests of compatibility with their software, they are 
  1964.  supported as specified. 
  1965.  
  1966.  When a three part address is specified, the last part is interpreted as a 
  1967.  16-bit quantity and placed in the right most two bytes of the network address. 
  1968.  This makes the three part address format convenient for specifying Class B 
  1969.  network addresses as "128.net.host". 
  1970.  
  1971.  When a two part address is specified, the last part is interpreted as a 24-bit 
  1972.  quantity and placed in the right most three bytes of the network address. 
  1973.  This makes the two part address format convenient for specifying Class A 
  1974.  network addresses as "net.host". 
  1975.  
  1976.  When only one part is given, the value is stored directly in the network 
  1977.  address without any byte rearrangement. 
  1978.  
  1979.  Return Value 
  1980.  
  1981.  If no error occurs, inet_addr() returns an unsigned long containing a suitable 
  1982.  binary representation of the Internet address given. If the passed-in string 
  1983.  does not contain a legitimate Internet address, for example if a portion of an 
  1984.  "a.b.c.d" address exceeds 255, inet_addr() returns the value INADDR_NONE. 
  1985.  
  1986.  See Also 
  1987.  
  1988.  inet_ntoa() 
  1989.  
  1990.  
  1991. ΓòÉΓòÉΓòÉ 7.1.11. inet_ntoa() ΓòÉΓòÉΓòÉ
  1992.  
  1993. Description 
  1994.  
  1995. Convert a network address into a string in dotted format. 
  1996.  
  1997. #include <winsock.h>
  1998.  
  1999. char FAR * PASCAL FAR inet_ntoa ( struct in_addr in ); 
  2000.  
  2001.  in 
  2002.    A structure which represents an Internet host address. 
  2003.  
  2004.  Remarks 
  2005.  
  2006.  This function takes an Internet address structure specified by the in 
  2007.  parameter.  It returns an ASCII string representing the address in "." 
  2008.  notation as "a.b.c.d".  Note that the string returned by inet_ntoa() resides 
  2009.  in memory which is allocated by the Windows Sockets implementation.  The 
  2010.  application should not make any assumptions about the way in which the memory 
  2011.  is allocated.  The data is guaranteed to be valid until the next Windows 
  2012.  Sockets API call within the same thread, but no longer. 
  2013.  
  2014.  Return Value 
  2015.  
  2016.  If no error occurs, inet_ntoa() returns a char pointer to a static buffer 
  2017.  containing the text address in standard "." notation.  Otherwise, it returns 
  2018.  NULL.  The data should be copied before another Windows Sockets call is made. 
  2019.  
  2020.  See Also 
  2021.  
  2022.  inet_addr() 
  2023.  
  2024.  
  2025. ΓòÉΓòÉΓòÉ 7.1.12. ioctlsocket() ΓòÉΓòÉΓòÉ
  2026.  
  2027. Description 
  2028.  
  2029. Control the mode of a socket. 
  2030.  
  2031. #include <winsock.h>
  2032.  
  2033. int PASCAL FAR ioctlsocket ( SOCKET s, long cmd, u_long FAR * argp); 
  2034.  
  2035.  s 
  2036.    A descriptor identifying a socket. 
  2037.  
  2038.  cmd 
  2039.    The command to perform on the socket s. 
  2040.  
  2041.  argp 
  2042.    A pointer to a parameter for cmd. 
  2043.  
  2044.  Remarks 
  2045.  
  2046.  This routine may be used on any socket in any state.  It is used to get or 
  2047.  retrieve operating parameters associated with the socket, independent of the 
  2048.  protocol and communications subsystem.  The following commands are supported: 
  2049.  
  2050.  FIONBIO 
  2051.            Enable or disable non-blocking mode on the socket s.  argp points at 
  2052.            an unsigned long, which is non-zero if non-blocking mode is to be 
  2053.            enabled and zero if it is to be disabled.  When a socket is created, 
  2054.            it operates in blocking mode (i.e. non-blocking mode is disabled). 
  2055.            This is consistent with BSD sockets. 
  2056.            The WSAAsyncSelect() routine automatically sets a socket to 
  2057.            nonblocking mode.  If WSAAsyncSelect() has been issued on a socket, 
  2058.            then any attempt to use ioctlsocket() to set the socket back to 
  2059.            blocking mode will fail with WSAEINVAL.  To set the socket back to 
  2060.            blocking mode, an application must first disable WSAAsyncSelect() by 
  2061.            calling WSAAsyncSelect() with the lEvent parameter equal to 0. 
  2062.  
  2063.  FIONREAD 
  2064.            Determine the amount of data which can be read atomically from 
  2065.            socket s.  argp points at an unsigned long in which ioctlsocket() 
  2066.            stores the result.  If s is of type SOCK_STREAM, FIONREAD returns 
  2067.            the total amount of data which may be read in a single recv(); this 
  2068.            is normally the same as the total amount of data queued on the 
  2069.            socket.  If s is of type SOCK_DGRAM, FIONREAD returns the size of 
  2070.            the first datagram queued on the socket. 
  2071.  
  2072.  SIOCATMARK 
  2073.            Determine whether or not all out-of-band data has been read.  This 
  2074.            applies only to a socket of type SOCK_STREAM which has been 
  2075.            configured for in-line reception of any out-of-band data 
  2076.            (SO_OOBINLINE).  If no out-of-band data is waiting to be read, the 
  2077.            operation returns TRUE.  Otherwise it returns FALSE, and the next 
  2078.            recv() or recvfrom() performed on the socket will retrieve some or 
  2079.            all of the data preceding the "mark"; the application should use the 
  2080.            SIOCATMARK operation to determine whether any remains.  If there is 
  2081.            any normal data preceding the "urgent" (out of band) data, it will 
  2082.            be received in order.  (Note that a recv() or recvfrom() will never 
  2083.            mix out-of-band and normal data in the same call.)  argp points at a 
  2084.            BOOL in which ioctlsocket() stores the result. 
  2085.  
  2086.  
  2087.  Compatibility This function is a subset of ioctl() as used in Berkeley 
  2088.  sockets.  In particular, there is no command which is equivalent to FIOASYNC, 
  2089.  while SIOCATMARK is the only socket-level command which is supported. 
  2090.  
  2091.  Return Value 
  2092.  
  2093.  Upon successful completion, the ioctlsocket() returns 0.  Otherwise, a value 
  2094.  of SOCKET_ERROR is returned, and a specific error code may be retrieved by 
  2095.  calling WSAGetLastError() 
  2096.  
  2097.  Error Codes 
  2098.  
  2099.  WSANOTINITIALISED 
  2100.            A successful WSAStartup() must occur before using this API. 
  2101.  
  2102.  WSAENETDOWN 
  2103.            The Windows Sockets implementation has detected that the network 
  2104.            subsystem has failed. 
  2105.  
  2106.  WSAEINVAL 
  2107.            cmd is not a valid command, or argp is not an acceptable parameter 
  2108.            for cmd, or the command is not applicable to the type of socket 
  2109.            supplied 
  2110.  
  2111.  WSAEINPROGRESS 
  2112.            A blocking Windows Sockets operation is in progress. 
  2113.  
  2114.  WSAENOTSOCK 
  2115.            The descriptor s is not a socket. 
  2116.  
  2117.  See Also 
  2118.  
  2119.  socket(), setsockopt(), getsockopt(), WSAAsyncSelect() 
  2120.  
  2121.  
  2122. ΓòÉΓòÉΓòÉ 7.1.13. listen() ΓòÉΓòÉΓòÉ
  2123.  
  2124. Description 
  2125.  
  2126. Establish a socket to listen for incoming connection. 
  2127.  
  2128. #include <winsock.h>
  2129.  
  2130. int PASCAL FAR listen(SOCKET s, int backlog ); 
  2131.  
  2132.  s 
  2133.    A descriptor identifying a bound, unconnected socket. 
  2134.  
  2135.  backlog 
  2136.    The maximum length to which the queue of pending connections may grow. 
  2137.  
  2138.  Remarks 
  2139.  
  2140.  To accept connections, a socket is first created with socket(), a backlog for 
  2141.  incoming connections is specified with listen(), and then the connections are 
  2142.  accepted with accept(). listen() applies only to sockets that support 
  2143.  connections, i.e. those of type SOCK_STREAM.  The socket s is put into 
  2144.  "passive" mode where incoming connections are acknowledged and queued pending 
  2145.  acceptance by the process. 
  2146.  
  2147.  This function is typically used by servers that could have more than one 
  2148.  connection request at a time: if a connection request arrives with the queue 
  2149.  full, the client will receive an error with an indication of WSAECONNREFUSED. 
  2150.  listen() attempts to continue to function rationally when there are no 
  2151.  available descriptors.  It will accept connections until the queue is emptied. 
  2152.  If descriptors become available, a later call to listen() or accept() will 
  2153.  re-fill the queue to the current or most recent "backlog", if possible, and 
  2154.  resume listening for incoming connections. 
  2155.  
  2156.  
  2157.  Compatibility backlog is currently limited (silently) to 5.  As in 4.3BSD, 
  2158.  illegal values (less than 1 or greater than 5) are replaced by the nearest 
  2159.  legal value. 
  2160.  
  2161.  Return Value 
  2162.  
  2163.  If no error occurs, listen() returns 0.  Otherwise, a value of SOCKET_ERROR is 
  2164.  returned, and a specific error code may be retrieved by calling 
  2165.  WSAGetLastError(). 
  2166.  
  2167.  Error Codes 
  2168.  
  2169.  WSANOTINITIALISED 
  2170.            A successful WSAStartup() must occur before using this API. 
  2171.  
  2172.  WSAENETDOWN 
  2173.            The Windows Sockets implementation has detected that the network 
  2174.            subsystem has failed. 
  2175.  
  2176.  WSAEADDRINUSE 
  2177.            An attempt has been made to listen() on an address in use. 
  2178.  
  2179.  WSAEINPROGRESS 
  2180.            A blocking Windows Sockets operation is in progress. 
  2181.  
  2182.  WSAEFAULT 
  2183.            An invalid argument was given. 
  2184.  
  2185.  WSAEINVAL 
  2186.            The socket has not been bound with bind() or is already connected. 
  2187.  
  2188.  WSAEISCONN 
  2189.            The socket is already connected. 
  2190.  
  2191.  WSAEMFILE 
  2192.            No more file descriptors are available. 
  2193.  
  2194.  WSAENOBUFS 
  2195.            No buffer space is available. 
  2196.  
  2197.  WSAENOTSOCK 
  2198.            The descriptor is not a socket. 
  2199.  
  2200.  WSAEOPNOTSUPP 
  2201.            The referenced socket is not of a type that supports the listen() operation.
  2202.  
  2203.  See Also 
  2204.  
  2205.  accept(), connect(), socket() 
  2206.  
  2207.  
  2208. ΓòÉΓòÉΓòÉ 7.1.14. ntohl() ΓòÉΓòÉΓòÉ
  2209.  
  2210. Description 
  2211.  
  2212. Convert a u_long from network to host byte order. 
  2213.  
  2214. #include <winsock.h>
  2215.  
  2216. u_long PASCAL FAR ntohl ( u_long netlong); 
  2217.  
  2218.  netlong 
  2219.    A 32-bit number in network byte order. 
  2220.  
  2221.  Remarks 
  2222.  
  2223.  This routine takes a 32-bit number in network byte order and returns a 32-bit 
  2224.  number in host byte order. 
  2225.  
  2226.  Return Value 
  2227.  
  2228.  ntohl() returns the value in host byte order. 
  2229.  
  2230.  See Also 
  2231.  
  2232.  htonl(), htons(), ntohs() 
  2233.  
  2234.  
  2235. ΓòÉΓòÉΓòÉ 7.1.15. ntohs() ΓòÉΓòÉΓòÉ
  2236.  
  2237. Description 
  2238.  
  2239. Convert a u_short from network to host byte order. 
  2240.  
  2241. #include <winsock.h>
  2242.  
  2243. u_short PASCAL FAR ntohs ( u_short netshort ); 
  2244.  
  2245.  netshort 
  2246.    A 16-bit number in network byte order. 
  2247.  
  2248.  Remarks 
  2249.  
  2250.  This routine takes a 16-bit number in network byte order and returns a 16-bit 
  2251.  number in host byte order. 
  2252.  
  2253.  Return Value 
  2254.  
  2255.  ntohs() returns the value in host byte order. 
  2256.  
  2257.  See Also 
  2258.  
  2259.  htonl(), htons(), ntohl() 
  2260.  
  2261.  
  2262. ΓòÉΓòÉΓòÉ 7.1.16. recv() ΓòÉΓòÉΓòÉ
  2263.  
  2264. Description 
  2265.  
  2266. Receive data from a socket. 
  2267.  
  2268. #include <winsock.h>
  2269.  
  2270. int PASCAL FAR recv ( int s, char FAR * buf, int len, int flags); 
  2271.  
  2272.  s 
  2273.    A descriptor identifying a connected socket. 
  2274.  
  2275.  buf 
  2276.    A buffer for the incoming data. 
  2277.  
  2278.  len 
  2279.    The length of buf. 
  2280.  
  2281.  flags 
  2282.    Specifies the way in which the call is made. 
  2283.  
  2284.  Remarks 
  2285.  
  2286.  This function is used on connected datagram or stream sockets specified by the 
  2287.  s parameter and is used to read incoming data. 
  2288.  
  2289.  For sockets of type SOCK_STREAM, as much information as is currently available 
  2290.  up to the size of the buffer supplied is returned.  If the socket has been 
  2291.  configured for in-line reception of out-of-band data (socket option 
  2292.  SO_OOBINLINE) and out-of-band data is unread, only out-of-band data will be 
  2293.  returned.  The application may use the ioctlsocket() SIOCATMARK to determine 
  2294.  whether any more out-of-band data remains to be read. 
  2295.  
  2296.  For datagram sockets, data is extracted from the first enqueued datagram, up 
  2297.  to the size of the size of the buffer supplied.  If the datagram is larger 
  2298.  than the buffer supplied, the excess data is lost, and recv() returns the 
  2299.  error WSAEMSGSIZE.  If no incoming data is available at the socket, the recv() 
  2300.  call waits for data to arrive unless the socket is non-blocking.  In this case 
  2301.  a value of SOCKET_ERROR is returned with the error code set to WSAEWOULDBLOCK. 
  2302.  The select() or WSAAsyncSelect() calls may be used to determine when more data 
  2303.  arrives.  If the socket is of type SOCK_STREAM and the remote side has shut 
  2304.  down the connection gracefully, a recv() will complete immediately with 0 
  2305.  bytes received.  If the connection has been abortively disconnected, a recv() 
  2306.  will fail with the error WSAECONNRESET. 
  2307.  
  2308.  Flags may be used to influence the behavior of the function invocation beyond 
  2309.  the options specified for the associated socket.  That is, the semantics of 
  2310.  this function are determined by the socket options and the flags parameter. 
  2311.  The latter is constructed by or-ing any of the following values: 
  2312.  
  2313.  MSG_PEEK 
  2314.            Peek at the incoming data.  The data is copied into the buffer but 
  2315.            is not removed from the input queue. 
  2316.  
  2317.  MSG_OOB 
  2318.            Process out-of-band data (See Out of Band Data for a discussion of 
  2319.            this topic.) 
  2320.  
  2321.  Return Value 
  2322.  
  2323.  If no error occurs, recv() returns the number of bytes received.  If the 
  2324.  connection has been closed, it returns 0.  Otherwise, a value of SOCKET_ERROR 
  2325.  is returned, and a specific error code may be retrieved by calling 
  2326.  WSAGetLastError(). 
  2327.  
  2328.  Error Codes 
  2329.  
  2330.  WSANOTINITIALISED 
  2331.            A successful WSAStartup() must occur before using this API. 
  2332.  
  2333.  WSAENETDOWN 
  2334.            The Windows Sockets implementation has detected that the network 
  2335.            subsystem has failed. 
  2336.  
  2337.  WSAENOTCONN 
  2338.            The socket is not connected. 
  2339.  
  2340.  WSAEINTR 
  2341.            The (blocking) call was canceled via WSACancelBlockingCall() 
  2342.  
  2343.  WSAEINPROGRESS 
  2344.            A blocking Windows Sockets operation is in progress. 
  2345.  
  2346.  WSAENOTSOCK 
  2347.            The descriptor is not a socket. 
  2348.  
  2349.  WSAEOPNOTSUPP 
  2350.            MSG_OOB was specified, but the socket is not of type SOCK_STREAM. 
  2351.  
  2352.  WSAESHUTDOWN 
  2353.            The socket has been shutdown; it is not possible to recv() on a 
  2354.            socket after shutdown() has been invoked with how set to 0 or 2. 
  2355.  
  2356.  WSAEWOULDBLOCK 
  2357.            The socket is marked as non-blocking and the receive operation would 
  2358.            block. 
  2359.  
  2360.  WSAEMSGSIZE 
  2361.            The datagram was too large to fit into the specified buffer and was 
  2362.            truncated. 
  2363.  
  2364.  WSAEINVAL 
  2365.            The socket has not been bound with bind(). 
  2366.  
  2367.  WSAECONNABORTED 
  2368.            The virtual circuit was aborted due to timeout or other failure. 
  2369.  
  2370.  WSAECONNRESET 
  2371.            The virtual circuit was reset by the remote side. 
  2372.  
  2373.  See Also 
  2374.  
  2375.  recvfrom(), send(), select(), WSAAsyncSelect(), socket() 
  2376.  
  2377.  
  2378. ΓòÉΓòÉΓòÉ 7.1.17. recvfrom() ΓòÉΓòÉΓòÉ
  2379.  
  2380. Description 
  2381.  
  2382. Receive a datagram and store the source address. 
  2383.  
  2384. #include <winsock.h>
  2385.  
  2386. int PASCAL FAR recvfrom ( int s, char FAR * buf, int len, int flags, struct 
  2387. sockaddr FAR * from, int FAR * fromlen ); 
  2388.  
  2389.  s 
  2390.    A descriptor identifying a bound socket. 
  2391.  
  2392.  buf 
  2393.    A buffer for the incoming data. 
  2394.  
  2395.  len 
  2396.    The length of buf. 
  2397.  
  2398.  flags 
  2399.    Specifies the way in which the call is made. 
  2400.  
  2401.  from 
  2402.    An optional pointer to a buffer which will hold the source address upon 
  2403.    return. 
  2404.  
  2405.  fromlen 
  2406.    An optional pointer to the size of the from buffer. 
  2407.  
  2408.  Remarks 
  2409.  
  2410.  This function is used to read incoming data on a (possibly connected) socket 
  2411.  and capture the address from which the data was sent. 
  2412.  
  2413.  For sockets of type SOCK_STREAM, as much information as is currently available 
  2414.  up to the size of the buffer supplied is returned.  If the socket has been 
  2415.  configured for in-line reception of out-of-band data (socket option 
  2416.  SO_OOBINLINE) and out-of-band data is unread, only out-of-band data will be 
  2417.  returned.  The application may use the ioctlsocket() SIOCATMARK to determine 
  2418.  whether any more out-of-band data remains to be read. The from and fromlen 
  2419.  parameters are ignored for SOCK_STREAM sockets. 
  2420.  
  2421.  For datagram sockets, data is extracted from the first enqueued datagram, up 
  2422.  to the size of the size of the buffer supplied.  If the datagram is larger 
  2423.  than the buffer supplied, the buffer is filled with the first part of the 
  2424.  message, the excess data is lost, and recvfrom() returns the error code 
  2425.  WSAEMSGSIZE. If from is non-zero, and the socket is of type SOCK_DGRAM, the 
  2426.  network address of the peer which sent the data is copied to the corresponding 
  2427.  struct sockaddr.  The value pointed to by fromlen is initialized to the size 
  2428.  of this structure, and is modified on return to indicate the actual size of 
  2429.  the address stored there. 
  2430.  
  2431.  If no incoming data is available at the socket, the recvfrom() call waits for 
  2432.  data to arrive unless the socket is non-blocking.  In this case a value of 
  2433.  SOCKET_ERROR is returned with the error code set to WSAEWOULDBLOCK. The 
  2434.  select() or WSAAsyncSelect() calls may be used to determine when more data 
  2435.  arrives. If the socket is of type SOCK_STREAM and the remote side has shut 
  2436.  down the connection gracefully, a recvfrom() will complete immediately with 0 
  2437.  bytes received.  If the connection has been abortively disconnected, a 
  2438.  recvfrom() will fail with the error WSAECONNRESET. 
  2439.  
  2440.  Flags may be used to influence the behavior of the function invocation beyond 
  2441.  the options specified for the associated socket.  That is, the semantics of 
  2442.  this function are determined by the socket options and the flags parameter. 
  2443.  The latter is constructed by or-ing any of the following values: 
  2444.  
  2445.  MSG_PEEK 
  2446.            Peek at the incoming data.  The data is copied into the buffer but 
  2447.            is not removed from the input queue. 
  2448.  
  2449.  MSG_OOB 
  2450.            Process out-of-band data (See Out of Band Data for a discussion of 
  2451.            this topic.) 
  2452.  
  2453.  Return Value 
  2454.  
  2455.  If no error occurs, recvfrom() returns the number of bytes received.  If the 
  2456.  connection has been closed, it returns 0.  Otherwise, a value of SOCKET_ERROR 
  2457.  is returned, and a specific error code may be retrieved by calling 
  2458.  WSAGetLastError(). 
  2459.  
  2460.  Error Codes 
  2461.  
  2462.  WSANOTINITIALISED 
  2463.            A successful WSAStartup() must occur before using this API. 
  2464.  
  2465.  WSAENETDOWN 
  2466.            The Windows Sockets implementation has detected that the network 
  2467.            subsystem has failed. 
  2468.  
  2469.  WSAEFAULT 
  2470.            The fromlen argument was invalid: the from buffer was too small to 
  2471.            accommodate the peer address. 
  2472.  
  2473.  WSAEINTR 
  2474.            The (blocking) call was canceled via WSACancelBlockingCall() 
  2475.  
  2476.  WSAEINPROGRESS 
  2477.            A blocking Windows Sockets operation is in progress. 
  2478.  
  2479.  WSAEINVAL 
  2480.            The socket has not been bound with bind(). 
  2481.  
  2482.  WSAENOTCONN 
  2483.            The socket is not connected (SOCK_STREAM only). 
  2484.  
  2485.  WSAENOTSOCK 
  2486.            The descriptor is not a socket. 
  2487.  
  2488.  WSAEOPNOTSUPP 
  2489.            MSG_OOB was specified, but the socket is not of type SOCK_STREAM. 
  2490.  
  2491.  WSAESHUTDOWN 
  2492.            The socket has been shutdown; it is not possible to recvfrom() on a 
  2493.            socket after shutdown() has been invoked with how set to 0 or 2. 
  2494.  
  2495.  WSAEWOULDBLOCK 
  2496.            The socket is marked as non-blocking and the recvfrom() operation 
  2497.            would block. 
  2498.  
  2499.  WSAEMSGSIZE 
  2500.            The datagram was too large to fit into the specified buffer and was 
  2501.            truncated. 
  2502.  
  2503.  WSAECONNABORTED 
  2504.            The virtual circuit was aborted due to timeout or other failure. 
  2505.  
  2506.  WSCONNRESET 
  2507.            The virtual circuit was reset by the remote side.
  2508.  
  2509.  See Also 
  2510.  
  2511.  recv(), send(), socket(), WSAAsyncSelect() 
  2512.  
  2513.  
  2514. ΓòÉΓòÉΓòÉ 7.1.18. select() ΓòÉΓòÉΓòÉ
  2515.  
  2516. Description 
  2517.  
  2518. Determine the status of one or more sockets, waiting if necessary. 
  2519.  
  2520. #include <winsock.h>
  2521.  
  2522. long PASCAL FAR select ( int nfds, fd_set FAR * readfds, fd_set FAR * writefds, 
  2523. fd_set FAR * exceptfds, const struct timeval FAR * timeout ); 
  2524.  
  2525.  nfds 
  2526.    This argument is ignored and included only for the sake of compatibility. 
  2527.  
  2528.  readfds 
  2529.    An optional pointer to a set of sockets to be checked for readability. 
  2530.  
  2531.  writefds 
  2532.    An optional pointer to a set of sockets to be checked for writeability 
  2533.  
  2534.  exceptfds 
  2535.    An optional pointer to a set of sockets to be checked for errors. 
  2536.  
  2537.  timeout 
  2538.    The maximum time for select() to wait, or NULL for blocking operation. 
  2539.  
  2540.  Remarks 
  2541.  
  2542.  This function is used to determine the status of one or more sockets.  For 
  2543.  each socket, the caller may request information on read, write or error 
  2544.  status.  The set of sockets for which a given status is requested is indicated 
  2545.  by an fd_set structure.  Upon return, the structure is updated to reflect the 
  2546.  subset of these sockets which meet the specified condition, and select() 
  2547.  returns the number of sockets meeting the conditions.  A set of macros is 
  2548.  provided for manipulating an fd_set.  These macros are compatible with those 
  2549.  used in the Berkeley software, but the underlying representation is completely 
  2550.  different. 
  2551.  
  2552.  The parameter readfds identifies those sockets which are to be checked for 
  2553.  readability.  If the socket is currently listen()ing, it will be marked as 
  2554.  readable if an incoming connection request has been received, so that an 
  2555.  accept() is guaranteed to complete without blocking.  For other sockets, 
  2556.  readability means that queued data is available for reading or,  for sockets 
  2557.  of type SOCK_STREAM, that the virtual socket corresponding to the socket has 
  2558.  been closed, so that a recv() or recvfrom() is guaranteed to complete without 
  2559.  blocking.  If the virtual circuit was closed gracefully, then a recv() will 
  2560.  return immediately with 0 bytes read; if the virtual circuit was closed 
  2561.  abortively, then a recv() will complete immediately with the error code 
  2562.  WSAECONNRESET.  The presence of out-of-band data will be checked if the socket 
  2563.  option SO_OOBINLINE has been enabled (see setsockopt()). 
  2564.  
  2565.  The parameter writefds identifies those sockets which are to be checked for 
  2566.  writeability.  If a socket is connect()ing (non-blocking), writeability means 
  2567.  that the connection establishment is complete.  For other sockets, 
  2568.  writeability means that a send() or sendto() will complete without blocking. 
  2569.  ╤ìIt is not specified how long this guarantee can be assumed to be valid, 
  2570.  particularly in a multithreaded environment.ΓêÖ 
  2571.  
  2572.  The parameter exceptfds identifies those sockets which are to be checked for 
  2573.  the presence of out-of-band data or any exceptional error conditions.  Note 
  2574.  that out-of-band data will only be reported in this way if the option 
  2575.  SO_OOBINLINE is FALSE.  For a SOCK_STREAM, the breaking of the connection by 
  2576.  the peer or due to KEEPALIVE failure will be indicated as an exception.  This 
  2577.  specification does not define which other errors will be included.  If a 
  2578.  socket is connect()ing (non-blocking), failure of the connect attempt is 
  2579.  indicated in exceptfds. 
  2580.  
  2581.  Any of readfds, writefds, or exceptfds may be given as NULL if no descriptors 
  2582.  are of interest.  Four macros are defined in the header file winsock.h for 
  2583.  manipulating the descriptor sets.  The variable FD_SETSIZE determines the 
  2584.  maximum number of descriptors in a set.  (The default value of FD_SETSIZE is 
  2585.  64, which may be modified by #defining FD_SETSIZE to another value before 
  2586.  #including winsock.h.)  Internally, an fd_set is represented as an array of 
  2587.  SOCKETs; the last valid entry is followed by an element set to INVALID_SOCKET. 
  2588.  The macros are: 
  2589.  
  2590.  FD_CLR(s, *set) 
  2591.            Removes the descriptor s from set. 
  2592.  
  2593.  FD_ISSET(s, *set) 
  2594.            Nonzero if s is a member of the set, zero otherwise. 
  2595.  
  2596.  FD_SET(s, *set) 
  2597.            Adds descriptor s to set. 
  2598.  
  2599.  FD_ZERO(*set) 
  2600.            Initializes the set to the NULL set. 
  2601.  
  2602.  The parameter timeout controls how long the select() may take to complete.  If 
  2603.  timeout is a null pointer, select() will block indefinitely until at least one 
  2604.  descriptor meets the specified criteria. Otherwise, timeout points to a struct 
  2605.  timeval which specifies the maximum time that select() should wait before 
  2606.  returning.  If the timeval is initialized to {0, 0}, select() will return 
  2607.  immediately; this is used to "poll" the state of the selected sockets.  If 
  2608.  this is the case, then the select() call is considered nonblocking and the 
  2609.  standard assumptions for nonblocking calls apply.  For example, the blocking 
  2610.  hook must not be called, and the Windows Sockets implementation must not 
  2611.  yield. 
  2612.  
  2613.  Return Value 
  2614.  
  2615.  select() returns the total number of descriptors which are ready and contained 
  2616.  in the fd_set structures, or 0 if the time limit expired, or SOCKET_ERROR if 
  2617.  an error occurred.  If the return value is SOCKET_ERROR, WSAGetLastError() may 
  2618.  be used to retrieve a specific error code. 
  2619.  
  2620.  Error Codes 
  2621.  
  2622.  WSANOTINITIALISED 
  2623.            A successful WSAStartup() must occur before using this API. 
  2624.  
  2625.  WSAENETDOWN 
  2626.            The Windows Sockets implementation has detected that the network 
  2627.            subsystem has failed. 
  2628.  
  2629.  WSAEINVAL 
  2630.            The timeout value is not valid. 
  2631.  
  2632.  WSAEINTR 
  2633.            The (blocking) call was canceled via WSACancelBlockingCall() 
  2634.  
  2635.  WSAEINPROGRESS 
  2636.            A blocking Windows Sockets operation is in progress. 
  2637.  
  2638.  WSAENOTSOCK 
  2639.            One of the descriptor sets contains an entry which is not a socket.
  2640.  
  2641.  See Also 
  2642.  
  2643.  WSAAsyncSelect(), accept(), connect(), recv(), recvfrom(), send() 
  2644.  
  2645.  
  2646. ΓòÉΓòÉΓòÉ 7.1.19. send() ΓòÉΓòÉΓòÉ
  2647.  
  2648. Description 
  2649.  
  2650. Send data on a connected socket. 
  2651.  
  2652. #include <winsock.h>
  2653.  
  2654. int PASCAL FAR send ( SOCKET s, const char FAR * buf, int len, int flags ); 
  2655.  
  2656.  s 
  2657.    A descriptor identifying a connected socket. 
  2658.  
  2659.  buf 
  2660.    A buffer containing the data to be transmitted. 
  2661.  
  2662.  len 
  2663.    The length of the data in buf. 
  2664.  
  2665.  flags 
  2666.    Specifies the way in which the call is made. 
  2667.  
  2668.  Remarks 
  2669.  
  2670.  send() is used on connected datagram or stream sockets and is used to write 
  2671.  outgoing data on a socket.  For datagram sockets, care must be taken not to 
  2672.  exceed the maximum IP packet size of the underlying subnets, which is given by 
  2673.  the iMaxUdpDg element in the WSAData structure returned by WSAStartup(). If 
  2674.  the data is too long to pass atomically through the underlying protocol the 
  2675.  error WSAEMSGSIZE is returned, and no data is transmitted. Note that the 
  2676.  successful completion of a send() does not indicate that the data was 
  2677.  successfully delivered. 
  2678.  
  2679.  If no buffer space is available within the transport system to hold the data 
  2680.  to be transmitted, send() will block unless the socket has been placed in a 
  2681.  non-blocking I/O mode.  On non-blocking SOCK_STREAM sockets, the number of 
  2682.  bytes written may be between 1 and the requested length, depending on buffer 
  2683.  availability on both the local and foreign hosts.  The select() call may be 
  2684.  used to determine when it is possible to send more data. 
  2685.  
  2686.  Flags may be used to influence the behavior of the function invocation beyond 
  2687.  the options specified for the associated socket.  That is, the semantics of 
  2688.  this function are determined by the socket options and the flags parameter. 
  2689.  The latter is constructed by or-ing any of the following values: 
  2690.  
  2691.  MSG_DONTROUTE 
  2692.            Specifies that the data should not be subject to routing.  A Windows 
  2693.            Sockets supplier may choose to ignore this flag; see also the 
  2694.            discussion of the SO_DONTROUTE option in Socket Options. 
  2695.  
  2696.  MSG_OOB 
  2697.            Send out-of-band data (SOCK_STREAM only; see also Out of Band Data) 
  2698.  
  2699.  Return Value 
  2700.  
  2701.  If no error occurs, send() returns the total number of characters sent.  (Note 
  2702.  that this may be less than the number indicated by len.) Otherwise, a value of 
  2703.  SOCKET_ERROR is returned, and a specific error code may be retrieved by 
  2704.  calling WSAGetLastError(). 
  2705.  
  2706.  Error Codes 
  2707.  
  2708.  WSANOTINITIALISED 
  2709.            A successful WSAStartup() must occur before using this API. 
  2710.  
  2711.  WSAENETDOWN 
  2712.            The Windows Sockets implementation has detected that the network 
  2713.            subsystem has failed. 
  2714.  
  2715.  WSAEACCES 
  2716.            The requested address is a broadcast address, but the appropriate 
  2717.            flag was not set. 
  2718.  
  2719.  WSAEINTR 
  2720.            The (blocking) call was canceled via WSACancelBlockingCall() 
  2721.  
  2722.  WSAEINPROGRESS 
  2723.            A blocking Windows Sockets operation is in progress. 
  2724.  
  2725.  WSAEFAULT 
  2726.            The buf is not in a valid part of the user address space. 
  2727.  
  2728.  WSAENETRESET 
  2729.            The connection must be reset because the Windows Sockets 
  2730.            implementation dropped it. 
  2731.  
  2732.  WSAENOBUFS 
  2733.            The Windows Sockets implementation reports a buffer deadlock. 
  2734.  
  2735.  WSAENOTCONN 
  2736.            The socket is not connected. 
  2737.  
  2738.  WSAENOTSOCK 
  2739.            The descriptor is not a socket. 
  2740.  
  2741.  WSAEOPNOTSUPP 
  2742.            MSG_OOB was specified, but the socket is not of type SOCK_STREAM. 
  2743.  
  2744.  WSAESHUTDOWN 
  2745.            The socket has been shutdown; it is not possible to send() on a 
  2746.            socket after shutdown() has been invoked with how set to 1 or 2. 
  2747.  
  2748.  WSAEWOULDBLOCK 
  2749.            The socket is marked as non-blocking and the requested operation 
  2750.            would block. 
  2751.  
  2752.  WSAEMSGSIZE 
  2753.            The socket is of type SOCK_DGRAM, and the datagram is larger than 
  2754.            the maximum supported by the Windows Sockets implementation. 
  2755.  
  2756.  WSAEINVAL 
  2757.            The socket has not been bound with bind() 
  2758.  
  2759.  WSAECONNABORTED 
  2760.            The virtual circuit was aborted due to timeout or other failure. 
  2761.  
  2762.  WSAECONNRESET 
  2763.            The virtual circuit was reset by the remote side. 
  2764.  
  2765.  See Also 
  2766.  
  2767.  recv(), recvfrom(), socket(), sendto(), WSAStartup() 
  2768.  
  2769.  
  2770. ΓòÉΓòÉΓòÉ 7.1.20. sendto() ΓòÉΓòÉΓòÉ
  2771.  
  2772. Description 
  2773.  
  2774. Send data to a specific destination. 
  2775.  
  2776. #include <winsock.h>
  2777.  
  2778. int PASCAL FAR sendto ( SOCKET s, const char FAR * buf, int len, int flags, 
  2779. const struct sockaddr FAR * to, int tolen); 
  2780.  
  2781.  s 
  2782.    A descriptor identifying a socket. 
  2783.  
  2784.  buf 
  2785.    A buffer containing the data to be transmitted. 
  2786.  
  2787.  len 
  2788.    The length of the data in buf. 
  2789.  
  2790.  flags 
  2791.    Specifies the way in which the call is made. 
  2792.  
  2793.  to 
  2794.    A optional pointer to the address of the target socket. 
  2795.  
  2796.  tolen 
  2797.    The size of the address in to. 
  2798.  
  2799.  Remarks 
  2800.  
  2801.  sendto() is used on datagram or stream sockets and is used to write outgoing 
  2802.  data on a socket.  For datagram sockets, care must be taken not to exceed the 
  2803.  maximum IP packet size of the underlying subnets, which is given by the 
  2804.  iMaxUdpDg element in the WSAData structure returned by WSAStartup(). If the 
  2805.  data is too long to pass atomically through the underlying protocol the error 
  2806.  WSAEMSGSIZE is returned, and no data is transmitted.  Note that the successful 
  2807.  completion of a sendto() does not indicate that the data was successfully 
  2808.  delivered. 
  2809.  
  2810.  sendto() is normally used on a SOCK_DGRAM socket to send a datagram to a 
  2811.  specific peer socket identified by the to parameter.  On a SOCK_STREAM socket, 
  2812.  the to and tolen parameters are ignored; in this case the sendto() is 
  2813.  equivalent to send(). 
  2814.  
  2815.  To send a broadcast (on a SOCK_DGRAM only), the address in the to parameter 
  2816.  should be constructed using the special IP address INADDR_BROADCAST (defined 
  2817.  in winsock.h) together with the intended port number.  It is generally 
  2818.  inadvisable for a broadcast datagram to exceed the size at which fragmentation 
  2819.  may occur, which implies that the data portion of the datagram (excluding 
  2820.  headers) should not exceed 512 bytes. 
  2821.  
  2822.  If no buffer space is available within the transport system to hold the data 
  2823.  to be transmitted, sendto() will block unless the socket has been placed in a 
  2824.  non-blocking I/O mode.  On non-blocking SOCK_STREAM sockets, the number of 
  2825.  bytes written may be between 1 and the requested length, depending on buffer 
  2826.  availability on both the local and foreign hosts.  The select() call may be 
  2827.  used to determine when it is possible to send more data. 
  2828.  
  2829.  Flags may be used to influence the behavior of the function invocation beyond 
  2830.  the options specified for the associated socket.  That is, the semantics of 
  2831.  this function are determined by the socket options and the flags parameter. 
  2832.  The latter is constructed by or-ing any of the following values: 
  2833.  
  2834.  MSG_DONTROUTE 
  2835.            Specifies that the data should not be subject to routing.  A Windows 
  2836.            Sockets supplier may choose to ignore this flag; see also the 
  2837.            discussion of the SO_DONTROUTE option in Socket Options. 
  2838.  
  2839.  MSG_OOB 
  2840.            Send out-of-band data (SOCK_STREAM only; see also Out of Band Data) 
  2841.  
  2842.  Return Value 
  2843.  
  2844.  If no error occurs, sendto() returns the total number of characters sent. 
  2845.  (Note that this may be less than the number indicated by len.) Otherwise, a 
  2846.  value of SOCKET_ERROR is returned, and a specific error code may be retrieved 
  2847.  by calling WSAGetLastError(). 
  2848.  
  2849.  Error Codes 
  2850.  
  2851.  WSANOTINITIALISED 
  2852.            A successful WSAStartup() must occur before using this API. 
  2853.  
  2854.  WSAENETDOWN 
  2855.            The Windows Sockets implementation has detected that the network 
  2856.            subsystem has failed. 
  2857.  
  2858.  WSAEACCES 
  2859.            The requested address is a broadcast address, but the appropriate 
  2860.            flag was not set. 
  2861.  
  2862.  WSAEINTR 
  2863.            The (blocking) call was canceled via WSACancelBlockingCall() 
  2864.  
  2865.  WSAEINPROGRESS 
  2866.            A blocking Windows Sockets operation is in progress. 
  2867.  
  2868.  WSAEFAULT 
  2869.            The buf or to are not in a valid part of the user address space, or 
  2870.            the to argument is too small (less than the sizeof a struct 
  2871.            sockaddr). 
  2872.  
  2873.  WSAENETRESET 
  2874.            The connection must be reset because the Windows Sockets 
  2875.            implementation dropped it. 
  2876.  
  2877.  WSAENOBUFS 
  2878.            The Windows Sockets implementation reports a buffer deadlock. 
  2879.  
  2880.  WSAENOTCONN 
  2881.            The socket is not connected (SOCK_STREAM only). 
  2882.  
  2883.  WSAENOTSOCK 
  2884.            The descriptor is not a socket. 
  2885.  
  2886.  WSAEOPNOTSUPP 
  2887.            MSG_OOB was specified, but the socket is not of type SOCK_STREAM. 
  2888.  
  2889.  WSAESHUTDOWN 
  2890.            The socket has been shutdown; it is not possible to sendto() on a 
  2891.            socket after shutdown() has been invoked with how set to 1 or 2. 
  2892.  
  2893.  WSAEWOULDBLOCK 
  2894.            The socket is marked as non-blocking and the requested operation 
  2895.            would block. 
  2896.  
  2897.  WSAEMSGSIZE 
  2898.            The socket is of type SOCK_DGRAM, and the datagram is larger than 
  2899.            the maximum supported by the Windows Sockets implementation. 
  2900.  
  2901.  WSAECONNABORTED 
  2902.            The virtual circuit was aborted due to timeout or other failure. 
  2903.  
  2904.  WSAECONNRESET 
  2905.            The virtual circuit was reset by the remote side. 
  2906.  
  2907.  WSAEADDRNOTAVAIL 
  2908.            The specified address is not available from the local machine. 
  2909.  
  2910.  WSAEAFNOSUPPORT 
  2911.            Addresses in the specified family cannot be used with this socket. 
  2912.  
  2913.  WSAEDESTADDRREQ 
  2914.            A destination address is required. 
  2915.  
  2916.  WSAENETUNREACH 
  2917.            The network can't be reached from this host at this time. 
  2918.  
  2919.  See Also 
  2920.  
  2921.  recv(), recvfrom(), socket(), send(), WSAStartup() 
  2922.  
  2923.  
  2924. ΓòÉΓòÉΓòÉ 7.1.21. setsockopt() ΓòÉΓòÉΓòÉ
  2925.  
  2926. Description 
  2927.  
  2928. Set a socket option. 
  2929.  
  2930. #include <winsock.h>
  2931.  
  2932. int PASCAL FAR setsockopt ( SOCKET s, int level, int optname, const char FAR * 
  2933. optval, int optlen); 
  2934.  
  2935.  s 
  2936.    A descriptor identifying a socket. 
  2937.  
  2938.  level 
  2939.    The level at which the option is defined; the only supported levels are 
  2940.    SOL_SOCKET and IPPROTO_TCP. 
  2941.  
  2942.  optname 
  2943.    The socket option for which the value is to be set. 
  2944.  
  2945.  optval 
  2946.    A pointer to the buffer in which the value for the requested option is 
  2947.    supplied. 
  2948.  
  2949.  optlen 
  2950.    The size of the optval buffer. 
  2951.  
  2952.  Remarks 
  2953.  
  2954.  setsockopt() sets the current value for a socket option associated with a 
  2955.  socket of any type, in any state.  Although options may exist at multiple 
  2956.  protocol levels, this specification only defines options that exist at the 
  2957.  uppermost "socket" level.  Options affect socket operations, such as whether 
  2958.  expedited data is received in the normal data stream, whether broadcast 
  2959.  messages may be sent on the socket, etc. There are two types of socket 
  2960.  options: Boolean options that enable or disable a feature or behavior, and 
  2961.  options which require an integer value or structure. To enable a Boolean 
  2962.  option, optval points to a nonzero integer.  To disable the option optval 
  2963.  points to an integer equal to zero. optlen should be equal to sizeof(int) for 
  2964.  Boolean options.  For other options, optval points to the an integer or 
  2965.  structure that contains the desired value for the option, and optlen is the 
  2966.  length of the integer or structure. 
  2967.  
  2968.  SO_LINGER controls the action taken when unsent data is queued on a socket and 
  2969.  a closesocket() is performed.  See closesocket() for a description of the way 
  2970.  in which the SO_LINGER settings affect the semantics of closesocket(). The 
  2971.  application sets the desired behavior by creating a struct linger (pointed to 
  2972.  by the optval argument) with the following elements: 
  2973.  
  2974.   struct linger {
  2975.           int     l_onoff;
  2976.           int     l_linger;
  2977.   }
  2978.  
  2979.  To enable SO_LINGER, the application should set l_onoff to a non-zero value, 
  2980.  set l_linger to 0 or the desired timeout (in seconds), and call setsockopt(). 
  2981.  To enable SO_DONTLINGER (i.e. disable SO_LINGER) l_onoff should be set to zero 
  2982.  and setsockopt() should be called. 
  2983.  
  2984.  By default, a socket may not be bound (see bind()) to a local address which is 
  2985.  already in use.  On occasions, however, it may be desirable to "re-use" an 
  2986.  address in this way.  Since every connection is uniquely identified by the 
  2987.  combination of local and remote addresses, there is no problem with having two 
  2988.  sockets bound to the same local address as long as the remote addresses are 
  2989.  different.  To inform the Windows Sockets implementation that a bind() on a 
  2990.  socket should not be disallowed because the desired address is already in use 
  2991.  by another socket, the application should set the SO_REUSEADDR socket option 
  2992.  for the socket before issuing the bind(). Note that the option is interpreted 
  2993.  only at the time of the bind(): it is therefore unnecessary (but harmless) to 
  2994.  set the option on a socket which is not to be bound to an existing address, 
  2995.  and setting or resetting the option after the bind() has no effect on this or 
  2996.  any other socket.. 
  2997.  
  2998.  An application may request that the Windows Sockets implementation enable the 
  2999.  use of "keep-alive" packets on TCP connections by turning on the SO_KEEPALIVE 
  3000.  socket option.  A Windows Sockets implementation need not support the use of 
  3001.  keep-alives: if it does, the precise semantics are implementation-specific but 
  3002.  should conform to section 4.2.3.6 of RFC 1122: Requirements for Internet Hosts 
  3003.  -- Communication Layers.  If a connection is dropped as the result of 
  3004.  "keep-alives" the error code WSAENETRESET is returned to any calls in progress 
  3005.  on the socket, and any subsequent calls will fail with WSAENOTCONN. 
  3006.  
  3007.  The TCP_NODELAY option disables the Nagle algorithm.  The Nagle algorithm is 
  3008.  used to reduce the number of small packets sent by a host by buffering 
  3009.  unacknowledged send data until a full-size packet can be sent.  However, for 
  3010.  some applications this algorithm can impede performance, and TCP_NODELAY may 
  3011.  be used to turn it off.  Application writers should not set TCP_NODELAY unless 
  3012.  the impact of doing so is well-understood and desired, since setting 
  3013.  TCP_NODELAY can have a significant negative impact of network performance. 
  3014.  TCP_NODELAY is the only supported socket option which uses level IPPROTO_TCP; 
  3015.  all other options use level SOL_SOCKET. 
  3016.  
  3017.  Windows Sockets suppliers are encouraged (but not required) to supply output 
  3018.  debug information if the SO_DEBUG option is set by an application.  The 
  3019.  mechanism for generating the debug information and the form it takes are 
  3020.  beyond the scope of this specification. The following options are supported 
  3021.  for setsockopt().  The Type identifies the type of data addressed by optval. 
  3022.  
  3023.   Value             Type            Meaning
  3024.   --------------- --------------- -----------------------------------------------
  3025.   SO_BROADCAST    BOOL            Allow transmission of broadcast messages on the
  3026.                                   socket.
  3027.  
  3028.   SO_DEBUG        BOOL            Record debugging information.
  3029.  
  3030.   SO_DONTLINGER   BOOL            Don't block close waiting for unsent data to be
  3031.                                   sent.  Setting this option is equivalent to
  3032.                                   setting SO_LINGER with l_onoff set to
  3033.                                   zero.
  3034.  
  3035.   SO_DONTROUTE    BOOL            Don't route: send directly to interface.
  3036.  
  3037.   SO_KEEPALIVE    BOOL            Send keepalives
  3038.  
  3039.   SO_LINGER       struct linger   Linger on close if unsent data is present
  3040.                   FAR *
  3041.  
  3042.   SO_OOBINLINE    BOOL            Receive out-of-band data in the normal data
  3043.                                   stream.
  3044.  
  3045.   SO_RCVBUF       int             Specify buffer size for receives
  3046.  
  3047.   SO_REUSEADDR    BOOL            Allow the socket to be bound to an address
  3048.                                   which is already in use.  (See bind().)
  3049.  
  3050.   SO_SNDBUF       int             Specify buffer size for sends
  3051.  
  3052.   TCP_NODELAY     BOOL            Disables the Nagle algorithm for send
  3053.                                   coalascing.
  3054.  
  3055.  BSD options not supported for setsockopt() are: 
  3056.  
  3057.   Value             Type            Meaning
  3058.   --------------- --------------- -----------------------------------------------
  3059.   SO_ACCEPTCON    BOOL            Socket is listening
  3060.  
  3061.   SO_ERROR        int             Get error status and clear
  3062.  
  3063.   SO_RCVLOWAT     int             Receive low water mark
  3064.  
  3065.   SO_RCVTIMEO     int             Receive timeout
  3066.  
  3067.   SO_SNDLOWAT     int             Send low water mark
  3068.  
  3069.   SO_SNDTIMEO     int             Send timeout
  3070.  
  3071.   SO_TYPE         int             Type of the socket
  3072.  
  3073.   IP_OPTIONS                      Set options field in IP header.
  3074.  
  3075.  Return Value 
  3076.  
  3077.  If no error occurs, setsockopt() returns 0. Otherwise, a value of SOCKET_ERROR 
  3078.  is returned, and a specific error code may be retrieved by calling 
  3079.  WSAGetLastError(). 
  3080.  
  3081.  Error Codes 
  3082.  
  3083.  WSANOTINITIALISED 
  3084.            A successful WSAStartup() must occur before using this API. 
  3085.  
  3086.  WSAENETDOWN 
  3087.            The Windows Sockets implementation has detected that the network 
  3088.            subsystem has failed. 
  3089.  
  3090.  WSAEFAULT 
  3091.            optval is not in a valid part of the process address  space. 
  3092.  
  3093.  WSAEINPROGRESS 
  3094.            A blocking Windows Sockets operation is in progress. 
  3095.  
  3096.  WSAEINVAL 
  3097.            level is not valid, or the information in optval is not valid. 
  3098.  
  3099.  WSAENETRESET 
  3100.            Connection has timed out when SO_KEEPALIVE is set. 
  3101.  
  3102.  WSAENOPROTOOPT 
  3103.            The option is unknown or unsupported.  In particular, SO_BROADCAST 
  3104.            is not supported on sockets of type SOCK_STREAM, while 
  3105.            SO_DONTLINGER, SO_KEEPALIVE, SO_LINGER and SO_OOBINLINE are not 
  3106.            supported on sockets of type SOCK_DGRAM. 
  3107.  
  3108.  WSAENOTCONN 
  3109.            Connection has been reset when SO_KEEPALIVE is set. 
  3110.  
  3111.  WSAENOTSOCK 
  3112.            The descriptor is not a socket.
  3113.  
  3114.  See Also 
  3115.  
  3116.  bind(), getsockopt(), ioctlsocket(), socket(), WSAAsyncSelect() 
  3117.  
  3118.  
  3119. ΓòÉΓòÉΓòÉ 7.1.22. shutdown() ΓòÉΓòÉΓòÉ
  3120.  
  3121. Description 
  3122.  
  3123. Disable sends and/or receives on a socket. 
  3124.  
  3125. #include <winsock.h>
  3126.  
  3127. int PASCAL FAR shutdown ( SOCKET s, int how ); 
  3128.  
  3129.  s 
  3130.    A descriptor identifying a socket. 
  3131.  
  3132.  how 
  3133.    A flag that describes what types of operation will no longer be allowed. 
  3134.  
  3135.  Remarks 
  3136.  
  3137.  shutdown() is used on all types of sockets to disable reception, transmission, 
  3138.  or both. 
  3139.  
  3140.  If how is 0, subsequent receives on the socket will be disallowed.  This has 
  3141.  no effect on the lower protocol layers.  For TCP, the TCP window is not 
  3142.  changed and incoming data will be accepted (but not acknowledged) until the 
  3143.  window is exhausted.  For UDP, incoming datagrams are accepted and queued.  In 
  3144.  no case will an ICMP error packet be generated. 
  3145.  
  3146.  If how is 1, subsequent sends are disallowed.  For TCP sockets, a FIN will be 
  3147.  sent. 
  3148.  
  3149.  Setting how to 2 disables both sends and receives as described above.  Note 
  3150.  that shutdown() does not close the socket, and resources attached to the 
  3151.  socket will not be freed until closesocket() is invoked. 
  3152.  
  3153.  Comments 
  3154.  
  3155.  shutdown() does not block regardless of the SO_LINGER setting on the socket. 
  3156.  
  3157.  An application should not rely on being able to re-use a socket after it has 
  3158.  been shut down.  In particular, a Windows Sockets implementation is not 
  3159.  required to support the use of connect() on such a socket. 
  3160.  
  3161.  Return Value 
  3162.  
  3163.  If no error occurs, shutdown() returns 0. Otherwise, a value of SOCKET_ERROR 
  3164.  is returned, and a specific error code may be retrieved by calling 
  3165.  WSAGetLastError() 
  3166.  
  3167.  Error Codes 
  3168.  
  3169.  WSANOTINITIALISED 
  3170.            A successful WSAStartup() must occur before using this API. 
  3171.  
  3172.  WSAENETDOWN 
  3173.            The Windows Sockets implementation has detected that the network 
  3174.            subsystem has failed. 
  3175.  
  3176.  WSAEINVAL 
  3177.            how is not valid. 
  3178.  
  3179.  WSAEINTR 
  3180.            The (blocking) call was canceled via WSACancelBlockingCall() 
  3181.  
  3182.  WSAEINPROGRESS 
  3183.            A blocking Windows Sockets operation is in progress. 
  3184.  
  3185.  WSAENOTCONN 
  3186.            The socket is not connected (SOCK_STREAM only). 
  3187.  
  3188.  WSAENOTSOCK 
  3189.            The descriptor is not a socket.
  3190.  
  3191.  See Also 
  3192.  
  3193.  connect(), socket() 
  3194.  
  3195.  
  3196. ΓòÉΓòÉΓòÉ 7.1.23. socket() ΓòÉΓòÉΓòÉ
  3197.  
  3198. Description 
  3199.  
  3200. Create a socket. 
  3201.  
  3202. #include <winsock.h>
  3203.  
  3204. SOCKET PASCAL FAR socket ( int af, int type, int protocol); 
  3205.  
  3206.  af 
  3207.    An address format specification.  The only format currently supported is 
  3208.    PF_INET, which is the ARPA Internet address format. 
  3209.  
  3210.  type 
  3211.    A type specification for the new socket. 
  3212.  
  3213.  protocol 
  3214.    A particular protocol to be used with the socket, or 0 if the caller does 
  3215.    not wish to specify a protocol. 
  3216.  
  3217.  Remarks 
  3218.  
  3219.  socket() allocates a socket descriptor of the specified address family, data 
  3220.  type and protocol, as well as related resources.  If a protocol is not 
  3221.  specified (i.e. equal to 0), the default for the specified connection mode is 
  3222.  used. Only a single protocol exists to support a particular socket type using 
  3223.  a given address format.  However, the address family may be given as AF_UNSPEC 
  3224.  (unspecified), in which case the protocol parameter must be specified. The 
  3225.  protocol number to use is particular to the "communication domain" in which 
  3226.  communication is to take place. 
  3227.  
  3228.  The following type specifications are supported: 
  3229.  
  3230.  SOCK_STREAM 
  3231.            Provides sequenced, reliable, two-way, connection-based byte streams 
  3232.            with an out-of-band data transmission mechanism.  Uses TCP for the 
  3233.            Internet address family. 
  3234.  
  3235.  SOCK_DGRAM 
  3236.            Supports datagrams, which are connectionless, unreliable buffers of 
  3237.            a fixed (typically small) maximum length.  Uses UDP for the Internet 
  3238.            address family. 
  3239.  
  3240.  Sockets of type SOCK_STREAM are full-duplex byte streams.  A stream socket 
  3241.  must be in a connected state before any data may be sent or received on it.  A 
  3242.  connection to another socket is created with a connect() call.  Once 
  3243.  connected, data may be transferred using send() and recv() calls.  When a 
  3244.  session has been completed, a closesocket() must be performed.  Out-of-band 
  3245.  data may also be transmitted as described in send() and received as described 
  3246.  in recv(). 
  3247.  
  3248.  The communications protocols used to implement a SOCK_STREAM ensure that data 
  3249.  is not lost or duplicated.  If data for which the peer protocol has buffer 
  3250.  space cannot be successfully transmitted within a reasonable length of time, 
  3251.  the connection is considered broken and subsequent calls will fail with the 
  3252.  error code set to WSAETIMEDOUT. 
  3253.  
  3254.  SOCK_DGRAM sockets allow sending and receiving of datagrams to and from 
  3255.  arbitrary peers using sendto() and recvfrom(). If such a socket is connect()ed 
  3256.  to a specific peer, datagrams may be send to that peer send() and may be 
  3257.  received from (only) this peer using recv(). 
  3258.  
  3259.  Return Value 
  3260.  
  3261.  If no error occurs, socket() returns a descriptor referencing the new socket. 
  3262.  Otherwise, a value of INVALID_SOCKET is returned, and a specific error code 
  3263.  may be retrieved by calling WSAGetLastError() 
  3264.  
  3265.  Error Codes 
  3266.  
  3267.  WSANOTINITIALISED 
  3268.            A successful WSAStartup() must occur before using this API. 
  3269.  
  3270.  WSAENETDOWN 
  3271.            The Windows Sockets implementation has detected that the network 
  3272.            subsystem has failed. 
  3273.  
  3274.  WSAEAFNOSUPPORT 
  3275.            The specified address family is not supported.. 
  3276.  
  3277.  WSAEINPROGRESS 
  3278.            A blocking Windows Sockets operation is in progress. 
  3279.  
  3280.  WSAEMFILE 
  3281.            No more file descriptors are available. 
  3282.  
  3283.  WSAENOBUFS 
  3284.            No buffer space is available.  The socket cannot be created. 
  3285.  
  3286.  WSAEPROTONOSUPPORT 
  3287.            The specified protocol is not supported. 
  3288.  
  3289.  WSAEPROTOTYPE 
  3290.            The specified protocol is the wrong type for this socket. 
  3291.  
  3292.  WSAESOCKTNOSUPPORT 
  3293.            The specified socket type is not supported in this address family.
  3294.  
  3295.  See Also 
  3296.  
  3297.  accept(), bind(), connect(), getsockname(), getsockopt(), setsockopt(), 
  3298.  listen(), recv(), recvfrom(), select(), send(), sendto(), shutdown(), 
  3299.  ioctlsocket() 
  3300.  
  3301.  
  3302. ΓòÉΓòÉΓòÉ 7.2. Database Routines ΓòÉΓòÉΓòÉ
  3303.  
  3304. gethostbyaddr() 
  3305.  
  3306. gethostbyname() 
  3307.  
  3308. gethostname() 
  3309.  
  3310. getprotobyname() 
  3311.  
  3312. getprotobynumber() 
  3313.  
  3314. getservbyname() 
  3315.  
  3316. getservbyport() 
  3317.  
  3318.  
  3319. ΓòÉΓòÉΓòÉ 7.2.1. gethostbyaddr() ΓòÉΓòÉΓòÉ
  3320.  
  3321. Description 
  3322.  
  3323. Get host information corresponding to an address. 
  3324.  
  3325. #include <winsock.h>
  3326.  
  3327. struct hostent FAR * PASCAL FAR gethostbyaddr ( const char FAR * addr, int len, 
  3328. int type ); 
  3329.  
  3330.  addr 
  3331.    A pointer to an address in network byte order. 
  3332.  
  3333.  len 
  3334.    The length of the address, which must be 4 for PF_INET addresses. 
  3335.  
  3336.  type 
  3337.    The type of the address, which must be PF_INET. 
  3338.  
  3339.  Remarks 
  3340.  
  3341.  gethostbyaddr() returns a pointer to the following structure which contains 
  3342.  the name(s) and address which correspond to the given address. 
  3343.  
  3344.   struct hostent {
  3345.           char FAR *      h_name;
  3346.           char FAR * FAR *h_aliases;
  3347.           short           h_addrtype;
  3348.           short           h_length;
  3349.           char FAR * FAR *h_addr_list;
  3350.   };
  3351.  
  3352.  The members of this structure are: 
  3353.  
  3354.  h_name 
  3355.    Official name of the host (PC). 
  3356.  
  3357.  h_aliases 
  3358.    A NULL -terminated array of alternate names. 
  3359.  
  3360.  h_addrtype 
  3361.    The type of address being returned; for Windows Sockets this is always 
  3362.    PF_INET. 
  3363.  
  3364.  h_length 
  3365.    The length, in bytes, of each address; for PF_INET, this is always 4. 
  3366.  
  3367.  h_addr_list 
  3368.    A NULL-terminated list of addresses for the host.  Addresses are returned in 
  3369.    network byte order. 
  3370.  
  3371.  The macro h_addr is defined to be h_addr_list╤ì0ΓêÖ for compatibility with older 
  3372.  software. 
  3373.  
  3374.  The pointer which is returned points to a structure which is allocated by the 
  3375.  Windows Sockets implementation.  The application must never attempt to modify 
  3376.  this structure or to free any of its components.  Furthermore, only one copy 
  3377.  of this structure is allocated per thread, and so the application should copy 
  3378.  any information which it needs before issuing any other Windows Sockets API 
  3379.  calls. 
  3380.  
  3381.  Return Value 
  3382.  
  3383.  If no error occurs, gethostbyaddr() returns a pointer to the hostent structure 
  3384.  described above.  Otherwise it returns a NULL pointer and a specific error 
  3385.  number may be retrieved by calling WSAGetLastError() 
  3386.  
  3387.  Error Codes 
  3388.  
  3389.  WSANOTINITIALISED 
  3390.            A successful WSAStartup() must occur before using this API. 
  3391.  
  3392.  WSAENETDOWN 
  3393.            The Windows Sockets implementation has detected that the network 
  3394.            subsystem has failed. 
  3395.  
  3396.  WSAHOST_NOT_FOUND 
  3397.            Authoritative Answer Host not found. 
  3398.  
  3399.  WSATRY_AGAIN 
  3400.            Non-Authoritative Host not found, or SERVERFAIL. 
  3401.  
  3402.  WSANO_RECOVERY 
  3403.            Non recoverable errors, FORMERR, REFUSED, NOTIMP. 
  3404.  
  3405.  WSANO_DATA 
  3406.            Valid name, no data record of requested type. 
  3407.  
  3408.  WSAEINPROGRESS 
  3409.            A blocking Windows Sockets operation is in progress. 
  3410.  
  3411.  WSAEINTR 
  3412.            The (blocking) call was canceled via WSACancelBlockingCall() 
  3413.  
  3414.  See Also 
  3415.  
  3416.  WSAAsyncGetHostByAddr(), gethostbyname(), 
  3417.  
  3418.  
  3419. ΓòÉΓòÉΓòÉ 7.2.2. gethostbyname() ΓòÉΓòÉΓòÉ
  3420.  
  3421. Description 
  3422.  
  3423. Get host information corresponding to a hostname. 
  3424.  
  3425. #include <winsock.h>
  3426.  
  3427. struct hostent FAR * PASCAL FAR gethostbyname ( const char FAR * name); 
  3428.  
  3429.  name 
  3430.    A pointer to the name of the host. 
  3431.  
  3432.  Remarks 
  3433.  
  3434.  gethostbyname() returns a pointer to a hostent structure as described under 
  3435.  gethostbyaddr(). The contents of this structure correspond to the hostname 
  3436.  name.  The pointer which is returned points to a structure which is allocated 
  3437.  by the Windows Sockets implementation.  The application must never attempt to 
  3438.  modify this structure or to free any of its components.  Furthermore, only one 
  3439.  copy of this structure is allocated per thread, and so the application should 
  3440.  copy any information which it needs before issuing any other Windows Sockets 
  3441.  API calls. 
  3442.  
  3443.  A gethostbyname() implementation must not resolve IP address strings passed to 
  3444.  it.  Such a request should be treated exactly as if an unknown host name were 
  3445.  passed.  An application with an IP address string to resolve should use 
  3446.  inet_addr() to convert the string to an IP address, then gethostbyaddr() to 
  3447.  obtain the hostent structure. 
  3448.  
  3449.  Return Value 
  3450.  
  3451.  If no error occurs, gethostbyname() returns a pointer to the hostent structure 
  3452.  described above.  Otherwise it returns a NULL pointer and a specific error 
  3453.  number may be retrieved by calling WSAGetLastError(). 
  3454.  
  3455.  Error Codes 
  3456.  
  3457.  WSANOTINITIALISED 
  3458.            A successful WSAStartup() must occur before using this API. 
  3459.  
  3460.  WSAENETDOWN 
  3461.            The Windows Sockets implementation has detected that the network 
  3462.            subsystem has failed. 
  3463.  
  3464.  WSAHOST_NOT_FOUND 
  3465.            Authoritative Answer Host not found. 
  3466.  
  3467.  WSATRY_AGAIN 
  3468.            Non-Authoritative Host not found, or SERVERFAIL. 
  3469.  
  3470.  WSANO_RECOVERY 
  3471.            Non recoverable errors, FORMERR, REFUSED, NOTIMP. 
  3472.  
  3473.  WSANO_DATA 
  3474.            Valid name, no data record of requested type. 
  3475.  
  3476.  WSAEINPROGRESS 
  3477.            A blocking Windows Sockets operation is in progress. 
  3478.  
  3479.  WSAEINTR 
  3480.            The (blocking) call was canceled via WSACancelBlockingCall() 
  3481.  
  3482.  See Also 
  3483.  
  3484.  WSAAsyncGetHostByName(), gethostbyaddr() 
  3485.  
  3486.  
  3487. ΓòÉΓòÉΓòÉ 7.2.3. gethostname() ΓòÉΓòÉΓòÉ
  3488.  
  3489. Description 
  3490.  
  3491. Return the standard host name for the local machine. 
  3492.  
  3493. #include <winsock.h>
  3494.  
  3495. int PASCAL FAR gethostname ( char FAR * name, int namelen ); 
  3496.  
  3497.  name 
  3498.    A pointer to a buffer that will receive the host name. 
  3499.  
  3500.  namelen 
  3501.    The length of the buffer. 
  3502.  
  3503.  Remarks 
  3504.  
  3505.  This routine returns the name of the local host into the buffer specified by 
  3506.  the name parameter.  The host name is returned as a null-terminated string. 
  3507.  The form of the host name is dependent on the Windows Sockets 
  3508.  implementation--it may be a simple host name, or it may be a fully qualified 
  3509.  domain name.  However, it is guaranteed that the name returned will be 
  3510.  successfully parsed by gethostbyname() and WSAAsyncGetHostByName(). 
  3511.  
  3512.  Return Value 
  3513.  
  3514.  If no error occurs, gethostname() reutrns 0, otherwise it returns SOCKET_ERROR 
  3515.  and a specific error code may be retrieved by calling WSAGetLastError(). 
  3516.  
  3517.  Error Codes 
  3518.  
  3519.  WSAEFAULT 
  3520.            The namelen parameter is too small 
  3521.  
  3522.  WSANOTINITIALISED 
  3523.            A successful WSAStartup() must occur before using this API. 
  3524.  
  3525.  WSAENETDOWN 
  3526.            The Windows Sockets implementation has detected that the network 
  3527.            subsystem has failed. 
  3528.  
  3529.  WSAEINPROGRESS 
  3530.            A blocking Windows Sockets operation is in progress. 
  3531.  
  3532.  See Also 
  3533.  
  3534.  gethostbyname(), WSAAsyncGetHostByName() 
  3535.  
  3536.  
  3537. ΓòÉΓòÉΓòÉ 7.2.4. getprotobyname() ΓòÉΓòÉΓòÉ
  3538.  
  3539. Description 
  3540.  
  3541. Get protocol information corresponding to a protocol name. 
  3542.  
  3543. #include <winsock.h>
  3544.  
  3545. struct protoent FAR * PASCAL FAR getprotobyname ( const char FAR * name); 
  3546.  
  3547.  name 
  3548.    A pointer to a protocol name. 
  3549.  
  3550.  Remarks 
  3551.  
  3552.  getprotobyname() returns a pointer to the following structure which contains 
  3553.  the name(s) and protocol number which correspond to the given protocol name. 
  3554.  
  3555.   struct protoent {
  3556.           char FAR *      p_name;
  3557.           char FAR * FAR *p_aliases;
  3558.           short           p_proto;
  3559.   };
  3560.  
  3561.  The members of this structure are: 
  3562.  
  3563.  p_name 
  3564.    Official name of the protocol. 
  3565.  
  3566.  p_aliases 
  3567.    A NULL-terminated array of alternate names. 
  3568.  
  3569.  p_proto 
  3570.    The protocol number, in host byte order. 
  3571.  
  3572.  The pointer which is returned points to a structure which is allocated by the 
  3573.  Windows Sockets library.  The application must never attempt to modify this 
  3574.  structure or to free any of its components.  Furthermore only one copy of this 
  3575.  structure is allocated per thread, and so the application should copy any 
  3576.  information which it needs before issuing any other Windows Sockets API calls. 
  3577.  
  3578.  Return Value 
  3579.  
  3580.  If no error occurs, getprotobyname() returns a pointer to the protoent 
  3581.  structure described above.  Otherwise it returns a NULL pointer and a specific 
  3582.  error number may be retrieved by calling WSAGetLastError(). 
  3583.  
  3584.  Error Codes 
  3585.  
  3586.  WSANOTINITIALISED 
  3587.            A successful WSAStartup() must occur before using this API. 
  3588.  
  3589.  WSAENETDOWN 
  3590.            The Windows Sockets implementation has detected that the network 
  3591.            subsystem has failed. 
  3592.  
  3593.  WSANO_RECOVERY 
  3594.            Non recoverable errors, FORMERR, REFUSED, NOTIMP. 
  3595.  
  3596.  WSANO_DATA 
  3597.            Valid name, no data record of requested type. 
  3598.  
  3599.  WSAEINPROGRESS 
  3600.            A blocking Windows Sockets operation is in progress. 
  3601.  
  3602.  WSAEINTR 
  3603.            The (blocking) call was canceled via WSACancelBlockingCall() 
  3604.  
  3605.  See Also 
  3606.  
  3607.  WSAAsyncGetProtoByName(), getprotobynumber() 
  3608.  
  3609.  
  3610. ΓòÉΓòÉΓòÉ 7.2.5. getprotobynumber() ΓòÉΓòÉΓòÉ
  3611.  
  3612. Description 
  3613.  
  3614. Get protocol information corresponding to a protocol number. 
  3615.  
  3616. #include <winsock.h>
  3617.  
  3618. struct protoent FAR * PASCAL FAR getprotobynumber ( int number ); 
  3619.  
  3620.  number 
  3621.    A protocol number, in host byte order. 
  3622.  
  3623.  Remarks 
  3624.  
  3625.  This function returns a pointer to a protoent structure as described above in 
  3626.  getprotobyname().  The contents of the structure correspond to the given 
  3627.  protocol number.  The pointer which is returned points to a structure which is 
  3628.  allocated by the Windows Sockets implementation.  The application must never 
  3629.  attempt to modify this structure or to free any of its components. 
  3630.  Furthermore, only one copy of this structure is allocated per thread, and so 
  3631.  the application should copy any information which it needs before issuing any 
  3632.  other Windows Sockets API calls. 
  3633.  
  3634.  Return Value 
  3635.  
  3636.  If no error occurs, getprotobynumber() returns a pointer to the protoent 
  3637.  structure described above.  Otherwise it returns a NULL pointer and a specific 
  3638.  error number may be retrieved by calling WSAGetLastError(). 
  3639.  
  3640.  Error Codes 
  3641.  
  3642.  WSANOTINITIALISED 
  3643.            A successful WSAStartup() must occur before using this API. 
  3644.  
  3645.  WSAENETDOWN 
  3646.            The Windows Sockets implementation has detected that the network 
  3647.            subsystem has failed. 
  3648.  
  3649.  WSANO_RECOVERY 
  3650.            Non recoverable errors, FORMERR, REFUSED, NOTIMP. 
  3651.  
  3652.  WSANO_DATA 
  3653.            Valid name, no data record of requested type. 
  3654.  
  3655.  WSAEINPROGRESS 
  3656.            A blocking Windows Sockets operation is in progress. 
  3657.  
  3658.  WSAEINTR 
  3659.            The (blocking) call was canceled via WSACancelBlockingCall() 
  3660.  
  3661.  See Also 
  3662.  
  3663.  WSAAsyncGetProtoByNumber(), getprotobyname() 
  3664.  
  3665.  
  3666. ΓòÉΓòÉΓòÉ 7.2.6. getservbyname() ΓòÉΓòÉΓòÉ
  3667.  
  3668. Description 
  3669.  
  3670. Get service information corresponding to a service name and protocol. 
  3671.  
  3672. #include <winsock.h>
  3673.  
  3674. struct servent FAR * PASCAL FAR getservbyname ( const char FAR * name, const 
  3675. char FAR * proto); 
  3676.  
  3677.  name 
  3678.    A pointer to a service name. 
  3679.  
  3680.  proto 
  3681.    An optional pointer to a protocol name.  If this is NULL, getservbyname() 
  3682.    returns the first service entry for which the name matches the s_name or one 
  3683.    of the s_aliases.  Otherwise getservbyname() matches both the name and the 
  3684.    proto. 
  3685.  
  3686.  Remarks 
  3687.  
  3688.  getservbyname() returns a pointer to the following structure which contains 
  3689.  the name(s) and service number which correspond to the given service name. 
  3690.  
  3691.   struct servent {
  3692.           char FAR *      s_name;
  3693.           char FAR * FAR *s_aliases;
  3694.           short           s_port;
  3695.           char FAR *      s_proto;
  3696.   };
  3697.  
  3698.  The members of this structure are: 
  3699.  
  3700.  s_name 
  3701.    Official name of the service. 
  3702.  
  3703.  s_aliases 
  3704.    A NULL-terminated array of alternate names. 
  3705.  
  3706.  s_port 
  3707.    The port number at which the service may be contacted.  Port numbers are in 
  3708.    network byte order. 
  3709.  
  3710.  s_proto 
  3711.    The name of the protocol to use when contacting the service. 
  3712.  
  3713.  The pointer which is returned points to a structure which is allocated by the 
  3714.  Windows Sockets library.  The application must never attempt to modify this 
  3715.  structure or to free any of its components.  Furthermore only one copy of this 
  3716.  structure is allocated per thread, and so the application should copy any 
  3717.  information which it needs before issuing any other Windows Sockets API calls. 
  3718.  
  3719.  Return Value 
  3720.  
  3721.  If no error occurs, getservbyname() returns a pointer to the servent structure 
  3722.  described above.  Otherwise it returns a NULL pointer and a specific error 
  3723.  number may be retrieved by calling WSAGetLastError() 
  3724.  
  3725.  Error Codes 
  3726.  
  3727.  WSANOTINITIALISED 
  3728.            A successful WSAStartup() must occur before using this API. 
  3729.  
  3730.  WSAENETDOWN 
  3731.            The Windows Sockets implementation has detected that the network 
  3732.            subsystem has failed. 
  3733.  
  3734.  WSANO_RECOVERY 
  3735.            Non recoverable errors, FORMERR, REFUSED, NOTIMP. 
  3736.  
  3737.  WSANO_DATA 
  3738.            Valid name, no data record of requested type. 
  3739.  
  3740.  WSAEINPROGRESS 
  3741.            A blocking Windows Sockets operation is in progress. 
  3742.  
  3743.  WSAEINTR 
  3744.            The (blocking) call was canceled via WSACancelBlockingCall() 
  3745.  
  3746.  See Also 
  3747.  
  3748.  WSAAsyncGetServByName(), getservbyport() 
  3749.  
  3750.  
  3751. ΓòÉΓòÉΓòÉ 7.2.7. getservbyport() ΓòÉΓòÉΓòÉ
  3752.  
  3753. Description 
  3754.  
  3755. Get service information corresponding to a port and protocol. 
  3756.  
  3757. #include <winsock.h>
  3758.  
  3759. struct servent FAR * PASCAL FAR getservbyport ( int port, const char FAR * 
  3760. proto); 
  3761.  
  3762.  port 
  3763.    The port for a service, in network byte order. 
  3764.  
  3765.  proto 
  3766.    An optional pointer to a protocol name.  If this is NULL, getservbyport() 
  3767.    returns the first service entry for which the port matches the s_port. 
  3768.    Otherwise getservbyport() matches both the port and the proto. 
  3769.  
  3770.  Remarks 
  3771.  
  3772.  getservbyport() returns a pointer a servent structure as described above for 
  3773.  getservbyname().  The pointer which is returned points to a structure which is 
  3774.  allocated by the Windows Sockets implementation.  The application must never 
  3775.  attempt to modify this structure or to free any of its components. 
  3776.  Furthermore, only one copy of this structure is allocated per thread, and so 
  3777.  the application should copy any information which it needs before issuing any 
  3778.  other Windows Sockets API calls. 
  3779.  
  3780.  Return Value 
  3781.  
  3782.  If no error occurs, getservbyport() returns a pointer to the servent structure 
  3783.  described above.  Otherwise it returns a NULL pointer and a specific error 
  3784.  number may be retrieved by calling WSAGetLastError() 
  3785.  
  3786.  Error Codes 
  3787.  
  3788.  WSANOTINITIALISED 
  3789.            A successful WSAStartup() must occur before using this API. 
  3790.  
  3791.  WSAENETDOWN 
  3792.            The Windows Sockets implementation has detected that the network 
  3793.            subsystem has failed. 
  3794.  
  3795.  WSANO_RECOVERY 
  3796.            Non recoverable errors, FORMERR, REFUSED, NOTIMP. 
  3797.  
  3798.  WSANO_DATA 
  3799.            Valid name, no data record of requested type. 
  3800.  
  3801.  WSAEINPROGRESS 
  3802.            A blocking Windows Sockets operation is in progress. 
  3803.  
  3804.  WSAEINTR 
  3805.            The (blocking) call was canceled via WSACancelBlockingCall() 
  3806.  
  3807.  See Also 
  3808.  
  3809.  WSAAsyncGetServByPort(), getservbyname() 
  3810.  
  3811.  
  3812. ΓòÉΓòÉΓòÉ 7.3. Microsoft Windows-specific Extensions ΓòÉΓòÉΓòÉ
  3813.  
  3814. WSAAsyncGetHostByAddr() 
  3815.  
  3816. WSAAsyncGetHostByName() 
  3817.  
  3818. WSAAsyncGetProtoByName() 
  3819.  
  3820. WSAAsyncGetProtoByNumber() 
  3821.  
  3822. WSAAsyncGetServByName() 
  3823.  
  3824. WSAAsyncGetServByPort() 
  3825.  
  3826. WSAAsyncSelect() 
  3827.  
  3828. WSACancelAsyncRequest() 
  3829.  
  3830. WSACancelBlockingCall() 
  3831.  
  3832. WSACleanup() 
  3833.  
  3834. WSAGetLastError() 
  3835.  
  3836. WSAIsBlocking() 
  3837.  
  3838. WSASetBlockingHook() 
  3839.  
  3840. WSASetLastError() 
  3841.  
  3842. WSAStartup() 
  3843.  
  3844. WSAUnhookBlockingHook() 
  3845.  
  3846.  
  3847. ΓòÉΓòÉΓòÉ 7.3.1. WSAAsyncGetHostByAddr() ΓòÉΓòÉΓòÉ
  3848.  
  3849. Description 
  3850.  
  3851. Get host information corresponding to an address - asynchronous version. 
  3852.  
  3853. #include <winsock.h>
  3854.  
  3855. HANDLE PASCAL FAR WSAAsyncGetHostByAddr ( HWND hWnd, unsigned int wMsg, const 
  3856. char FAR * addr, int len, int type, char FAR * buf, int buflen); 
  3857.  
  3858.  hWnd 
  3859.    The handle of the window which should receive a message when the 
  3860.    asynchronous request completes. 
  3861.  
  3862.  wMsg 
  3863.    The message to be received when the asynchronous request completes. 
  3864.  
  3865.  addr 
  3866.    Apointer to the network address for the host.  Host addresses are stored in 
  3867.    network byte order. 
  3868.  
  3869.  len 
  3870.    The length of the address, which must be 4 for PF_INET. 
  3871.  
  3872.  type 
  3873.    The type of the address, which must be PF_INET. 
  3874.  
  3875.  buf 
  3876.    A pointer to the data area to receive the hostent data.  Note that this must 
  3877.    be larger than the size of a hostent structure.  This is because the data 
  3878.    area supplied is used by the Windows Sockets implementation to contain not 
  3879.    only a hostent structure but any and all of the data which is referenced by 
  3880.    members of the hostent structure.  It is recommended that you supply a 
  3881.    buffer of MAXGETHOSTSTRUCT bytes. 
  3882.  
  3883.  buflen 
  3884.    The size of data area buf above. 
  3885.  
  3886.  Remarks 
  3887.  
  3888.  This function is an asynchronous version of gethostbyaddr(), and is used to 
  3889.  retrieve host name and address information corresponding to a network address. 
  3890.  The Windows Sockets implementation initiates the operation and returns to the 
  3891.  caller immediately, passing back an asynchronous task handle which the 
  3892.  application may use to identify the operation.  When the operation is 
  3893.  completed, the results (if any) are copied into the buffer provided by the 
  3894.  caller and a message is sent to the application's window. When the 
  3895.  asynchronous operation is complete the application's window hWnd receives 
  3896.  message wMsg.  The wParam argument contains the asynchronous task handle as 
  3897.  returned by the original function call.  The high 16 bits of lParam contain 
  3898.  any error code.  The error code may be any error as defined in winsock.h.  An 
  3899.  error code of zero indicates successful completion of the asynchronous 
  3900.  operation.  On successful completion, the buffer supplied to the original 
  3901.  function call contains a hostent structure. To access the elements of this 
  3902.  structure, the original buffer address should be cast to a hostent structure 
  3903.  pointer and accessed as appropriate. 
  3904.  
  3905.  Note that if the error code is WSAENOBUFS, it indicates that the size of the 
  3906.  buffer specified by buflen in the original call was too small to contain all 
  3907.  the resultant information.  In this case, the low 16 bits of lParam contain 
  3908.  the size of buffer required to supply ALL the requisite information. If the 
  3909.  application decides that the partial data is inadequate, it may reissue the 
  3910.  WSAAsyncGetHostByAddr() function call with a buffer large enough to receive 
  3911.  all the desired  information (i.e.  no smaller than the low 16 bits of 
  3912.  lParam). 
  3913.  
  3914.  The error code and buffer length should be extracted from the lParam using the 
  3915.  macros  WSAGETASYNCERROR and WSAGETASYNCBUFLEN, defined in winsock.h as: 
  3916.  
  3917.   #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  3918.   #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  3919.  
  3920.  The use of these macros will maximize the portability of the source code for 
  3921.  the application. 
  3922.  
  3923.  Return Value 
  3924.  
  3925.  The return value specifies whether or not the asynchronous operation was 
  3926.  successfully initiated.  Note that it does not imply success or failure of the 
  3927.  operation itself. If the operation was successfully initiated, 
  3928.  WSAAsyncGetHostByAddr() returns a nonzero value of type HANDLE which is the 
  3929.  asynchronous task handle for the request.  This value can be used in two ways. 
  3930.  It can be used to cancel the operation using WSACancelAsyncRequest(). It can 
  3931.  also be used to match up asynchronous operations and completion messages, by 
  3932.  examining the wParam message argument. 
  3933.  
  3934.  If the asynchronous operation could not be initiated, WSAAsyncGetHostByAddr() 
  3935.  returns a zero value, and a specific error number may be retrieved by calling 
  3936.  WSAGetLastError(). 
  3937.  
  3938.  Comments 
  3939.  
  3940.  The buffer supplied to this function is used by the Windows Sockets 
  3941.  implementation to construct a hostent structure together with the contents of 
  3942.  data areas referenced by members of the same hostent structure.  To avoid the 
  3943.  WSAENOBUFS error noted above, the application should provide a buffer of at 
  3944.  least MAXGETHOSTSTRUCT bytes (as defined in winsock.h). 
  3945.  
  3946.  Notes For Windows Sockets Suppliers 
  3947.  
  3948.  It is the responsibility of the Windows Sockets implementation to ensure that 
  3949.  messages are successfully posted to the application.  If a PostMessage() 
  3950.  operation fails, the Windows Sockets implementation must re-post that message 
  3951.  as long as the window exists. 
  3952.  
  3953.  Windows Sockets suppliers should use the WSAMAKEASYNCREPLY macro when 
  3954.  constructing the lParam in the message. 
  3955.  
  3956.  Error Codes 
  3957.  
  3958.  The following error codes may be set when an application window receives a 
  3959.  message.  As described above, they may be extracted from the lParam in the 
  3960.  reply message using the WSAGETASYNCERROR macro. 
  3961.  
  3962.  WSAENETDOWN 
  3963.            The Windows Sockets implementation has detected that the network 
  3964.            subsystem has failed. 
  3965.  
  3966.  WSAENOBUFS 
  3967.            No/insufficient buffer space is available 
  3968.  
  3969.  WSAHOST_NOT_FOUND 
  3970.            Authoritative Answer Host not found. 
  3971.  
  3972.  WSATRY_AGAIN 
  3973.            Non-Authoritative Host not found, or SERVERFAIL. 
  3974.  
  3975.  WSANO_RECOVERY 
  3976.            Non recoverable errors, FORMERR, REFUSED, NOTIMP. 
  3977.  
  3978.  WSANO_DATA 
  3979.            Valid name, no data record of requested type. 
  3980.  
  3981.  The following errors may occur at the time of the function call, and indicate 
  3982.  that the asynchronous operation could not be initiated. 
  3983.  
  3984.  WSANOTINITIALISED 
  3985.            A successful WSAStartup() must occur before using this API. 
  3986.  
  3987.  WSAENETDOWN 
  3988.            The Windows Sockets implementation has detected that the network 
  3989.            subsystem has failed. 
  3990.  
  3991.  WSAEINPROGRESS 
  3992.            A blocking Windows Sockets operation is in progress. 
  3993.  
  3994.  WSAEWOULDBLOCK 
  3995.            The asynchronous operation cannot be scheduled at this time due to 
  3996.            resource or other constraints within the Windows Sockets implementation.
  3997.  
  3998.  See Also 
  3999.  
  4000.  gethostbyaddr(), WSACancelAsyncRequest() 
  4001.  
  4002.  
  4003. ΓòÉΓòÉΓòÉ 7.3.2. WSAAsyncGetHostByName() ΓòÉΓòÉΓòÉ
  4004.  
  4005. Description 
  4006.  
  4007. Get host information corresponding to a hostname - asynchronous version. 
  4008.  
  4009. #include <winsock.h>
  4010.  
  4011. HANDLE PASCAL FAR WSAAsyncGetHostByName ( HWND hWnd, unsigned int wMsg, const 
  4012. char FAR * name, char FAR * buf, int buflen); 
  4013.  
  4014.  hWnd 
  4015.    The handle of the window which should receive a message when the 
  4016.    asynchronous request completes. 
  4017.  
  4018.  wMsg 
  4019.    The message to be received when the asynchronous request completes. 
  4020.  
  4021.  name 
  4022.    Apointer to the name of the host. 
  4023.  
  4024.  buf 
  4025.    A pointer to the data area to receive the hostent data.  Note that this must 
  4026.    be larger than the size of a hostent structure.  This is because the data 
  4027.    area supplied is used by the Windows Sockets implementation to contain not 
  4028.    only a hostent structure but any and all of the data which is referenced by 
  4029.    members of the hostent structure.  It is recommended that you supply a 
  4030.    buffer of MAXGETHOSTSTRUCT bytes. 
  4031.  
  4032.  buflen 
  4033.    The size of data area buf above. 
  4034.  
  4035.  Remarks 
  4036.  
  4037.  This function is an asynchronous version of gethostbyname(), and is used to 
  4038.  retrieve host name and address information corresponding to a hostname.  The 
  4039.  Windows Sockets implementation initiates the operation and returns to the 
  4040.  caller immediately, passing back an asynchronous task handle which the 
  4041.  application may use to identify the operation.  When the operation is 
  4042.  completed, the results (if any) are copied into the buffer provided by the 
  4043.  caller and a message is sent to the application's window.  When the 
  4044.  asynchronous operation is complete the application's window hWnd receives 
  4045.  message wMsg.  The wParam argument contains the asynchronous task handle as 
  4046.  returned by the original function call.  The high 16 bits of lParam contain 
  4047.  any error code.  The error code may be any error as defined in winsock.h.  An 
  4048.  error code of zero indicates successful completion of the asynchronous 
  4049.  operation.  On successful completion, the buffer supplied to the original 
  4050.  function call contains a hostent structure. To access the elements of this 
  4051.  structure, the original buffer address should be cast to a hostent structure 
  4052.  pointer and accessed as appropriate. 
  4053.  
  4054.  Note that if the error code is WSAENOBUFS, it indicates that the size of the 
  4055.  buffer specified by buflen in the original call was too small to contain all 
  4056.  the resultant information.  In this case, the low 16 bits of lParam contain 
  4057.  the size of buffer required to supply ALL the requisite information. If the 
  4058.  application decides that the partial data is inadequate, it may reissue the 
  4059.  WSAAsyncGetHostByName() function call with a buffer large enough to receive 
  4060.  all the desired  information (i.e. no smaller than the low 16 bits of lParam). 
  4061.  
  4062.  The error code and buffer length should be extracted from the lParam using the 
  4063.  macros  WSAGETASYNCERROR and WSAGETASYNCBUFLEN, defined in winsock.h as: 
  4064.  
  4065.   #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  4066.   #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  4067.  
  4068.  The use of these macros will maximize the portability of the source code for 
  4069.  the application. 
  4070.  
  4071.  Return Value 
  4072.  
  4073.  The return value specifies whether or not the asynchronous operation was 
  4074.  successfully initiated.  Note that it does not imply success or failure of the 
  4075.  operation itself. If the operation was successfully initiated, 
  4076.  WSAAsyncGetHostByName() returns a nonzero value of type HANDLE which is the 
  4077.  asynchronous task handle for the request.  This value can be used in two ways. 
  4078.  It can be used to cancel the operation using WSACancelAsyncRequest(). It can 
  4079.  also be used to match up asynchronous operations and completion messages, by 
  4080.  examining the wParam message argument. 
  4081.  
  4082.  If the asynchronous operation could not be initiated, WSAAsyncGetHostByName() 
  4083.  returns a zero value, and a specific error number may be retrieved by calling 
  4084.  WSAGetLastError(). 
  4085.  
  4086.  Comments 
  4087.  
  4088.  The buffer supplied to this function is used by the Windows Sockets 
  4089.  implementation to construct a hostent structure together with the contents of 
  4090.  data areas referenced by members of the same hostent structure.  To avoid the 
  4091.  WSAENOBUFS error noted above, the application should provide a buffer of at 
  4092.  least MAXGETHOSTSTRUCT bytes (as defined in winsock.h). 
  4093.  
  4094.  Notes For Windows Sockets Suppliers 
  4095.  
  4096.  It is the responsibility of the Windows Sockets implementation to ensure that 
  4097.  messages are successfully posted to the application.  If a PostMessage() 
  4098.  operation fails, the Windows Sockets implementation must re-post that message 
  4099.  as long as the window exists. 
  4100.  
  4101.  Windows Sockets suppliers should use the WSAMAKEASYNCREPLY macro when 
  4102.  constructing the lParam in the message. 
  4103.  
  4104.  Error Codes 
  4105.  
  4106.  The following error codes may be set when an application window receives a 
  4107.  message.  As described above, they may be extracted from the lParam in the 
  4108.  reply message using the WSAGETASYNCERROR macro. 
  4109.  
  4110.  WSAENETDOWN 
  4111.            The Windows Sockets implementation has detected that the network 
  4112.            subsystem has failed. 
  4113.  
  4114.  WSAENOBUFS 
  4115.            No/insufficient buffer space is available 
  4116.  
  4117.  WSAHOST_NOT_FOUND 
  4118.            Authoritative Answer Host not found. 
  4119.  
  4120.  WSATRY_AGAIN 
  4121.            Non-Authoritative Host not found, or SERVERFAIL. 
  4122.  
  4123.  WSANO_RECOVERY 
  4124.            Non recoverable errors, FORMERR, REFUSED, NOTIMP. 
  4125.  
  4126.  WSANO_DATA 
  4127.            Valid name, no data record of requested type. 
  4128.  
  4129.  The following errors may occur at the time of the function call, and indicate 
  4130.  that the asynchronous operation could not be initiated. 
  4131.  
  4132.  WSANOTINITIALISED 
  4133.            A successful WSAStartup() must occur before using this API. 
  4134.  
  4135.  WSAENETDOWN 
  4136.            The Windows Sockets implementation has detected that the network 
  4137.            subsystem has failed. 
  4138.  
  4139.  WSAEINPROGRESS 
  4140.            A blocking Windows Sockets operation is in progress. 
  4141.  
  4142.  WSAEWOULDBLOCK 
  4143.            The asynchronous operation cannot be scheduled at this time due to 
  4144.            resource or other constraints within the Windows Sockets implementation.
  4145.  
  4146.  See Also 
  4147.  
  4148.  gethostbyname(), WSACancelAsyncRequest() 
  4149.  
  4150.  
  4151. ΓòÉΓòÉΓòÉ 7.3.3. WSAAsyncGetProtoByName() ΓòÉΓòÉΓòÉ
  4152.  
  4153. Description 
  4154.  
  4155. Get protocol information corresponding to a protocol name - asynchronous 
  4156. version. 
  4157.  
  4158. #include <winsock.h>
  4159.  
  4160. HANDLE PASCAL FAR WSAAsyncGetProtoByName ( HWND hWnd, unsigned int wMsg, const 
  4161. char FAR * name, char FAR * buf, int buflen); 
  4162.  
  4163.  hWnd 
  4164.    The handle of the window which should receive a message when the 
  4165.    asynchronous request completes. 
  4166.  
  4167.  wMsg 
  4168.    The message to be received when the asynchronous request completes. 
  4169.  
  4170.  name 
  4171.    Apointer to the protocol name to be resolved. 
  4172.  
  4173.  buf 
  4174.    A pointer to the data area to receive the protoent data.  Note that this 
  4175.    must be larger than the size of a protoent structure.  This is because the 
  4176.    data area supplied is used by the Windows Sockets implementation to contain 
  4177.    not only a protoent structure but any and all of the data which is 
  4178.    referenced by members of the protoent structure.  It is recommended that you 
  4179.    supply a buffer of MAXGETHOSTSTRUCT bytes. 
  4180.  
  4181.  buflen 
  4182.    The size of data area buf above. 
  4183.  
  4184.  Remarks 
  4185.  
  4186.  This function is an asynchronous version of getprotobyname(), and is used to 
  4187.  retrieve the protocol name and number corresponding to a protocol name.  The 
  4188.  Windows Sockets implementation initiates the operation and returns to the 
  4189.  caller immediately, passing back an asynchronous task handle which the 
  4190.  application may use to identify the operation.  When the operation is 
  4191.  completed, the results (if any) are copied into the buffer provided by the 
  4192.  caller and a message is sent to the application's window.  When the 
  4193.  asynchronous operation is complete the application's window hWnd receives 
  4194.  message wMsg.  The wParam argument contains the asynchronous task handle as 
  4195.  returned by the original function call.  The high 16 bits of lParam contain 
  4196.  any error code.  The error code may be any error as defined in winsock.h.  An 
  4197.  error code of zero indicates successful completion of the asynchronous 
  4198.  operation.  On successful completion, the buffer supplied to the original 
  4199.  function call contains a protoent structure.  To access the elements of this 
  4200.  structure, the original buffer address should be cast to a protoent structure 
  4201.  pointer and accessed as appropriate. 
  4202.  
  4203.  Note that if the error code is WSAENOBUFS, it indicates that the size of the 
  4204.  buffer specified by buflen in the original call was too small to contain all 
  4205.  the resultant information.  In this case, the low 16 bits of lParam contain 
  4206.  the size of buffer required to supply ALL the requisite information. If the 
  4207.  application decides that the partial data is inadequate, it may reissue the 
  4208.  WSAAsyncGetProtoByName() function call with a buffer large enough to receive 
  4209.  all the desired  information (i.e.  no smaller than the low 16 bits of 
  4210.  lParam). 
  4211.  
  4212.  The error code and buffer length should be extracted from the lParam using the 
  4213.  macros  WSAGETASYNCERROR and WSAGETASYNCBUFLEN, defined in winsock.h as: 
  4214.  
  4215.   #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  4216.   #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  4217.  
  4218.  The use of these macros will maximize the portability of the source code for 
  4219.  the application. 
  4220.  
  4221.  Return Value 
  4222.  
  4223.  The return value specifies whether or not the asynchronous operation was 
  4224.  successfully initiated.  Note that it does not imply success or failure of the 
  4225.  operation itself. If the operation was successfully initiated, 
  4226.  WSAAsyncGetProtoByName() returns a nonzero value of type HANDLE which is the 
  4227.  asynchronous task handle for the request.  This value can be used in two ways. 
  4228.  It can be used to cancel the operation using WSACancelAsyncRequest(). It can 
  4229.  also be used to match up asynchronous operations and completion messages, by 
  4230.  examining the wParam message argument. 
  4231.  
  4232.  If the asynchronous operation could not be initiated, WSAAsyncGetProtoByName() 
  4233.  returns a zero value, and a specific error number may be retrieved by calling 
  4234.  WSAGetLastError(). 
  4235.  
  4236.  Comments 
  4237.  
  4238.  The buffer supplied to this function is used by the Windows Sockets 
  4239.  implementation to construct a protoent structure together with the contents of 
  4240.  data areas referenced by members of the same protoent structure. To avoid the 
  4241.  WSAENOBUFS error noted above, the application should provide a buffer of at 
  4242.  least MAXGETHOSTSTRUCT bytes (as defined in winsock.h). 
  4243.  
  4244.  Notes For Windows Sockets Suppliers 
  4245.  
  4246.  It is the responsibility of the Windows Sockets implementation to ensure that 
  4247.  messages are successfully posted to the application.  If a PostMessage() 
  4248.  operation fails, the Windows Sockets implementation must re-post that message 
  4249.  as long as the window exists. 
  4250.  
  4251.  Windows Sockets suppliers should use the WSAMAKEASYNCREPLY macro when 
  4252.  constructing the lParam in the message. 
  4253.  
  4254.  Error Codes 
  4255.  
  4256.  The following error codes may be set when an application window receives a 
  4257.  message.  As described above, they may be extracted from the lParam in the 
  4258.  reply message using the WSAGETASYNCERROR macro. 
  4259.  
  4260.  WSAENETDOWN 
  4261.            The Windows Sockets implementation has detected that the network 
  4262.            subsystem has failed. 
  4263.  
  4264.  WSAENOBUFS 
  4265.            No/insufficient buffer space is available 
  4266.  
  4267.  WSAHOST_NOT_FOUND 
  4268.            Authoritative Answer Host not found. 
  4269.  
  4270.  WSATRY_AGAIN 
  4271.            Non-Authoritative Host not found, or SERVERFAIL. 
  4272.  
  4273.  WSANO_RECOVERY 
  4274.            Non recoverable errors, FORMERR, REFUSED, NOTIMP. 
  4275.  
  4276.  WSANO_DATA 
  4277.            Valid name, no data record of requested type. 
  4278.  
  4279.  The following errors may occur at the time of the function call, and indicate 
  4280.  that the asynchronous operation could not be initiated. 
  4281.  
  4282.  WSANOTINITIALISED 
  4283.            A successful WSAStartup() must occur before using this API. 
  4284.  
  4285.  WSAENETDOWN 
  4286.            The Windows Sockets implementation has detected that the network 
  4287.            subsystem has failed. 
  4288.  
  4289.  WSAEINPROGRESS 
  4290.            A blocking Windows Sockets operation is in progress. 
  4291.  
  4292.  WSAEWOULDBLOCK 
  4293.            The asynchronous operation cannot be scheduled at this time due to 
  4294.            resource or other constraints within the Windows Sockets implementation.
  4295.  
  4296.  See Also 
  4297.  
  4298.  getprotobyname(), WSACancelAsyncRequest() 
  4299.  
  4300.  
  4301. ΓòÉΓòÉΓòÉ 7.3.4. WSAAsyncGetProtoByNumber() ΓòÉΓòÉΓòÉ
  4302.  
  4303. Description 
  4304.  
  4305. Get protocol information corresponding to a protocol number - asynchronous 
  4306. version. 
  4307.  
  4308. #include <winsock.h>
  4309.  
  4310. HANDLE PASCAL FAR WSAAsyncGetProtoByNumber ( HWND hWnd, unsigned int wMsg, int 
  4311. number, char FAR * buf, int buflen); 
  4312.  
  4313.  hWnd 
  4314.    The handle of the window which should receive a message when the 
  4315.    asynchronous request completes. 
  4316.  
  4317.  wMsg 
  4318.    The message to be received when the asynchronous request completes. 
  4319.  
  4320.  number 
  4321.    The protocol number to be resolved, in host byte order. 
  4322.  
  4323.  buf 
  4324.    A pointer to the data area to receive the protoent data.  Note that this 
  4325.    must be larger than the size of a protoent structure.  This is because the 
  4326.    data area supplied is used by the Windows Sockets implementation to contain 
  4327.    not only a protoent structure but any and all of the data which is 
  4328.    referenced by members of the protoent structure.  It is recommended that you 
  4329.    supply a buffer of MAXGETHOSTSTRUCT bytes. 
  4330.  
  4331.  buflen 
  4332.    The size of data area buf above. 
  4333.  
  4334.  Remarks 
  4335.  
  4336.  This function is an asynchronous version of getprotobynumber(), and is used to 
  4337.  retrieve the protocol name and number corresponding to a protocol number.  The 
  4338.  Windows Sockets implementation initiates the operation and returns to the 
  4339.  caller immediately, passing back an asynchronous task handle which the 
  4340.  application may use to identify the operation.  When the operation is 
  4341.  completed, the results (if any) are copied into the buffer provided by the 
  4342.  caller and a message is sent to the application's window.  When the 
  4343.  asynchronous operation is complete the application's window hWnd receives 
  4344.  message wMsg.  The wParam argument contains the asynchronous task handle as 
  4345.  returned by the original function call.  The high 16 bits of lParam contain 
  4346.  any error code.  The error code may be any error as defined in winsock.h.  An 
  4347.  error code of zero indicates successful completion of the asynchronous 
  4348.  operation.  On successful completion, the buffer supplied to the original 
  4349.  function call contains a protoent structure.  To access the elements of this 
  4350.  structure, the original buffer address should be cast to a protoent structure 
  4351.  pointer and accessed as appropriate. 
  4352.  
  4353.  Note that if the error code is WSAENOBUFS, it indicates that the size of the 
  4354.  buffer specified by buflen in the original call was too small to contain all 
  4355.  the resultant information.  In this case, the low 16 bits of lParam contain 
  4356.  the size of buffer required to supply ALL the requisite information. If the 
  4357.  application decides that the partial data is inadequate, it may reissue the 
  4358.  WSAAsyncGetProtoByNumber() function call with a buffer large enough to receive 
  4359.  all the desired  information (i.e. no smaller than the low 16 bits of lParam). 
  4360.  
  4361.  The error code and buffer length should be extracted from the lParam using the 
  4362.  macros  WSAGETASYNCERROR and WSAGETASYNCBUFLEN, defined in winsock.h as: 
  4363.  
  4364.   #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  4365.   #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  4366.  
  4367.  The use of these macros will maximize the portability of the source code for 
  4368.  the application. 
  4369.  
  4370.  Return Value 
  4371.  
  4372.  The return value specifies whether or not the asynchronous operation was 
  4373.  successfully initiated.  Note that it does not imply success or failure of the 
  4374.  operation itself. If the operation was successfully initiated, 
  4375.  WSAAsyncGetProtoByNumber() returns a nonzero value of type HANDLE which is the 
  4376.  asynchronous task handle for the request.  This value can be used in two ways. 
  4377.  It can be used to cancel the operation using WSACancelAsyncRequest(). It can 
  4378.  also be used to match up asynchronous operations and completion messages, by 
  4379.  examining the wParam message argument. 
  4380.  
  4381.  If the asynchronous operation could not be initiated, 
  4382.  WSAAsyncGetProtoByNumber() returns a zero value, and a specific error number 
  4383.  may be retrieved by calling WSAGetLastError(). 
  4384.  
  4385.  Comments 
  4386.  
  4387.  The buffer supplied to this function is used by the Windows Sockets 
  4388.  implementation to construct a protoent structure together with the contents of 
  4389.  data areas referenced by members of the same protoent structure. To avoid the 
  4390.  WSAENOBUFS error noted above, the application should provide a buffer of at 
  4391.  least MAXGETHOSTSTRUCT bytes (as defined in winsock.h). 
  4392.  
  4393.  Notes For Windows Sockets Suppliers 
  4394.  
  4395.  It is the responsibility of the Windows Sockets implementation to ensure that 
  4396.  messages are successfully posted to the application.  If a PostMessage() 
  4397.  operation fails, the Windows Sockets implementation must re-post that message 
  4398.  as long as the window exists. 
  4399.  
  4400.  Windows Sockets suppliers should use the WSAMAKEASYNCREPLY macro when 
  4401.  constructing the lParam in the message. 
  4402.  
  4403.  Error Codes 
  4404.  
  4405.  The following error codes may be set when an application window receives a 
  4406.  message.  As described above, they may be extracted from the lParam in the 
  4407.  reply message using the WSAGETASYNCERROR macro. 
  4408.  
  4409.  WSAENETDOWN 
  4410.            The Windows Sockets implementation has detected that the network 
  4411.            subsystem has failed. 
  4412.  
  4413.  WSAENOBUFS 
  4414.            No/insufficient buffer space is available 
  4415.  
  4416.  WSAHOST_NOT_FOUND 
  4417.            Authoritative Answer Host not found. 
  4418.  
  4419.  WSATRY_AGAIN 
  4420.            Non-Authoritative Host not found, or SERVERFAIL. 
  4421.  
  4422.  WSANO_RECOVERY 
  4423.            Non recoverable errors, FORMERR, REFUSED, NOTIMP. 
  4424.  
  4425.  WSANO_DATA 
  4426.            Valid name, no data record of requested type. 
  4427.  
  4428.  The following errors may occur at the time of the function call, and indicate 
  4429.  that the asynchronous operation could not be initiated. 
  4430.  
  4431.  WSANOTINITIALISED 
  4432.            A successful WSAStartup() must occur before using this API. 
  4433.  
  4434.  WSAENETDOWN 
  4435.            The Windows Sockets implementation has detected that the network 
  4436.            subsystem has failed. 
  4437.  
  4438.  WSAEINPROGRESS 
  4439.            A blocking Windows Sockets operation is in progress. 
  4440.  
  4441.  WSAEWOULDBLOCK 
  4442.            The asynchronous operation cannot be scheduled at this time due to 
  4443.            resource or other constraints within the Windows Sockets 
  4444.            implementation. 
  4445.  
  4446.  See Also 
  4447.  
  4448.  getprotobynumber(), WSACancelAsyncRequest() 
  4449.  
  4450.  
  4451. ΓòÉΓòÉΓòÉ 7.3.5. WSAAsyncGetServByName() ΓòÉΓòÉΓòÉ
  4452.  
  4453. Description 
  4454.  
  4455. Get service information corresponding to a service name and port -- 
  4456. asynchronous version. 
  4457.  
  4458. #include <winsock.h>
  4459.  
  4460. HANDLE PASCAL FAR WSAAsyncGetServByName ( HWND hWnd, unsigned int wMsg, const 
  4461. char FAR * name, const char FAR * proto, char FAR * buf, int buflen ); 
  4462.  
  4463.  hWnd 
  4464.    The handle of the window which should receive a message when the 
  4465.    asynchronous request completes. 
  4466.  
  4467.  wMsg 
  4468.    The message to be received when the asynchronous request completes. 
  4469.  
  4470.  name 
  4471.    A pointer to a service name. 
  4472.  
  4473.  proto 
  4474.    A pointer to a protocol name.  This may be NULL, in which case 
  4475.    WSAAsyncGetServByName() will search for the first service entry for which 
  4476.    s_name or one of the s_aliases matches the given name.  Otherwise 
  4477.    WSAAsyncGetServByName() matches both name and proto. 
  4478.  
  4479.  buf 
  4480.    A pointer to the data area to receive the servent data.  Note that this must 
  4481.    be larger than the size of a servent structure.  This is because the data 
  4482.    area supplied is used by the Windows Sockets implementation to contain not 
  4483.    only a servent structure but any and all of the data which is referenced by 
  4484.    members of the servent structure.  It is recommended that you supply a 
  4485.    buffer of MAXGETHOSTSTRUCT bytes. 
  4486.  
  4487.  buflen 
  4488.    The size of data area buf above. 
  4489.  
  4490.  Remarks 
  4491.  
  4492.  This function is an asynchronous version of getservbyname(), and is used to 
  4493.  retrieve service information corresponding to a service name. The Windows 
  4494.  Sockets implementation initiates the operation and returns to the caller 
  4495.  immediately, passing back an asynchronous task handle which the application 
  4496.  may use to identify the operation.  When the operation is completed, the 
  4497.  results (if any) are copied into the buffer provided by the caller and a 
  4498.  message is sent to the application's window.  When the asynchronous operation 
  4499.  is complete the application's window hWnd receives message wMsg.  The wParam 
  4500.  argument contains the asynchronous task handle as returned by the original 
  4501.  function call.  The high 16 bits of lParam contain any error code.  The error 
  4502.  code may be any error as defined in winsock.h.  An error code of zero 
  4503.  indicates successful completion of the asynchronous operation.  On successful 
  4504.  completion, the buffer supplied to the original function call contains a 
  4505.  hostent structure. To access the elements of this structure, the original 
  4506.  buffer address should be cast to a hostent structure pointer and accessed as 
  4507.  appropriate. 
  4508.  
  4509.  Note that if the error code is WSAENOBUFS, it indicates that the size of the 
  4510.  buffer specified by buflen in the original call was too small to contain all 
  4511.  the resultant information.  In this case, the low 16 bits of lParam contain 
  4512.  the size of buffer required to supply ALL the requisite information. If the 
  4513.  application decides that the partial data is inadequate, it may reissue the 
  4514.  WSAAsyncGetServByName() function call with a buffer large enough to receive 
  4515.  all the desired  information (i.e. no smaller than the low 16 bits of lParam). 
  4516.  
  4517.  The error code and buffer length should be extracted from the lParam using the 
  4518.  macros  WSAGETASYNCERROR and WSAGETASYNCBUFLEN, defined in winsock.h as: 
  4519.  
  4520.   #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  4521.   #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  4522.  
  4523.  The use of these macros will maximize the portability of the source code for 
  4524.  the application. 
  4525.  
  4526.  Return Value 
  4527.  
  4528.  The return value specifies whether or not the asynchronous operation was 
  4529.  successfully initiated.  Note that it does not imply success or failure of the 
  4530.  operation itself. If the operation was successfully initiated, 
  4531.  WSAAsyncGetServByName() returns a nonzero value of type HANDLE which is the 
  4532.  asynchronous task handle for the request.  This value can be used in two ways. 
  4533.  It can be used to cancel the operation using WSACancelAsyncRequest(). It can 
  4534.  also be used to match up asynchronous operations and completion messages, by 
  4535.  examining the wParam message argument. 
  4536.  
  4537.  If the asynchronous operation could not be initiated, WSAAsyncGetHostByAddr() 
  4538.  returns a zero value, and a specific error number may be retrieved by calling 
  4539.  WSAGetLastError(). 
  4540.  
  4541.  Comments 
  4542.  
  4543.  The buffer supplied to this function is used by the Windows Sockets 
  4544.  implementation to construct a hostent structure together with the contents of 
  4545.  data areas referenced by members of the same hostent structure.  To avoid the 
  4546.  WSAENOBUFS error noted above, the application should provide a buffer of at 
  4547.  least MAXGETHOSTSTRUCT bytes (as defined in winsock.h). 
  4548.  
  4549.  Notes For Windows Sockets Suppliers 
  4550.  
  4551.  It is the responsibility of the Windows Sockets implementation to ensure that 
  4552.  messages are successfully posted to the application.  If a PostMessage() 
  4553.  operation fails, the Windows Sockets implementation must re-post that message 
  4554.  as long as the window exists. 
  4555.  
  4556.  Windows Sockets suppliers should use the WSAMAKEASYNCREPLY macro when 
  4557.  constructing the lParam in the message. 
  4558.  
  4559.  Error Codes 
  4560.  
  4561.  The following error codes may be set when an application window receives a 
  4562.  message.  As described above, they may be extracted from the lParam in the 
  4563.  reply message using the WSAGETASYNCERROR macro. 
  4564.  
  4565.  WSAENETDOWN 
  4566.            The Windows Sockets implementation has detected that the network 
  4567.            subsystem has failed. 
  4568.  
  4569.  WSAENOBUFS 
  4570.            No/insufficient buffer space is available 
  4571.  
  4572.  WSAHOST_NOT_FOUND 
  4573.            Authoritative Answer Host not found. 
  4574.  
  4575.  WSATRY_AGAIN 
  4576.            Non-Authoritative Host not found, or SERVERFAIL. 
  4577.  
  4578.  WSANO_RECOVERY 
  4579.            Non recoverable errors, FORMERR, REFUSED, NOTIMP. 
  4580.  
  4581.  WSANO_DATA 
  4582.            Valid name, no data record of requested type. 
  4583.  
  4584.  The following errors may occur at the time of the function call, and indicate 
  4585.  that the asynchronous operation could not be initiated. 
  4586.  
  4587.  WSANOTINITIALISED 
  4588.            A successful WSAStartup() must occur before using this API. 
  4589.  
  4590.  WSAENETDOWN 
  4591.            The Windows Sockets implementation has detected that the network 
  4592.            subsystem has failed. 
  4593.  
  4594.  WSAEINPROGRESS 
  4595.            A blocking Windows Sockets operation is in progress. 
  4596.  
  4597.  WSAEWOULDBLOCK 
  4598.            The asynchronous operation cannot be scheduled at this time due to 
  4599.            resource or other constraints within the Windows Sockets implementation.
  4600.  
  4601.  See Also 
  4602.  
  4603.  getservbyname(), WSACancelAsyncRequest() 
  4604.  
  4605.  
  4606. ΓòÉΓòÉΓòÉ 7.3.6. WSAAsyncGetServByPort() ΓòÉΓòÉΓòÉ
  4607.  
  4608. Description 
  4609.  
  4610. Get service information corresponding to a port and protocol - asynchronous 
  4611. version. 
  4612.  
  4613. #include <winsock.h>
  4614.  
  4615. HANDLE PASCAL FAR WSAAsyncGetServByPort ( HWND hWnd, unsigned int wMsg, int 
  4616. port, const char FAR * proto, char FAR * buf, int buflen ); 
  4617.  
  4618.  hWnd 
  4619.    The handle of the window which should receive a message when the 
  4620.    asynchronous request completes. 
  4621.  
  4622.  wMsg 
  4623.    The message to be received when the asynchronous request completes. 
  4624.  
  4625.  port 
  4626.    The port for the service, in network byte order. 
  4627.  
  4628.  proto 
  4629.    A pointer to a protocol name.  This may be NULL, in which case 
  4630.    WSAAsyncGetServByPort() will search for the first service entry for which 
  4631.    s_port match the given port.  Otherwise WSAAsyncGetServByPort() matches both 
  4632.    port and proto. 
  4633.  
  4634.  buf 
  4635.    A pointer to the data area to receive the servent data.  Note that this must 
  4636.    be larger than the size of a servent structure.  This is because the data 
  4637.    area supplied is used by the Windows Sockets implementation to contain not 
  4638.    only a servent structure but any and all of the data which is referenced by 
  4639.    members of the servent structure.  It is recommended that you supply a 
  4640.    buffer of MAXGETHOSTSTRUCT bytes. 
  4641.  
  4642.  buflen 
  4643.    The size of data area buf above. 
  4644.  
  4645.  Remarks 
  4646.  
  4647.  This function is an asynchronous version of getservbyport(), and is used to 
  4648.  retrieve service information corresponding to a port number. The Windows 
  4649.  Sockets implementation initiates the operation and returns to the caller 
  4650.  immediately, passing back an asynchronous task handle which the application 
  4651.  may use to identify the operation.  When the operation is completed, the 
  4652.  results (if any) are copied into the buffer provided by the caller and a 
  4653.  message is sent to the application's window.  When the asynchronous operation 
  4654.  is complete the application's window hWnd receives message wMsg.  The wParam 
  4655.  argument contains the asynchronous task handle as returned by the original 
  4656.  function call.  The high 16 bits of lParam contain any error code.  The error 
  4657.  code may be any error as defined in winsock.h.  An error code of zero 
  4658.  indicates successful completion of the asynchronous operation.  On successful 
  4659.  completion, the buffer supplied to the original function call contains a 
  4660.  servent structure. To access the elements of this structure, the original 
  4661.  buffer address should be cast to a servent structure pointer and accessed as 
  4662.  appropriate. 
  4663.  
  4664.  Note that if the error code is WSAENOBUFS, it indicates that the size of the 
  4665.  buffer specified by buflen in the original call was too small to contain all 
  4666.  the resultant information.  In this case, the low 16 bits of lParam contain 
  4667.  the size of buffer required to supply ALL the requisite information. If the 
  4668.  application decides that the partial data is inadequate, it may reissue the 
  4669.  WSAAsyncGetServByPort() function call with a buffer large enough to receive 
  4670.  all the desired  information (i.e. no smaller than the low 16 bits of lParam). 
  4671.  
  4672.  The error code and buffer length should be extracted from the lParam using the 
  4673.  macros  WSAGETASYNCERROR and WSAGETASYNCBUFLEN, defined in winsock.h as: 
  4674.  
  4675.   #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  4676.   #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  4677.  
  4678.  The use of these macros will maximize the portability of the source code for 
  4679.  the application. 
  4680.  
  4681.  Return Value 
  4682.  
  4683.  The return value specifies whether or not the asynchronous operation was 
  4684.  successfully initiated.  Note that it does not imply success or failure of the 
  4685.  operation itself. If the operation was successfully initiated, 
  4686.  WSAAsyncGetServByPort() returns a nonzero value of type HANDLE which is the 
  4687.  asynchronous task handle for the request.  This value can be used in two ways. 
  4688.  It can be used to cancel the operation using WSACancelAsyncRequest(). It can 
  4689.  also be used to match up asynchronous operations and completion messages, by 
  4690.  examining the wParam message argument. 
  4691.  
  4692.  If the asynchronous operation could not be initiated, WSAAsyncGetServByPort() 
  4693.  returns a zero value, and a specific error number may be retrieved by calling 
  4694.  WSAGetLastError(). 
  4695.  
  4696.  Comments 
  4697.  
  4698.  The buffer supplied to this function is used by the Windows Sockets 
  4699.  implementation to construct a servent structure together with the contents of 
  4700.  data areas referenced by members of the same servent structure.  To avoid the 
  4701.  WSAENOBUFS error noted above, the application should provide a buffer of at 
  4702.  least MAXGETHOSTSTRUCT bytes (as defined in winsock.h). 
  4703.  
  4704.  Notes For Windows Sockets Suppliers 
  4705.  
  4706.  It is the responsibility of the Windows Sockets implementation to ensure that 
  4707.  messages are successfully posted to the application.  If a PostMessage() 
  4708.  operation fails, the Windows Sockets implementation must re-post that message 
  4709.  as long as the window exists. 
  4710.  
  4711.  Windows Sockets suppliers should use the WSAMAKEASYNCREPLY macro when 
  4712.  constructing the lParam in the message. 
  4713.  
  4714.  Error Codes 
  4715.  
  4716.  The following error codes may be set when an application window receives a 
  4717.  message.  As described above, they may be extracted from the lParam in the 
  4718.  reply message using the WSAGETASYNCERROR macro. 
  4719.  
  4720.  WSAENETDOWN 
  4721.            The Windows Sockets implementation has detected that the network 
  4722.            subsystem has failed. 
  4723.  
  4724.  WSAENOBUFS 
  4725.            No/insufficient buffer space is available 
  4726.  
  4727.  WSAHOST_NOT_FOUND 
  4728.            Authoritative Answer Host not found. 
  4729.  
  4730.  WSATRY_AGAIN 
  4731.            Non-Authoritative Host not found, or SERVERFAIL. 
  4732.  
  4733.  WSANO_RECOVERY 
  4734.            Non recoverable errors, FORMERR, REFUSED, NOTIMP. 
  4735.  
  4736.  WSANO_DATA 
  4737.            Valid name, no data record of requested type. 
  4738.  
  4739.  The following errors may occur at the time of the function call, and indicate 
  4740.  that the asynchronous operation could not be initiated. 
  4741.  
  4742.  WSANOTINITIALISED 
  4743.            A successful WSAStartup() must occur before using this API. 
  4744.  
  4745.  WSAENETDOWN 
  4746.            The Windows Sockets implementation has detected that the network 
  4747.            subsystem has failed. 
  4748.  
  4749.  WSAEINPROGRESS 
  4750.            A blocking Windows Sockets operation is in progress. 
  4751.  
  4752.  WSAEWOULDBLOCK 
  4753.            The asynchronous operation cannot be scheduled at this time due to 
  4754.            resource or other constraints within the Windows Sockets implementation.
  4755.  
  4756.  See Also 
  4757.  
  4758.  getservbyport(), WSACancelAsyncRequest() 
  4759.  
  4760.  
  4761. ΓòÉΓòÉΓòÉ 7.3.7. WSAAsyncSelect() ΓòÉΓòÉΓòÉ
  4762.  
  4763. Description 
  4764.  
  4765. Request event notification for a socket. 
  4766.  
  4767. #include <winsock.h>
  4768.  
  4769. int PASCAL FAR WSAAsyncSelect ( SOCKET s, HWND hWnd, unsigned int wMsg, long 
  4770. lEvent ); 
  4771.  
  4772.  s 
  4773.    A descriptor identifying the socket for which event notification is 
  4774.    required. 
  4775.  
  4776.  hWnd 
  4777.    A handle identifying the window which should receive a message when a 
  4778.    network event occurs. 
  4779.  
  4780.  wMsg 
  4781.    The message to be received when a network event occurs. 
  4782.  
  4783.  lEvent 
  4784.    A bitmask which specifies a combination of network events in which the 
  4785.    application is interested. 
  4786.  
  4787.  Remarks 
  4788.  
  4789.  This function is used to request that the Windows Sockets DLL should send a 
  4790.  message to the window hWnd whenever it detects any of the network events 
  4791.  specified by the lEvent parameter.  The message which should be sent is 
  4792.  specified by the wMsg parameter.  The socket for which notification is 
  4793.  required is identified by s.  The lEvent parameter is constructed by or'ing 
  4794.  any of the values specified in the following list. 
  4795.  
  4796.  FD_READ 
  4797.            Want to receive notification of readiness for reading 
  4798.  
  4799.  FD_WRITE 
  4800.            Want to receive notification of readiness for writing 
  4801.  
  4802.  FD_OOB 
  4803.            Want to receive notification of the arrival of out-of-band data 
  4804.  
  4805.  FD_ACCEPT 
  4806.            Want to receive notification of incoming connections 
  4807.  
  4808.  FD_CONNECT 
  4809.            Want to receive notification of completed connection 
  4810.  
  4811.  FD_CLOSE 
  4812.            Want to receive notification of socket closure 
  4813.  
  4814.  Issuing a WSAAsyncSelect() for a socket cancels any previous WSAAsyncSelect() 
  4815.  for the same socket.  For example, to receive notification for both reading 
  4816.  and writing, the application must call WSAAsyncSelect() with both FD_READ and 
  4817.  FD_WRITE, as follows: 
  4818.  
  4819.   rc = WSAAsyncSelect(s, hWnd, wMsg, FD_READ!FD_WRITE);
  4820.  
  4821.  It is not possible to specify different messages for different events.  The 
  4822.  following code will not work; the second call will cancel the effects of the 
  4823.  first, and only FD_WRITE events will be reported with message wMsg2: 
  4824.  
  4825.   rc = WSAAsyncSelect(s, hWnd, wMsg1, FD_READ);
  4826.   rc = WSAAsyncSelect(s, hWnd, wMsg2, FD_WRITE);
  4827.  
  4828.  To cancel all notification -- i.e., to indicate that the Windows Sockets 
  4829.  implementation should send no further messages related to network events on 
  4830.  the socket -- lEvent should be set to zero. 
  4831.  
  4832.   rc = WSAAsyncSelect(s, hWnd, 0, 0);
  4833.  
  4834.  Although in this instance WSAAsyncSelect() immediately disables event message 
  4835.  posting for the socket, it is possible that messages may be waiting in the 
  4836.  application's message queue.  The application must therefore be prepared to 
  4837.  receive network event messages even after cancellation.  Closing a socket with 
  4838.  closesocket() also cancels WSAAsyncSelect() message sending, but the same 
  4839.  caveat about messages in the queue prior to the closesocket() still applies. 
  4840.  
  4841.  Since an accept()'ed socket has the same properties as the listening socket 
  4842.  used to accept it, any WSAAsyncSelect() events set for the listening socket 
  4843.  apply to the accepted socket.  For example, if a listening socket has 
  4844.  WSAAsyncSelect() events FD_ACCEPT, FD_READ, and FD_WRITE, then any socket 
  4845.  accepted on that listening socket will also have FD_ACCEPT, FD_READ, and 
  4846.  FD_WRITE events with the same wMsg value used for messages.  If a different 
  4847.  wMsg or events are desired, the application should call WSAAsyncSelect(), 
  4848.  passing the accepted socket and the desired new information. 
  4849.  
  4850.  ╤ìNote: There is a timing window between the accept() call and the call to 
  4851.  WSAAsyncSelect() to change the events or wMsg.  An application which desires a 
  4852.  different wMsg for the listening and accept()'ed sockets should ask for only 
  4853.  FD_ACCEPT events on the listening socket, then set appropriate events after 
  4854.  the accept(). Since FD_ACCEPT is never sent for a connected socket and 
  4855.  FD_READ, FD_WRITE, FD_OOB, and FD_CLOSE are never sent for listening sockets, 
  4856.  this will not impose difficulties.ΓêÖ 
  4857.  
  4858.  When one of the nominated network events occurs on the specified socket s, the 
  4859.  application's window hWnd receives message wMsg. The wParam argument 
  4860.  identifies the socket on which a network event has occurred.  The low word of 
  4861.  lParam specifies the network event that has occurred.  The high word of lParam 
  4862.  contains any error code.  The error code be any error as defined in winsock.h. 
  4863.  
  4864.  The error and event codes may be extracted from the lParam using the macros 
  4865.  WSAGETSELECTERROR and WSAGETSELECTEVENT, defined in winsock.h as: 
  4866.  
  4867.   #define WSAGETSELECTERROR(lParam)            HIWORD(lParam)
  4868.   #define WSAGETSELECTEVENT(lParam)            LOWORD(lParam)
  4869.  
  4870.  The use of these macros will maximize the portability of the source code for 
  4871.  the application. 
  4872.  
  4873.  The possible network event codes which may be returned are as follows: 
  4874.  
  4875.  FD_READ 
  4876.            Socket s ready for reading 
  4877.  
  4878.  FD_WRITE 
  4879.            Socket s ready for writing 
  4880.  
  4881.  FD_OOB 
  4882.            Out-of-band data ready for reading on socket s. 
  4883.  
  4884.  FD_ACCEPT 
  4885.            Socket s ready for accepting a new incoming connection 
  4886.  
  4887.  FD_CONNECT 
  4888.            Connection on socket s completed 
  4889.  
  4890.  FD_CLOSE 
  4891.            Connection identified by socket s has been closed 
  4892.  
  4893.  Return Value 
  4894.  
  4895.  The return value is 0 if the application's declaration of interest in the 
  4896.  network event set was successful.  Otherwise the value SOCKET_ERROR is 
  4897.  returned, and a specific error number may be retrieved by calling 
  4898.  WSAGetLastError(). 
  4899.  
  4900.  Comments 
  4901.  
  4902.  Although WSAAsyncSelect() can be called with interest in multiple events, the 
  4903.  application window will receive a single message for each network event. As in 
  4904.  the case of the select() function, WSAAsyncSelect() will frequently be used to 
  4905.  determine when a data transfer operation (send() or recv()) can be issued with 
  4906.  the expectation of immediate success. Nevertheless, a robust application must 
  4907.  be prepared for the possibility that it may receive a message and issue a 
  4908.  Windows Sockets API call which returns WSAEWOULDBLOCK immediately.  For 
  4909.  example, the following sequence of events is possible: 
  4910.  
  4911.    1. data arrives on socket s; Windows Sockets posts WSAAsyncSelect message 
  4912.  
  4913.    2. application processes some other message 
  4914.  
  4915.    3. while processing, application issues an ioctlsocket(s, FIONREAD...) and 
  4916.       notices that there is data ready to be read 
  4917.  
  4918.    4. application issues a recv(s,...) to read the data 
  4919.  
  4920.    5. application loops to process next message, eventually reaching the 
  4921.       WSAAsyncSelect message indicating that data is ready to read 
  4922.  
  4923.    6. application issues recv(s,...), which fails with the error 
  4924.       WSAEWOULDBLOCK. 
  4925.  
  4926.  Other sequences are possible. 
  4927.  
  4928.  The Windows Sockets DLL will not continually flood an application with 
  4929.  messages for a particular network event.  Having successfully posted 
  4930.  notification of a particular event to an application window, no further 
  4931.  message(s) for that network event will be posted to the application window 
  4932.  until the application makes the function call which implicitly re-enables 
  4933.  notification of that network event. 
  4934.  
  4935.  FD_READ 
  4936.            recv() or recvfrom() 
  4937.  
  4938.  FD_WRITE 
  4939.            send() or sendto() 
  4940.  
  4941.  FD_OOB 
  4942.            recv() 
  4943.  
  4944.  FD_ACCEPT 
  4945.            accept() 
  4946.  
  4947.  FD_CONNECT 
  4948.            NONE 
  4949.  
  4950.  FD_CLOSE 
  4951.            NONE 
  4952.  
  4953.  Any call to the reenabling routine, even one which fails, results in 
  4954.  reenabling of message posting for the relevent event. 
  4955.  
  4956.  For FD_READ, FD_OOB, and FD_ACCEPT events, message posting is 
  4957.  "level-triggerred."  This means that if the reenabling routine is called and 
  4958.  the relevent event is still valid after the call, a WSAAsyncSelect() message 
  4959.  is posted to the application.  This allows an application to be event-driven 
  4960.  and not concern itself with the amount of data that arrives at any one time. 
  4961.  Consider the following sequence: 
  4962.  
  4963.    1. Windows Sockets DLL receives 100 bytes of data on socket s and posts an 
  4964.       FD_READ message. 
  4965.  
  4966.    2. The application issues recv( s, buffptr, 50, 0) to read 50 bytes. 
  4967.  
  4968.    3. The Windows Sockets DLL posts another FD_READ message since there is 
  4969.       still data to be read. 
  4970.  
  4971.  With these semantics, an application need not read all available data in 
  4972.  response to an FD_READ message--a single recv() in response to each FD_READ 
  4973.  message is appropriate.  If an application issues multiple recv() calls in 
  4974.  response to a single FD_READ, it may receive multiple FD_READ messages.  Such 
  4975.  an application may wish to disable FD_READ messages before starting the recv() 
  4976.  calls by calling WSAAsyncSelect() with the FD_READ event not set. 
  4977.  
  4978.  If an event is true when the application initially calls WSAAsyncSelect() or 
  4979.  when the reenabling function is called, then a message is posted as 
  4980.  appropriate.  For example, if an application calls listen(), a connect attempt 
  4981.  is made, then the application calls WSAAsyncSelect() specifying that it wants 
  4982.  to receive FD_ACCEPT messages for the socket, the Windows Sockets 
  4983.  implementation posts an FD_ACCEPT message immediately. 
  4984.  
  4985.  The FD_WRITE event is handled slightly differently.  An FD_WRITE message is 
  4986.  posted when a socket is first connected with connect() or accepted with 
  4987.  accept(), and then after a send() or sendto() fails with WSAEWOULDBLOCK and 
  4988.  buffer space becomes available.  Therefore, an application can assume that 
  4989.  sends are possible starting from the first FD_WRITE message and lasting until 
  4990.  a send returns WSAEWOULDBLOCK.  After such a failure the application will be 
  4991.  notified that sends are again possible with an FD_WRITE message. 
  4992.  
  4993.  The FD_OOB event is used only when a socket is configured to receive 
  4994.  out-of-band data separately.  If the socket is configured to receive 
  4995.  out-of-band data in-line, the out-of-band (expedited) data is treated as 
  4996.  normal data and the application should register an interest in, and will 
  4997.  receive, FD_READ events, not FD_OOB events.  An application may set or inspect 
  4998.  the way in which out-of-band data is to be handled by using setsockopt() or 
  4999.  getsockopt for the SO_OOBINLINE option. 
  5000.  
  5001.  The error code in an FD_CLOSE message indicates whether the socket close was 
  5002.  graceful or abortive.  If the error code is 0, then the close was graceful; if 
  5003.  the error code is WSAECONNRESET, then the socket's virtual socket was 
  5004.  abortively disconnected.  This only applies to sockets of type SOCK_STREAM. 
  5005.  
  5006.  The FD_CLOSE message is posted when a close indication is received for the 
  5007.  virtual circuit corresponding to the socket.  In TCP terms, this means that 
  5008.  the FD_CLOSE is posted when the connection goes into the FIN WAIT or CLOSE 
  5009.  WAIT states.  This results from the remote end performing a shutdown() on the 
  5010.  send side or a closesocket(). 
  5011.  
  5012.  Please note your application will receive ONLY an FD_CLOSE message to indicate 
  5013.  closure of a virtual circuit. It will NOT receive an FD_READ message to 
  5014.  indicate this condition. 
  5015.  
  5016.  Error Codes 
  5017.  
  5018.  WSANOTINITIALISED 
  5019.            A successful WSAStartup() must occur before using this API. 
  5020.  
  5021.  WSAENETDOWN 
  5022.            The Windows Sockets implementation has detected that the network 
  5023.            subsystem has failed. 
  5024.  
  5025.  WSAEINVAL 
  5026.            Indicates that one of the specified parameters was invalid 
  5027.  
  5028.  WSAEINPROGRESS 
  5029.            A blocking Windows Sockets operation is in progress. 
  5030.  
  5031.  Additional error codes may be set when an application window receives a 
  5032.  message.  This error code is extracted from the lParam in the reply message 
  5033.  using the WSAGETSELECTERROR macro.  Possible error codes for each network 
  5034.  event are:Event: FD_CONNECT 
  5035.  
  5036.  Error Codes 
  5037.  
  5038.  WSAEADDRINUSE 
  5039.            The specified address is already in use. 
  5040.  
  5041.  WSAEADDRNOTAVAIL 
  5042.            The specified address is not available from the local machine. 
  5043.  
  5044.  WSAEAFNOSUPPORT 
  5045.            Addresses in the specified family cannot be used with this socket. 
  5046.  
  5047.  WSAECONNREFUSED 
  5048.            The attempt to connect was forcefully rejected. 
  5049.  
  5050.  WSAEDESTADDRREQ 
  5051.            A destination address is required. 
  5052.  
  5053.  WSAEFAULT 
  5054.            The namelen argument is incorrect. 
  5055.  
  5056.  WSAEINVAL 
  5057.            The socket is already bound to an address. 
  5058.  
  5059.  WSAEISCONN 
  5060.            The socket is already connected. 
  5061.  
  5062.  WSAEMFILE 
  5063.            No more file descriptors are available. 
  5064.  
  5065.  WSAENETUNREACH 
  5066.            The network can't be reached from this host at this time. 
  5067.  
  5068.  WSAENOBUFS 
  5069.            No buffer space is available.  The socket cannot be connected. 
  5070.  
  5071.  WSAENOTCONN 
  5072.            The socket is not connected. 
  5073.  
  5074.  WSAENOTSOCK 
  5075.            The descriptor is a file, not a socket. 
  5076.  
  5077.  WSAETIMEDOUT 
  5078.            Attempt to connect timed out without establishing a connection 
  5079.  
  5080.  Event: FD_CLOSE 
  5081.  
  5082.  Error Codes 
  5083.  
  5084.  WSAENETDOWN 
  5085.            The Windows Sockets implementation has detected that the network 
  5086.            subsystem has failed. 
  5087.  
  5088.  WSAECONNRESET 
  5089.            The connection is reset by the remote side. 
  5090.  
  5091.  WSAECONNABORTED 
  5092.            The connection was aborted due to timeout or other failure.
  5093.  
  5094.  Event: FD_READ 
  5095.  Event: FD_WRITE 
  5096.  Event: FD_OOB 
  5097.  Event: FD_ACCEPT 
  5098.  
  5099.  
  5100.  Error Code 
  5101.  
  5102.  WSAENETDOWN 
  5103.            The Windows Sockets implementation has detected that the network 
  5104.            subsystem has failed. 
  5105.  
  5106.  Notes For Windows Sockets Suppliers 
  5107.  
  5108.  It is the responsibility of the Windows Sockets Supplier to ensure that 
  5109.  messages are successfully posted to the application.  If a PostMessage() 
  5110.  operation fails, the Windows Sockets implementation must re-post that message 
  5111.  as long as the window exists. 
  5112.  
  5113.  Windows Sockets suppliers should use the WSAMAKESELECTREPLY macro when 
  5114.  constructing the lParam in the message. When a socket is closed, the Windows 
  5115.  Sockets Supplier should purge any messages remaining for posting to the 
  5116.  application window.  However the application must be prepared to receive, and 
  5117.  discard, any messages which may have been posted prior to the closesocket(). 
  5118.  
  5119.  See Also 
  5120.  
  5121.  select() 
  5122.  
  5123.  
  5124. ΓòÉΓòÉΓòÉ 7.3.8. WSACancelAsyncRequest() ΓòÉΓòÉΓòÉ
  5125.  
  5126. Description 
  5127.  
  5128. Cancel an incomplete asynchronous operation. 
  5129.  
  5130. #include <winsock.h>
  5131.  
  5132. int PASCAL FAR WSACancelAsyncRequest ( HANDLE hAsyncTaskHandle ); 
  5133.  
  5134.  hAsyncTaskHandle 
  5135.    Specifies the asynchronous operation to be canceled. 
  5136.  
  5137.  Remarks 
  5138.  
  5139.  The WSACancelAsyncRequest() function is used to cancel an asynchronous 
  5140.  operation which was initiated by one of the WSAAsyncGetXByY() functions such 
  5141.  as WSAAsyncGetHostByName(). The operation to be canceled is identified by the 
  5142.  hAsyncTaskHandle parameter, which should be set to the asynchronous task 
  5143.  handle as returned by the initiating function.  Return Value   The value 
  5144.  returned by WSACancelAsyncRequest() is 0 if the operation was successfully 
  5145.  canceled. Otherwise the value SOCKET_ERROR is returned, and a specific error 
  5146.  number may be retrieved by calling WSAGetLastError(). 
  5147.  
  5148.  Comments 
  5149.  
  5150.  An attempt to cancel an existing asynchronous WSAAsyncGetXByY() operation can 
  5151.  fail with an error code of WSAEALREADY for two reasons.  Firstly, the original 
  5152.  operation has already completed and the application has dealt with the 
  5153.  resultant message.  Secondly, the original operation has already completed but 
  5154.  the resultant message is still waiting in the application window queue. 
  5155.  
  5156.  Notes For Windows Sockets Suppliers 
  5157.  
  5158.  It is unclear whether the application can usefully distinguish between 
  5159.  WSAEINVAL and WSAEALREADY, since in both cases the error indicates that there 
  5160.  is no asynchronous operation in progress with the indicated handle. ╤ìTrivial 
  5161.  exception: 0 is always an invalid asynchronous task handle.ΓêÖ  The Windows 
  5162.  Sockets specification does not prescribe how a conformant Windows Sockets 
  5163.  implementation should distinguish between the two cases.  For maximum 
  5164.  portability, a Windows Sockets application should treat the two errors as 
  5165.  equivalent. 
  5166.  
  5167.  Error Codes 
  5168.  
  5169.  WSANOTINITIALISED 
  5170.            A successful WSAStartup() must occur before using this API. 
  5171.  
  5172.  WSAENETDOWN 
  5173.            The Windows Sockets implementation has detected that the network 
  5174.            subsystem has failed. 
  5175.  
  5176.  WSAEINVAL 
  5177.            Indicates that the specified asynchronous task handle was invalid 
  5178.  
  5179.  WSAEINPROGRESS 
  5180.            A blocking Windows Sockets operation is in progress. 
  5181.  
  5182.  WSAEALREADY 
  5183.            The asynchronous routine being canceled has already completed. 
  5184.  
  5185.  See Also 
  5186.  
  5187.  WSAAsyncGetHostByAddr(), WSAAsyncGetHostByName(), WSAAsyncGetProtoByNumber(), 
  5188.  WSAAsyncGetProtoByName(), WSAAsyncGetHostByName(), WSAAsyncGetServByPort(), 
  5189.  WSAAsyncGetServByName() 
  5190.  
  5191.  
  5192. ΓòÉΓòÉΓòÉ 7.3.9. WSACancelBlockingCall() ΓòÉΓòÉΓòÉ
  5193.  
  5194. Description 
  5195.  
  5196. Cancel a blocking call which is currently in progress. 
  5197.  
  5198. #include <winsock.h>
  5199.  
  5200. int PASCAL FAR WSACancelBlockingCall ( void ); 
  5201.  
  5202. Remarks 
  5203.  
  5204. This function cancels any outstanding blocking operation for this task.  It is 
  5205. normally used in two situations: 
  5206.  
  5207.    1. An application is processing a message which has been received while a 
  5208.       blocking call is in progress.  In this case, WSAIsBlocking() will be 
  5209.       true. 
  5210.  
  5211.    2. A blocking call is in progress, and Windows Sockets has called back to 
  5212.       the application's "blocking hook" function (as established by 
  5213.       WSASetBlockingHook()). 
  5214.  
  5215.  In each case, the original blocking call will terminate as soon as possible 
  5216.  with the error WSAEINTR.  (In (1), the termination will not take place until 
  5217.  Windows message scheduling has caused control to revert to the blocking 
  5218.  routine in Windows Sockets.  In (2), the blocking call will be terminated as 
  5219.  soon as the blocking hook function completes.) 
  5220.  
  5221.  In the case of a blocking connect() operation, the Windows Sockets 
  5222.  implementation will terminate the blocking call as soon as possible, but it 
  5223.  may not be possible for the socket resources to be released until the 
  5224.  connection has completed (and then been reset) or timed out. This is likely to 
  5225.  be noticeable only if the application immediately tries to open a new socket 
  5226.  (if no sockets are available), or to connect() to the same peer. 
  5227.  
  5228.  Cancelling an accept() or a select() call does not adversely impact the 
  5229.  sockets passed to these calls.  Only the particular call fails; any operation 
  5230.  that was legal before the cancel is legal after the cancel, and the state of 
  5231.  the socket is not affected in any way. 
  5232.  
  5233.  Cancelling any operation other than accept() and select() can leave the socket 
  5234.  in an indeterminate state.  If an application cancels a blocking operation on 
  5235.  a socket, the only operation that the application can depend on being able to 
  5236.  perform on the socket is a call to closesocket(), although other operations 
  5237.  may work on some Windows Sockets implementations.  If an application desires 
  5238.  maximum portability, it must be careful not to depend on performing operations 
  5239.  after a cancel.  An application may reset the connection by setting the 
  5240.  timeout on SO_LINGER to 0. 
  5241.  
  5242.  If a cancel operation comprimised the integrity of a SOCK_STREAM's data stream 
  5243.  in any way, the Windows Sockets implementation must reset the connection and 
  5244.  fail all future operations other than closesocket() with WSAECONNABORTED. 
  5245.  
  5246.  Return Value 
  5247.  
  5248.  The value returned by WSACancelBlockingCall() is 0 if the operation was 
  5249.  successfully canceled.  Otherwise the value SOCKET_ERROR is returned, and a 
  5250.  specific error number may be retrieved by calling WSAGetLastError(). Comments 
  5251.  Note that it is possible that the network operation completes before the 
  5252.  WSACancelBlockingCall()  is processed, for example if data is received into 
  5253.  the user buffer at interrupt time while the application is in a blocking hook. 
  5254.  In this case, the blocking operation will return successfully as if 
  5255.  WSACancelBlockingCall() had never been called.  Note that the 
  5256.  WSACancelBlockingCall() still succeeds in this case; the only way to know with 
  5257.  certainty that an operation was actually cancelled is to check for a return 
  5258.  code of WSAEINTR from the blocking call. 
  5259.  
  5260.  Error Codes 
  5261.  
  5262.  WSANOTINITIALISED 
  5263.            A successful WSAStartup() must occur before using this API. 
  5264.  
  5265.  WSAENETDOWN 
  5266.            The Windows Sockets implementation has detected that the network 
  5267.            subsystem has failed. 
  5268.  
  5269.  WSAEINVAL 
  5270.            Indicates that there is no outstanding blocking call. 
  5271.  
  5272.  
  5273. ΓòÉΓòÉΓòÉ 7.3.10. WSACleanup() ΓòÉΓòÉΓòÉ
  5274.  
  5275. Description 
  5276.  
  5277. Terminate use of the Windows Sockets DLL. 
  5278.  
  5279. #include <winsock.h>
  5280.  
  5281. int PASCAL FAR WSACleanup ( void ); 
  5282.  
  5283. Remarks 
  5284.  
  5285. An application is required to perform a (successful) WSAStartup() call before 
  5286. it can use Windows Sockets services.  When it has completed the use of Windows 
  5287. Sockets, the application must call WSACleanup() to deregister itself from a 
  5288. Windows Sockets implementation and allow the implementation to free any 
  5289. resources allocated on behalf of the application or DLL.  Any open SOCK_STREAM 
  5290. sockets that are connected when WSACleanup() is called are reset; sockets which 
  5291. have been closed with closesocket() but which still have pending data to be 
  5292. sent are not affected--the pending data is still sent. 
  5293.  
  5294. There must be a call to WSACleanup() for every call to WSAStartup() made by a 
  5295. task.  Only the final WSACleanup() does the actual cleanup; the preceding calls 
  5296. simply decrement an internal reference count in the Windows Sockets DLL.  A 
  5297. naive application may ensure that WSACleanup() was called enough times by 
  5298. calling WSACleanup() in a loop until it returns WSANOTINITIALISED. 
  5299.  
  5300. Return Value 
  5301.  
  5302. The return value is 0 if the operation was successful. Otherwise the value 
  5303. SOCKET_ERROR is returned, and a specific error number may be retrieved by 
  5304. calling WSAGetLastError(). 
  5305.  
  5306. Comments 
  5307.  
  5308. Attempting to call WSACleanup() from within a blocking hook and then failing to 
  5309. check the return code is a common Windows Sockets programming error.  If an 
  5310. application needs to quit while a blocking call is outstanding, the application 
  5311. must first cancel the blocking call with WSACancelBlockingCall() then issue the 
  5312. WSACleanup() call once control has been returned to the application. 
  5313.  
  5314. Notes For Windows Sockets Suppliers 
  5315.  
  5316. Well-behaved Windows Sockets applications will make a WSACleanup() call to 
  5317. indicate deregistration from a Windows Sockets implementation.  This function 
  5318. can thus, for example, be utilized to free up resources allocated to the 
  5319. specific application. 
  5320.  
  5321. A Windows Sockets implementation must be prepared to deal with an application 
  5322. which terminates without invoking WSACleanup() -- for example, as a result of 
  5323. an error. 
  5324.  
  5325. In a multithreaded environment, WSACleanup() terminates Windows Sockets 
  5326. operations for all threads. 
  5327.  
  5328. A Windows Sockets implementation must ensure that WSACleanup() leaves things in 
  5329. a state in which the application can invoke WSAStartup() to re-establish 
  5330. Windows Sockets usage. 
  5331.  
  5332. Error Codes 
  5333.  
  5334.  WSANOTINITIALISED 
  5335.            A successful WSAStartup() must occur before using this API. 
  5336.  
  5337.  WSAENETDOWN 
  5338.            The Windows Sockets implementation has detected that the network 
  5339.            subsystem has failed. 
  5340.  
  5341.  WSAEINPROGRESS 
  5342.            A blocking Windows Sockets operation is in progress.
  5343.  
  5344.  See Also 
  5345.  
  5346.  WSAStartup() 
  5347.  
  5348.  
  5349. ΓòÉΓòÉΓòÉ 7.3.11. WSAGetLastError() ΓòÉΓòÉΓòÉ
  5350.  
  5351. Description 
  5352.  
  5353. Get the error status for the last operation which failed. 
  5354.  
  5355. #include <winsock.h>
  5356.  
  5357. int PASCAL FAR WSAGetLastError ( void ); 
  5358.  
  5359. Remarks 
  5360.  
  5361. This function returns the last network error that occurred. When a particular 
  5362. Windows Sockets API function indicates that an error has occurred, this 
  5363. function should be called to retrieve the appropriate error code. 
  5364.  
  5365. Return Value 
  5366.  
  5367. The return value indicates the error code for the last Windows Sockets API 
  5368. routine performed by this thread. 
  5369.  
  5370. Notes For Windows Sockets Suppliers 
  5371.  
  5372. The use of the WSAGetLastError() function to retrieve the last error code, 
  5373. rather than relying on a global error variable (cf. errno), is required in 
  5374. order to provide compatibility with future multi-threaded environments. 
  5375.  
  5376. Note that in a Win16 environment WSAGetLastError() is used to retrieve only 
  5377. Windows Sockets API errors.  In a Win32 environment, WSAGetLastError() will 
  5378. invoke GetLastError(), which is used to retrieve the error status for all Win32 
  5379. API functions on a per-thread basis. For portability, an application should use 
  5380. WSAGetLastError() immediately after the Windows Sockets API function which 
  5381. failed. 
  5382.  
  5383. See Also 
  5384.  
  5385. WSASetLastError() 
  5386.  
  5387.  
  5388. ΓòÉΓòÉΓòÉ 7.3.12. WSAIsBlocking() ΓòÉΓòÉΓòÉ
  5389.  
  5390. Description 
  5391.  
  5392. Determine if a blocking call is in progress. 
  5393.  
  5394. #include <winsock.h>
  5395.  
  5396. BOOL PASCAL FAR WSAIsBlocking ( void ); 
  5397.  
  5398. Remarks 
  5399.  
  5400. This function allows a task to determine if it is executing while waiting for a 
  5401. previous blocking call to complete. 
  5402.  
  5403. Return Value 
  5404.  
  5405. The return value is TRUE if there is an outstanding blocking function awaiting 
  5406. completion.  Otherwise, it is FALSE. 
  5407.  
  5408. Comments 
  5409.  
  5410. Although a call issued on a blocking socket appears to an application program 
  5411. as though it "blocks", the Windows Sockets DLL has to relinquish the processor 
  5412. to allow other applications to run.  This means that it is possible for the 
  5413. application which issued the blocking call to be re-entered, depending on the 
  5414. message(s) it receives.  In this instance, the WSAIsBlocking() function can be 
  5415. used to ascertain whether the task has been re-entered while waiting for an 
  5416. outstanding blocking call to complete. Note that Windows Sockets prohibits more 
  5417. than one outstanding call per thread. 
  5418.  
  5419. Notes For Windows Sockets Suppliers 
  5420.  
  5421. A Windows Sockets implementation must prohibit more than one outstanding 
  5422. blocking call per thread. 
  5423.  
  5424.  
  5425. ΓòÉΓòÉΓòÉ 7.3.13. WSASetBlockingHook() ΓòÉΓòÉΓòÉ
  5426.  
  5427. Description 
  5428.  
  5429. Establish an application-specific blocking hook function. 
  5430.  
  5431. #include <winsock.h>
  5432.  
  5433. FARPROC PASCAL FAR WSASetBlockingHook ( FARPROC lpBlockFunc ); 
  5434.  
  5435.  lpBlockFunc 
  5436.    A pointer to the procedure instance address of the blocking function to be 
  5437.    installed. 
  5438.  
  5439.  Remarks 
  5440.  
  5441.  This function installs a new function which a Windows Sockets implementation 
  5442.  should use to implement blocking socket function calls. A Windows Sockets 
  5443.  implementation includes a default mechanism by which blocking socket functions 
  5444.  are implemented.  The function WSASetBlockingHook() gives the application the 
  5445.  ability to execute its own function at "blocking" time in place of the default 
  5446.  function. 
  5447.  
  5448.  When an application invokes a blocking Windows Sockets API operation, the 
  5449.  Windows Sockets implementation initiates the operation and then enters a loop 
  5450.  which is equivalent to the following pseudocode: 
  5451.  
  5452.   for(;;) {
  5453.        /* flush messages for good user response */
  5454.        while(BlockingHook())
  5455.             ;
  5456.        /* check for WSACancelBlockingCall() */
  5457.        if(operation_cancelled())
  5458.             break;
  5459.        /* check to see if operation completed */
  5460.        if(operation_complete())
  5461.             break;     /* normal completion */
  5462.   }
  5463.  
  5464.  Note that Windows Sockets implementations may perform the above steps in a 
  5465.  different order; for example, the check for operation complete may occur 
  5466.  before calling the blocking hook.  The default BlockingHook() function is 
  5467.  equivalent to: 
  5468.  
  5469.   BOOL DefaultBlockingHook(void) {
  5470.        MSG msg;
  5471.        BOOL ret;
  5472.        /* get the next message if any */
  5473.        ret = (BOOL)PeekMessage(&msg,NULL,0,0,PM_REMOVE);
  5474.        /* if we got one, process it */
  5475.        if (ret) {
  5476.             TranslateMessage(&msg);
  5477.             DispatchMessage(&msg);
  5478.        }
  5479.        /* TRUE if we got a message */
  5480.        return ret;
  5481.   }
  5482.  
  5483.  The WSASetBlockingHook() function is provided to support those applications 
  5484.  which require more complex message processing -- for example, those employing 
  5485.  the MDI (multiple document interface) model.  It is not intended as a 
  5486.  mechanism for performing general applications functions.  In particular, the 
  5487.  only Windows Sockets API function which may be issued from a custom blocking 
  5488.  hook function is WSACancelBlockingCall(), which will cause the blocking loop 
  5489.  to terminate. 
  5490.  
  5491.  This function must be implemented on a per-task basis for non-multithreaded 
  5492.  versions of Windows and on a per-thread basis for multithreaded versions of 
  5493.  Windows such as Windows NT.  It thus provides for a particular task or thread 
  5494.  to replace the blocking mechanism without affecting other tasks or threads. 
  5495.  
  5496.  In multithreaded versions of Windows, there is no default blocking 
  5497.  hook--blocking calls block the thread that makes the call.  However, an 
  5498.  application may install a specific blocking hook by calling 
  5499.  WSASetBlockingHook(). 
  5500.  
  5501.  This allows easy portability of applications that depend on the blocking hook 
  5502.  behavior. 
  5503.  
  5504.  Return Value 
  5505.  
  5506.  The return value is a pointer to the procedure-instance of the previously 
  5507.  installed blocking function.  The application or library that calls the 
  5508.  WSASetBlockingHook() function should save this return value so that it can be 
  5509.  restored if necessary.  (If "nesting" is not important, the application may 
  5510.  simply discard the value returned by WSASetBlockingHook() and eventually use 
  5511.  WSAUnhookBlockingHook() to restore the default mechanism.)  If the operation 
  5512.  fails, a NULL pointer is returned, and a specific error number may be 
  5513.  retrieved by calling WSAGetLastError(). 
  5514.  
  5515.  Notes For Windows Sockets Suppliers 
  5516.  
  5517.  This function must be implemented on a per-thread basis.  It thus provides for 
  5518.  a particular thread to replace the blocking mechanism without affecting other 
  5519.  threads. 
  5520.  
  5521.  Error Codes 
  5522.  
  5523.  WSANOTINITIALISED 
  5524.            A successful WSAStartup() must occur before using this API. 
  5525.  
  5526.  WSAENETDOWN 
  5527.            The Windows Sockets implementation has detected that the network 
  5528.            subsystem has failed. 
  5529.  
  5530.  WSAEINPROGRESS 
  5531.            A blocking Windows Sockets operation is in progress.
  5532.  
  5533.  See Also 
  5534.  
  5535.  WSAUnhookBlockingHook() 
  5536.  
  5537.  
  5538. ΓòÉΓòÉΓòÉ 7.3.14. WSASetLastError() ΓòÉΓòÉΓòÉ
  5539.  
  5540. Description 
  5541.  
  5542. Set the error code which can be retrieved by WSAGetLastError(). 
  5543.  
  5544. #include <winsock.h>
  5545.  
  5546. void PASCAL FAR WSASetLastError ( int iError ); 
  5547.  
  5548. Remarks 
  5549.  
  5550. This function allows an application to set the error code to be returned by a 
  5551. subsequent WSAGetLastError() call for the current thread.  Note that any 
  5552. subsequent Windows Sockets routine called by the application will override the 
  5553. error code as set by this routine. 
  5554.  
  5555.  iError 
  5556.    Specifies the error code to be returned by a subsequent WSAGetLastError() 
  5557.    call. 
  5558.  
  5559.  Notes For Windows Sockets Suppliers 
  5560.  
  5561.  In a Win32 environment, this function will invoke SetLastError(). 
  5562.  
  5563.  Return Value 
  5564.  
  5565.  None. 
  5566.  
  5567.  Error Codes 
  5568.  
  5569.  WSANOTINITIALISED 
  5570.            A successful WSAStartup() must occur before using this API.
  5571.  
  5572.  See Also 
  5573.  
  5574.  WSAGetLastError() 
  5575.  
  5576.  
  5577. ΓòÉΓòÉΓòÉ 7.3.15. WSAStartup() ΓòÉΓòÉΓòÉ
  5578.  
  5579. Description 
  5580.  
  5581. #include <winsock.h>
  5582.  
  5583. int PASCAL FAR WSAStartup ( WORD wVersionRequired, LPWSADATA lpWSAData ); 
  5584.  
  5585.  wVersionRequired 
  5586.    The highest version of Windows Sockets API support that the caller can use. 
  5587.    The high order byte specifies the minor version (revision) number; the 
  5588.    low-order byte specifies the major version number. 
  5589.  
  5590.  lpWSAData 
  5591.    A pointer to the WSADATA data structure that is to receive details of the 
  5592.    Windows Sockets implementation. 
  5593.  
  5594.  Remarks 
  5595.  
  5596.  This function must be the first Windows Sockets function called by an 
  5597.  application or DLL.  It allows an application to specify the version of 
  5598.  Windows Sockets API required and to retrieve details of the specific Windows 
  5599.  Sockets implementation.  The application may only issue further Windows 
  5600.  Sockets API functions after a successful WSAStartup() invocation. 
  5601.  
  5602.  In order to support future Windows Sockets implementations and applications 
  5603.  which may have functionality differences from Windows Sockets 1.1, a 
  5604.  negotiation takes place in WSAStartup().  The caller of WSAStartup() and the 
  5605.  Windows Sockets DLL indicate to each other the highest version that they can 
  5606.  support, and each confirms that the other's highest version is acceptable. 
  5607.  Upon entry to WSAStartup(), the Windows Sockets DLL examines the version 
  5608.  requested by the application.  If this version is higher than the lowest 
  5609.  version supported by the DLL, the call succeeds and the DLL returns in 
  5610.  wHighVersion the highest version it supports and in wVersion the minimum of 
  5611.  its high version and wVersionRequested. The Windows Sockets DLL then assumes 
  5612.  that the application will use wVersion.  If the wVersion field of the WSADATA 
  5613.  structure is unacceptable to the caller, it should call WSACleanup() and 
  5614.  either search for another Windows Sockets DLL or fail to initialize. 
  5615.  
  5616.  This negotiation allows both a Windows Sockets DLL and a Windows Sockets 
  5617.  application to support a range of Windows Sockets versions.  An application 
  5618.  can successfully utilize a Windows Sockets DLL if there is any overlap in the 
  5619.  version ranges.  The following chart gives examples of how WSAStartup() works 
  5620.  in conjunction with different application and Windows Sockets DLL versions: 
  5621.  
  5622.   App versions DLL Versions wVersionRequested wVersion wHighVersion End Result
  5623.   ------------ ------------ ----------------- -------- ------------ ----------
  5624.   1.1          1.1          1.1               1.1      1.1          use 1.1
  5625.  
  5626.   1.0 1.1      1.0          1.1               1.0      1.0          use 1.0
  5627.   1.0          1.0 1.1      1.0               1.0      1.1          use 1.0
  5628.   1.1          1.0 1.1      1.1               1.1      1.1          use 1.1
  5629.  
  5630.   1.1          1.0          1.1               1.0      1.0          App fails
  5631.  
  5632.   1.0          1.1          1.0               ---      ---          NotSupp
  5633.  
  5634.   1.0 1.1      1.0 1.1      1.1               1.1      1.1          use 1.1
  5635.  
  5636.   1.1 2.0      1.1          2.0               1.1      1.1          use 1.1
  5637.   2.0          1.1          2.0               1.1      1.1          App fails
  5638.  
  5639.  The following code fragment demonstrates how an application which supports 
  5640.  only version 1.1 of Windows Sockets makes a WSAStartup() call: 
  5641.  
  5642.   WORD wVersionRequested;
  5643.   WSADATA wsaData;
  5644.   int err;
  5645.  
  5646.   wVersionRequested = MAKEWORD( 1, 1 );
  5647.  
  5648.   err = WSAStartup( wVersionRequested, &wsaData );
  5649.   if ( err ]= 0 ) {
  5650.       /* Tell the user that we couldn't find a useable */
  5651.       /* winsock.dll.                                  */
  5652.       return;
  5653.   }
  5654.  
  5655.   /* Confirm that the Windows Sockets DLL supports 1.1.*/
  5656.   /* Note that if the DLL supports versions greater    */
  5657.   /* than 1.1 in addition to 1.1, it will still return */
  5658.   /* 1.1 in wVersion since that is the version we      */
  5659.   /* requested.                                        */
  5660.  
  5661.   if ( LOBYTE( wsaData.wVersion ) ]= 1 !!
  5662.            HIBYTE( wsaData.wVersion ) ]= 1 ) {
  5663.       /* Tell the user that we couldn't find a useable */
  5664.       /* winsock.dll.                                  */
  5665.       WSACleanup( );
  5666.       return;
  5667.   }
  5668.  
  5669.   /* The Windows Sockets DLL is acceptable.  Proceed.  */
  5670.  
  5671.  And this code fragment demonstrates how a Windows Sockets DLL which supports 
  5672.  only version 1.1 performs the WSAStartup() negotiation: 
  5673.  
  5674.   /* Make sure that the version requested is >= 1.1.   */
  5675.   /* The low byte is the major version and the high    */
  5676.   /* byte is the minor version.                        */
  5677.  
  5678.   if ( LOBYTE( wVersionRequested ) < 1 !!
  5679.        ( LOBYTE( wVersionRequested ) == 1 &&
  5680.          HIBYTE( wVersionRequested ) < 1 ) {
  5681.       return WSAVERNOTSUPPORTED;
  5682.   }
  5683.  
  5684.   /* Since we only support 1.1, set both wVersion and  */
  5685.   /* wHighVersion to 1.1.                              */
  5686.  
  5687.   lpWsaData->wVersion = MAKEWORD( 1, 1 );
  5688.   lpWsaData->wHighVersion = MAKEWORD( 1, 1 );
  5689.  
  5690.  Once an application has made a successful WSAStartup() call, it may proceed to 
  5691.  make other Windows Sockets API calls as needed.  When it has finished using 
  5692.  the services of the Windows Sockets DLL, the application must call 
  5693.  WSACleanup() in order to allow the DLL to free any resources allocated by the 
  5694.  Windows Sockets DLL for the application. Details of the actual Windows Sockets 
  5695.  implementation are described in the WSAData structure defined as follows: 
  5696.  
  5697.   struct WSAData {
  5698.           WORD            wVersion;
  5699.           WORD            wHighVersion;
  5700.           char            szDescription╤ìWSADESCRIPTION_LEN+1ΓêÖ;
  5701.           char            szSystemStatus╤ìWSASYSSTATUS_LEN+1ΓêÖ;
  5702.           unsigned short  iMaxSockets;
  5703.           unsigned short  iMaxUdpDg;
  5704.           char FAR *      lpVendorInfo
  5705.   };
  5706.  
  5707.  The members of this structure are: 
  5708.  
  5709.  wVersion 
  5710.    The version of the Windows Sockets specification that the Windows Sockets 
  5711.    DLL expects the caller to use. 
  5712.  
  5713.  wHighVersion 
  5714.    The highest version of the Windows Sockets specification that this DLL can 
  5715.    support (also encoded as above).  Normally this will be the same as 
  5716.    wVersion. 
  5717.  
  5718.  szDescription 
  5719.    A null-terminated ASCII string into which the Windows Sockets DLL copies a 
  5720.    description of the Windows Sockets implementation, including vendor 
  5721.    identification.  The text (up to 256 characters in length) may contain any 
  5722.    characters, but vendors are cautioned against including control and 
  5723.    formatting characters: the most likely use that an application will put this 
  5724.    to is to display it (possibly truncated) in a status message. 
  5725.  
  5726.  szSystemStatus 
  5727.    A null-terminated ASCII string into which the Windows Sockets DLL copies 
  5728.    relevant status or configuration information.  The Windows Sockets DLL 
  5729.    should use this field only if the information might be useful to the user or 
  5730.    support staff: it should not be considered as an extension of the 
  5731.    szDescription field. 
  5732.  
  5733.  iMaxSockets 
  5734.    The maximum number of sockets which a single process can potentially open. A 
  5735.    Windows Sockets implementation may provide a global pool of sockets for 
  5736.    allocation to any process; alternatively it may allocate per-process 
  5737.    resources for sockets.  The number may well reflect the way in which the 
  5738.    Windows Sockets DLL or the networking software was configured.  Application 
  5739.    writers may use this number as a crude indication of whether the Windows 
  5740.    Sockets implementation is usable by the application.  For example, an X 
  5741.    Windows server might check iMaxSockets when first started: if it is less 
  5742.    than 8, the application would display an error message instructing the user 
  5743.    to reconfigure the networking software.  (This is a situation in which the 
  5744.    szSystemStatus text might be used.)  Obviously there is no guarantee that a 
  5745.    particular application can actually allocate iMaxSockets sockets, since 
  5746.    there may be other Windows Sockets applications in use. 
  5747.  
  5748.  iMaxUdpDg 
  5749.    The size in bytes of the largest UDP datagram that can be sent or received 
  5750.    by a Windows Sockets application.  If the implementation imposes no limit, 
  5751.    iMaxUdpDg is zero.  In many implementations of Berkeley sockets, there is an 
  5752.    implicit limit of 8192 bytes on UDP datagrams (which are fragmented if 
  5753.    necessary).  A Windows Sockets implementation may impose a limit based, for 
  5754.    instance, on the allocation of fragment reassembly buffers.  The minimum 
  5755.    value of iMaxUdpDg for a compliant Windows Sockets implementation is 512. 
  5756.    Note that regardless of the value of iMaxUdpDg, it is inadvisable to attempt 
  5757.    to send a broadcast datagram which is larger than the Maximum Transmission 
  5758.    Unit (MTU) for the network.  (The Windows Sockets API does not provide a 
  5759.    mechanism to discover the MTU, but it must be no less than 512 bytes.) 
  5760.  
  5761.  lpVendorInfo 
  5762.    A far pointer to a vendor-specific data structure.  The definition of this 
  5763.    structure (if supplied) is beyond the scope of this specification. 
  5764.  
  5765.  An application may call WSAStartup() more than once if it needs to obtain the 
  5766.  WSAData structure information more than once.  However, the wVersionRequired 
  5767.  parameter is assumed to be the same on all calls to WSAStartup(); that is, an 
  5768.  application cannot change the version of Windows Sockets it expects after the 
  5769.  initial call to WSAStartup(). 
  5770.  
  5771.  There must be one WSACleanup() call corresponding to every WSAStartup() call 
  5772.  to allow third-party DLLs to make use of a Windows Sockets DLL on behalf of an 
  5773.  application.  This means, for example, that if an application calls 
  5774.  WSAStartup() three times, it must call WSACleanup() three times.  The first 
  5775.  two calls to WSACleanup() do nothing except decrement an internal counter; the 
  5776.  final WSACleanup() call does all necessary resource deallocation for the task. 
  5777.  
  5778.  Return Value 
  5779.  
  5780.  WSAStartup() returns zero if successful.  Otherwise it returns one of the 
  5781.  error codes listed below.  Note that the normal mechanism whereby the 
  5782.  application calls WSAGetLastError() to determine the error code cannot be 
  5783.  used, since the Windows Sockets DLL may not have established the client data 
  5784.  area where the "last error" information is stored. 
  5785.  
  5786.  Notes For Windows Sockets Suppliers 
  5787.  
  5788.  Each Windows Sockets application must make a WSAStartup() call before issuing 
  5789.  any other Windows Sockets API calls. This function can thus be utilized for 
  5790.  initialization purposes. 
  5791.  
  5792.  Further issues are discussed in the notes for WSACleanup(). 
  5793.  
  5794.  Error Codes 
  5795.  
  5796.  WSASYSNOTREADY 
  5797.            Indicates that the underlying network subsystem is not ready for 
  5798.            network communication. 
  5799.  
  5800.  WSAVERNOTSUPPORTED 
  5801.            The version of Windows Sockets API support requested is not provided 
  5802.            by this particular Windows Sockets implementation. 
  5803.  
  5804.  WSAEINVAL 
  5805.            The Windows Sockets version specified by the application is not 
  5806.            supported by this DLL.
  5807.  
  5808.  See Also 
  5809.  
  5810.  send(), sendto(), WSACleanup() 
  5811.  
  5812.  
  5813. ΓòÉΓòÉΓòÉ 7.3.16. WSAUnhookBlockingHook() ΓòÉΓòÉΓòÉ
  5814.  
  5815. Description 
  5816.  
  5817. Restore the default blocking hook function. 
  5818.  
  5819. #include <winsock.h>
  5820.  
  5821. int PASCAL FAR WSAUnhookBlockingHook ( void ); 
  5822.  
  5823. Remarks 
  5824.  
  5825. This function removes any previous blocking hook that has been installed and 
  5826. reinstalls the default blocking mechanism. 
  5827.  
  5828. WSAUnhookBlockingHook() will always install the default mechanism, not the 
  5829. previous mechanism.  If an application wish to nest blocking hooks -- i.e. to 
  5830. establish a temporary blocking hook function and then revert to the previous 
  5831. mechanism (whether the default or one established by an earlier 
  5832. WSASetBlockingHook()) - it must save and restore the value returned by 
  5833. WSASetBlockingHook(); it cannot use WSAUnhookBlockingHook(). 
  5834.  
  5835. In multithreaded versions of Windows such as Windows NT, there is no default 
  5836. blocking hook.  Calling WSAUnhookBlockingHook() disables any blocking hook 
  5837. installed by the application and any blocking calls made block the thread which 
  5838. made the call. 
  5839.  
  5840. Return Value 
  5841.  
  5842. The return value is 0 if the operation was successful. Otherwise the value 
  5843. SOCKET_ERROR is returned, and a specific error number may be retrieved by 
  5844. calling WSAGetLastError(). 
  5845.  
  5846. Error Codes 
  5847.  
  5848.  WSANOTINITIALISED 
  5849.            A successful WSAStartup() must occur before using this API.
  5850.  
  5851.  See Also 
  5852.  
  5853.  WSASetBlockingHook() 
  5854.  
  5855.  
  5856. ΓòÉΓòÉΓòÉ 8. Appendices ΓòÉΓòÉΓòÉ
  5857.  
  5858.  
  5859. ΓòÉΓòÉΓòÉ 8.1. Error Codes and Header Files ΓòÉΓòÉΓòÉ
  5860.  
  5861.  
  5862. ΓòÉΓòÉΓòÉ 8.1.1. Error Codes ΓòÉΓòÉΓòÉ
  5863.  
  5864. The following is a list of possible error codes returned by the 
  5865. WSAGetLastError() call, along with their explanations.  The error numbers are 
  5866. consistently set across all Windows Sockets-compliant implementations. 
  5867.  
  5868. Windows Sockets code    Berkeley equivalent     Error   Interpretation
  5869. ----------------------- ----------------------- ------- ----------------
  5870. WSAEINTR                EINTR                   10004   As in standard C
  5871. WSAEBADF                EBADF                   10009   As in standard C
  5872. WSEACCES                EACCES                  10013   As in standard C
  5873. WSAEFAULT               EFAULT                  10014   As in standard C
  5874. WSAEINVAL               EINVAL                  10022   As in standard C
  5875. WSAEMFILE               EMFILE                  10024   As in standard C
  5876. WSAEWOULDBLOCK          EWOULDBLOCK             10035   As in BSD
  5877. WSAEINPROGRESS          EINPROGRESS             10036   This error is returned
  5878.                                                         if any Windows Sockets
  5879.                                                         API function is called
  5880.                                                         while a blocking
  5881.                                                         function is in
  5882.                                                         progress.
  5883.  
  5884. WSAEALREADY             EALREADY                10037   As in BSD
  5885. WSAENOTSOCK             ENOTSOCK                10038   As in BSD
  5886. WSAEDESTADDRREQ         EDESTADDRREQ            10039   As in BSD
  5887. WSAEMSGSIZE             EMSGSIZE                10040   As in BSD
  5888. WSAEPROTOTYPE           EPROTOTYPE              10041   As in BSD
  5889. WSAENOPROTOOPT          ENOPROTOOPT             10042   As in BSD
  5890. WSAEPROTONOSUPPORT      EPROTONOSUPPORT         10043   As in BSD
  5891. WSAESOCKTNOSUPPORT      ESOCKTNOSUPPORT         10044   As in BSD
  5892. WSAEOPNOTSUPP           EOPNOTSUPP              10045   As in BSD
  5893. WSAEPFNOSUPPORT         EPFNOSUPPORT            10046   As in BSD
  5894. WSAEAFNOSUPPORT         EAFNOSUPPORT            10047   As in BSD
  5895. WSAEADDRINUSE           EADDRINUSE              10048   As in BSD
  5896. WSAEADDRNOTAVAIL        EADDRNOTAVAIL           10049   As in BSD
  5897. WSAENETDOWN             ENETDOWN                10050   As in BSD.  This error
  5898.                                                         may be reported at any
  5899.                                                         time if the Windows
  5900.                                                         Sockets implementation
  5901.                                                         detects an underlying
  5902.                                                         failure.
  5903. WSAENETUNREACH          ENETUNREACH             10051   As in BSD
  5904. WSAENETRESET            ENETRESET               10052   As in BSD
  5905. WSAECONNABORTED         ECONNABORTED            10053   As in BSD
  5906. WSAECONNRESET           ECONNRESET              10054   As in BSD
  5907. WSAENOBUFS              ENOBUFS                 10055   As in BSD
  5908. WSAEISCONN              EISCONN                 10056   As in BSD
  5909. WSAENOTCONN             ENOTCONN                10057   As in BSD
  5910. WSAESHUTDOWN            ESHUTDOWN               10058   As in BSD
  5911. WSAETOOMANYREFS         ETOOMANYREFS            10059   As in BSD
  5912. WSAETIMEDOUT            ETIMEDOUT               10060   As in BSD
  5913. WSAECONNREFUSED         ECONNREFUSED            10061   As in BSD
  5914. WSAELOOP                ELOOP                   10062   As in BSD
  5915. WSAENAMETOOLONG         ENAMETOOLONG            10063   As in BSD
  5916. WSAEHOSTDOWN            EHOSTDOWN               10064   As in BSD
  5917. WSAEHOSTUNREACH         EHOSTUNREACH            10065   As in BSD
  5918. WSASYSNOTREADY                                  10091   Returned by WSAStartup()
  5919.                                                         indicating that the
  5920.                                                         network subsystem is
  5921.                                                         unusable.
  5922. WSAVERNOTSUPPORTED                              10092   Returned by WSAStartup()
  5923.                                                         indicating that the
  5924.                                                         Windows Sockets DLL
  5925.                                                         cannot support this
  5926.                                                         app.
  5927. WSANOTINITIALISED                               10093   Returned by any
  5928.                                                         function except
  5929.                                                         WSAStartup()
  5930.                                                         indicating that a
  5931.                                                         successful WSAStartup()
  5932.                                                         has not yet been
  5933.                                                         performed.
  5934. WSAHOST_NOT_FOUND       HOST_NOT_FOUND          11001   As in BSD.
  5935. WSATRY_AGAIN            TRY_AGAIN               11002   As in BSD
  5936. WSANO_RECOVERY          NO_RECOVERY             11003   As in BSD
  5937. WSANO_DATA              NO_DATA                 11004   As in BSD
  5938.  
  5939. The first set of definitions is present to resolve contentions between standard 
  5940. C error codes which may be defined inconsistently between various C compilers. 
  5941.  
  5942. The second set of definitions provides Windows Sockets versions of regular 
  5943. Berkeley Sockets error codes. 
  5944.  
  5945. The third set of definitions consists of extended Windows Sockets-specific 
  5946. error codes. 
  5947.  
  5948. The fourth set of errors are returned by Windows Sockets getXbyY() and 
  5949. WSAAsyncGetXByY() functions, and correspond to the errors which in Berkeley 
  5950. software would be returned in the h_errno variable.  They correspond to various 
  5951. failures which may be returned by the Domain Name Service.  If the Windows 
  5952. Sockets implementation  does not use the DNS, it will use the most appropriate 
  5953. code.  In general, a Windows Sockets application should interpret 
  5954. WSAHOST_NOT_FOUND and WSANO_DATA as indicating that the key (name, address, 
  5955. etc.) was not found,, while WSATRY_AGAIN and WSANO_RECOVERY suggest that the 
  5956. name service itself is non-operational. 
  5957.  
  5958. The error numbers are derived from the winsock.h header file, and are based on 
  5959. the fact that Windows Sockets error numbers are computed by adding 10000 to the 
  5960. "normal" Berkeley error number. 
  5961.  
  5962. Note that this table does not include all of the error codes defined in 
  5963. winsock.h.  This is because it includes only errors which might reasonably be 
  5964. returned by a Windows Sockets implementation: winsock.h, on the other hand, 
  5965. includes a full set of BSD definitions to ensure compatibility with ported 
  5966. software. 
  5967.  
  5968.  
  5969. ΓòÉΓòÉΓòÉ 8.1.2. Header Files ΓòÉΓòÉΓòÉ
  5970.  
  5971. Berkeley Header Files 
  5972.  
  5973. Windows Sockets Header File -- winsock.h 
  5974.  
  5975.  
  5976. ΓòÉΓòÉΓòÉ 8.1.3. Berkeley Header Files ΓòÉΓòÉΓòÉ
  5977.  
  5978. A Windows Sockets supplier who provides a development kit to support the 
  5979. development of Windows Sockets applications must supply a set of vestigial 
  5980. header files with names that match a number of the header files in the Berkeley 
  5981. software distribution.  These files are provided for source code compatibility 
  5982. only, and each consists of three lines: 
  5983.  
  5984. #ifndef _WINSOCKAPI_
  5985. #include <winsock.h>
  5986. #endif
  5987.  
  5988. The header files provided for compatibility are: 
  5989.  
  5990.      netdb.h 
  5991.  
  5992.      arpa/inet.h 
  5993.  
  5994.      sys/time.h 
  5995.  
  5996.      sys/socket.h 
  5997.  
  5998.      netinet/in.h 
  5999.  
  6000.  The file winsock.h contains all of the type and structure definitions, 
  6001.  constants, macros, and function prototypes used by the Windows Sockets 
  6002.  specification.  An application writer may choose to ignore the compatibility 
  6003.  headers and include winsock.h in each source file. 
  6004.  
  6005.  
  6006. ΓòÉΓòÉΓòÉ 8.1.4. Windows Sockets Header File -- winsock.h ΓòÉΓòÉΓòÉ
  6007.  
  6008. The winsock.h header file includes a number of types and definitions from the 
  6009. standard Windows header file windows.h.  The windows.h in the Windows 3.0 SDK 
  6010. (Software Developer's Kit) lacks a #include guard, so if you need to include 
  6011. windows.h as well as winsock.h, you should define the symbol _INC_WINDOWS 
  6012. before #including winsock.h, as follows: 
  6013.  
  6014. #include <windows.h>
  6015. #define _INC_WINDOWS
  6016. #include <winsock.h>
  6017.  
  6018. Users of the SDK for Windows 3.1 and later need not do this. 
  6019.  
  6020. A Windows Sockets DLL vendor MUST NOT make any modifications to this header 
  6021. file which could impact binary compatibility of Windows Sockets applications. 
  6022. The constant values, function parameters and return codes, and the like must 
  6023. remain consistent across all Windows Sockets DLL vendors. 
  6024.  
  6025. /* WINSOCK.H--definitions to be used with the WINSOCK.DLL
  6026.  *
  6027.  * This header file corresponds to version 1.1 of the Windows Sockets specification.
  6028.  *
  6029.  * This file includes parts which are Copyright (c) 1982-1986 Regents
  6030.  * of the University of California.  All rights reserved.  The
  6031.  * Berkeley Software License Agreement specifies the terms and
  6032.  * conditions for redistribution.
  6033.  */
  6034.  
  6035. #ifndef _WINSOCKAPI_
  6036. #define _WINSOCKAPI_
  6037.  
  6038. /*
  6039.  * Pull in WINDOWS.H if necessary
  6040.  */
  6041. #ifndef _INC_WINDOWS
  6042. #include <windows.h>
  6043. #endif /* _INC_WINDOWS */
  6044.  
  6045. /*
  6046.  * Basic system type definitions, taken from the BSD file sys/types.h.
  6047.  */
  6048. typedef unsigned char   u_char;
  6049. typedef unsigned short  u_short;
  6050. typedef unsigned int    u_int;
  6051. typedef unsigned long   u_long;
  6052.  
  6053. /*
  6054.  * The new type to be used in all
  6055.  * instances which refer to sockets.
  6056.  */
  6057. typedef u_int           SOCKET;
  6058.  
  6059. /*
  6060.  * Select uses arrays of SOCKETs.  These macros manipulate such
  6061.  * arrays.  FD_SETSIZE may be defined by the user before including
  6062.  * this file, but the default here should be >= 64.
  6063.  *
  6064.  * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
  6065.  * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
  6066.  */
  6067. #ifndef FD_SETSIZE
  6068. #define FD_SETSIZE      64
  6069. #endif /* FD_SETSIZE */
  6070.  
  6071. typedef struct fd_set {
  6072.         u_short fd_count;               /* how many are SET? */
  6073.         SOCKET  fd_array╤ìFD_SETSIZEΓêÖ;   /* an array of SOCKETs */
  6074. } fd_set;
  6075.  
  6076. extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);
  6077.  
  6078. #define FD_CLR(fd, set) do { \
  6079.     u_int __i; \
  6080.     for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
  6081.         if (((fd_set FAR *)(set))->fd_array╤ì__iΓêÖ == fd) { \
  6082.             while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
  6083.                 ((fd_set FAR *)(set))->fd_array╤ì__iΓêÖ = \
  6084.                     ((fd_set FAR *)(set))->fd_array╤ì__i+1ΓêÖ; \
  6085.                 __i++; \
  6086.             } \
  6087.             ((fd_set FAR *)(set))->fd_count--; \
  6088.             break; \
  6089.         } \
  6090.     } \
  6091. } while(0)
  6092.  
  6093. #define FD_SET(fd, set) do { \
  6094.     if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
  6095.         ((fd_set FAR *)(set))->fd_array╤ì((fd_set FAR *)(set))->fd_count++ΓêÖ=fd;\
  6096. } while(0)
  6097.  
  6098. #define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
  6099.  
  6100. #define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)fd, (fd_set FAR *)set)
  6101.  
  6102. /*
  6103.  * Structure used in select() call, taken from the BSD file sys/time.h.
  6104.  */
  6105. struct timeval {
  6106.         long    tv_sec;         /* seconds */
  6107.         long    tv_usec;        /* and microseconds */
  6108. };
  6109.  
  6110. /*
  6111.  * Operations on timevals.
  6112.  *
  6113.  * NB: timercmp does not work for >= or <=.
  6114.  */
  6115. #define timerisset(tvp)         ((tvp)->tv_sec !! (tvp)->tv_usec)
  6116. #define timercmp(tvp, uvp, cmp) \
  6117.         ((tvp)->tv_sec cmp (uvp)->tv_sec !! \
  6118.          (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
  6119. #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
  6120.  
  6121. /*
  6122.  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
  6123.  *
  6124.  *
  6125.  * Ioctl's have the command encoded in the lower word,
  6126.  * and the size of any in or out parameters in the upper
  6127.  * word.  The high 2 bits of the upper word are used
  6128.  * to encode the in/out status of the parameter; for now
  6129.  * we restrict parameters to at most 128 bytes.
  6130.  */
  6131. #define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
  6132. #define IOC_VOID        0x20000000      /* no parameters */
  6133. #define IOC_OUT         0x40000000      /* copy out parameters */
  6134. #define IOC_IN          0x80000000      /* copy in parameters */
  6135. #define IOC_INOUT       (IOC_IN!IOC_OUT)
  6136.                                         /* 0x20000000 distinguishes new &
  6137.                                            old ioctl's */
  6138. #define _IO(x,y)        (IOC_VOID!(x<<8)!y)
  6139.  
  6140. #define _IOR(x,y,t)     (IOC_OUT!(((long)sizeof(t)&IOCPARM_MASK)<<16)!(x<<8)!y)
  6141.  
  6142. #define _IOW(x,y,t)     (IOC_IN!(((long)sizeof(t)&IOCPARM_MASK)<<16)!(x<<8)!y)
  6143.  
  6144. #define FIONREAD    _IOR('f', 127, u_long) /* get # bytes to read */
  6145. #define FIONBIO     _IOW('f', 126, u_long) /* set/clear non-blocking i/o */
  6146. #define FIOASYNC    _IOW('f', 125, u_long) /* set/clear async i/o */
  6147.  
  6148. /* Socket I/O Controls */
  6149. #define SIOCSHIWAT  _IOW('s',  0, u_long)  /* set high watermark */
  6150. #define SIOCGHIWAT  _IOR('s',  1, u_long)  /* get high watermark */
  6151. #define SIOCSLOWAT  _IOW('s',  2, u_long)  /* set low watermark */
  6152. #define SIOCGLOWAT  _IOR('s',  3, u_long)  /* get low watermark */
  6153. #define SIOCATMARK  _IOR('s',  7, u_long)  /* at oob mark? */
  6154.  
  6155. /*
  6156.  * Structures returned by network data base library, taken from the
  6157.  * BSD file netdb.h.  All addresses are supplied in host order, and
  6158.  * returned in network order (suitable for use in system calls).
  6159.  */
  6160.  
  6161. struct  hostent {
  6162.         char    FAR * h_name;           /* official name of host */
  6163.         char    FAR * FAR * h_aliases;  /* alias list */
  6164.         short   h_addrtype;             /* host address type */
  6165.         short   h_length;               /* length of address */
  6166.         char    FAR * FAR * h_addr_list; /* list of addresses */
  6167. #define h_addr  h_addr_list╤ì0ΓêÖ          /* address, for backward compat */
  6168. };
  6169.  
  6170. /*
  6171.  * It is assumed here that a network number
  6172.  * fits in 32 bits.
  6173.  */
  6174. struct  netent {
  6175.         char    FAR * n_name;           /* official name of net */
  6176.         char    FAR * FAR * n_aliases;  /* alias list */
  6177.         short   n_addrtype;             /* net address type */
  6178.         u_long  n_net;                  /* network # */
  6179. };
  6180.  
  6181. struct  servent {
  6182.         char    FAR * s_name;           /* official service name */
  6183.         char    FAR * FAR * s_aliases;  /* alias list */
  6184.         short   s_port;                 /* port # */
  6185.         char    FAR * s_proto;          /* protocol to use */
  6186. };
  6187.  
  6188. struct  protoent {
  6189.         char    FAR * p_name;           /* official protocol name */
  6190.         char    FAR * FAR * p_aliases;  /* alias list */
  6191.         short   p_proto;                /* protocol # */
  6192. };
  6193.  
  6194. /*
  6195.  * Constants and structures defined by the internet system,
  6196.  * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
  6197.  */
  6198.  
  6199. /*
  6200.  * Protocols
  6201.  */
  6202. #define IPPROTO_IP              0               /* dummy for IP */
  6203. #define IPPROTO_ICMP            1               /* control message protocol */
  6204. #define IPPROTO_GGP             2               /* gateway^2 (deprecated) */
  6205. #define IPPROTO_TCP             6               /* tcp */
  6206. #define IPPROTO_PUP             12              /* pup */
  6207. #define IPPROTO_UDP             17              /* user datagram protocol */
  6208. #define IPPROTO_IDP             22              /* xns idp */
  6209. #define IPPROTO_ND              77              /* UNOFFICIAL net disk proto */
  6210.  
  6211. #define IPPROTO_RAW             255             /* raw IP packet */
  6212. #define IPPROTO_MAX             256
  6213.  
  6214. /*
  6215.  * Port/socket numbers: network standard functions
  6216.  */
  6217. #define IPPORT_ECHO             7
  6218. #define IPPORT_DISCARD          9
  6219. #define IPPORT_SYSTAT           11
  6220. #define IPPORT_DAYTIME          13
  6221. #define IPPORT_NETSTAT          15
  6222. #define IPPORT_FTP              21
  6223. #define IPPORT_TELNET           23
  6224. #define IPPORT_SMTP             25
  6225. #define IPPORT_TIMESERVER       37
  6226. #define IPPORT_NAMESERVER       42
  6227. #define IPPORT_WHOIS            43
  6228. #define IPPORT_MTP              57
  6229.  
  6230. /*
  6231.  * Port/socket numbers: host specific functions
  6232.  */
  6233. #define IPPORT_TFTP             69
  6234. #define IPPORT_RJE              77
  6235. #define IPPORT_FINGER           79
  6236. #define IPPORT_TTYLINK          87
  6237. #define IPPORT_SUPDUP           95
  6238.  
  6239. /*
  6240.  * UNIX TCP sockets
  6241.  */
  6242. #define IPPORT_EXECSERVER       512
  6243. #define IPPORT_LOGINSERVER      513
  6244. #define IPPORT_CMDSERVER        514
  6245. #define IPPORT_EFSSERVER        520
  6246.  
  6247. /*
  6248.  * UNIX UDP sockets
  6249.  */
  6250. #define IPPORT_BIFFUDP          512
  6251. #define IPPORT_WHOSERVER        513
  6252. #define IPPORT_ROUTESERVER      520
  6253.                                         /* 520+1 also used */
  6254.  
  6255. /*
  6256.  * Ports < IPPORT_RESERVED are reserved for
  6257.  * privileged processes (e.g. root).
  6258.  */
  6259. #define IPPORT_RESERVED         1024
  6260.  
  6261. /*
  6262.  * Link numbers
  6263.  */
  6264. #define IMPLINK_IP              155
  6265. #define IMPLINK_LOWEXPER        156
  6266. #define IMPLINK_HIGHEXPER       158
  6267.  
  6268. /*
  6269.  * Internet address (old style... should be updated)
  6270.  */
  6271. struct in_addr {
  6272.         union {
  6273.                 struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
  6274.                 struct { u_short s_w1,s_w2; } S_un_w;
  6275.                 u_long S_addr;
  6276.         } S_un;
  6277. #define s_addr  S_un.S_addr
  6278.                                 /* can be used for most tcp & ip code */
  6279. #define s_host  S_un.S_un_b.s_b2
  6280.                                 /* host on imp */
  6281. #define s_net   S_un.S_un_b.s_b1
  6282.                                 /* network */
  6283. #define s_imp   S_un.S_un_w.s_w2
  6284.                                 /* imp */
  6285. #define s_impno S_un.S_un_b.s_b4
  6286.                                 /* imp # */
  6287. #define s_lh    S_un.S_un_b.s_b3
  6288.                                 /* logical host */
  6289. };
  6290.  
  6291. /*
  6292.  * Definitions of bits in internet address integers.
  6293.  * On subnets, the decomposition of addresses to host and net parts
  6294.  * is done according to subnet mask, not the masks here.
  6295.  */
  6296. #define IN_CLASSA(i)            (((long)(i) & 0x80000000) == 0)
  6297. #define IN_CLASSA_NET           0xff000000
  6298. #define IN_CLASSA_NSHIFT        24
  6299. #define IN_CLASSA_HOST          0x00ffffff
  6300. #define IN_CLASSA_MAX           128
  6301.  
  6302. #define IN_CLASSB(i)            (((long)(i) & 0xc0000000) == 0x80000000)
  6303. #define IN_CLASSB_NET           0xffff0000
  6304. #define IN_CLASSB_NSHIFT        16
  6305. #define IN_CLASSB_HOST          0x0000ffff
  6306. #define IN_CLASSB_MAX           65536
  6307.  
  6308. #define IN_CLASSC(i)            (((long)(i) & 0xc0000000) == 0xc0000000)
  6309. #define IN_CLASSC_NET           0xffffff00
  6310. #define IN_CLASSC_NSHIFT        8
  6311. #define IN_CLASSC_HOST          0x000000ff
  6312.  
  6313. #define INADDR_ANY              (u_long)0x00000000
  6314. #define INADDR_LOOPBACK         0x7f000001
  6315. #define INADDR_BROADCAST        (u_long)0xffffffff
  6316. #define INADDR_NONE             0xffffffff
  6317.  
  6318. /*
  6319.  * Socket address, internet style.
  6320.  */
  6321. struct sockaddr_in {
  6322.         short   sin_family;
  6323.         u_short sin_port;
  6324.         struct  in_addr sin_addr;
  6325.         char    sin_zero╤ì8ΓêÖ;
  6326. };
  6327.  
  6328. #define WSADESCRIPTION_LEN      256
  6329. #define WSASYS_STATUS_LEN       128
  6330.  
  6331. typedef struct WSAData {
  6332.         WORD                    wVersion;
  6333.         WORD                    wHighVersion;
  6334.         char                    szDescription╤ìWSADESCRIPTION_LEN+1ΓêÖ;
  6335.         char                    szSystemStatus╤ìWSASYS_STATUS_LEN+1ΓêÖ;
  6336.         unsigned short          iMaxSockets;
  6337.         unsigned short          iMaxUdpDg;
  6338.         char FAR *              lpVendorInfo;
  6339. } WSADATA;
  6340.  
  6341. typedef WSADATA FAR *LPWSADATA;
  6342.  
  6343. /*
  6344.  * Options for use with ╤ìgsΓêÖetsockopt at the IP level.
  6345.  */
  6346. #define IP_OPTIONS      1               /* set/get IP per-packet options */
  6347.  
  6348. /*
  6349.  * Definitions related to sockets: types, address families, options,
  6350.  * taken from the BSD file sys/socket.h.
  6351.  */
  6352.  
  6353. /*
  6354.  * This is used instead of -1, since the
  6355.  * SOCKET type is unsigned.
  6356.  */
  6357. #define INVALID_SOCKET  (SOCKET)(~0)
  6358. #define SOCKET_ERROR            (-1)
  6359.  
  6360. /*
  6361.  * Types
  6362.  */
  6363. #define SOCK_STREAM     1               /* stream socket */
  6364. #define SOCK_DGRAM      2               /* datagram socket */
  6365. #define SOCK_RAW        3               /* raw-protocol interface */
  6366. #define SOCK_RDM        4               /* reliably-delivered message */
  6367. #define SOCK_SEQPACKET  5               /* sequenced packet stream */
  6368.  
  6369. /*
  6370.  * Option flags per-socket.
  6371.  */
  6372. #define SO_DEBUG        0x0001          /* turn on debugging info recording */
  6373. #define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
  6374. #define SO_REUSEADDR    0x0004          /* allow local address reuse */
  6375. #define SO_KEEPALIVE    0x0008          /* keep connections alive */
  6376. #define SO_DONTROUTE    0x0010          /* just use interface addresses */
  6377. #define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
  6378. #define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
  6379. #define SO_LINGER       0x0080          /* linger on close if data present */
  6380. #define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
  6381.  
  6382. #define SO_DONTLINGER   (u_int)(~SO_LINGER)
  6383.  
  6384. /*
  6385.  * Additional options.
  6386.  */
  6387. #define SO_SNDBUF       0x1001          /* send buffer size */
  6388. #define SO_RCVBUF       0x1002          /* receive buffer size */
  6389. #define SO_SNDLOWAT     0x1003          /* send low-water mark */
  6390. #define SO_RCVLOWAT     0x1004          /* receive low-water mark */
  6391. #define SO_SNDTIMEO     0x1005          /* send timeout */
  6392. #define SO_RCVTIMEO     0x1006          /* receive timeout */
  6393. #define SO_ERROR        0x1007          /* get error status and clear */
  6394. #define SO_TYPE         0x1008          /* get socket type */
  6395.  
  6396. /*
  6397.  * TCP options.
  6398.  */
  6399. #define TCP_NODELAY     0x0001
  6400.  
  6401. /*
  6402.  * Address families.
  6403.  */
  6404. #define AF_UNSPEC       0               /* unspecified */
  6405. #define AF_UNIX         1               /* local to host (pipes, portals) */
  6406. #define AF_INET         2               /* internetwork: UDP, TCP, etc. */
  6407. #define AF_IMPLINK      3               /* arpanet imp addresses */
  6408. #define AF_PUP          4               /* pup protocols: e.g. BSP */
  6409. #define AF_CHAOS        5               /* mit CHAOS protocols */
  6410. #define AF_NS           6               /* XEROX NS protocols */
  6411. #define AF_ISO          7               /* ISO protocols */
  6412. #define AF_OSI          AF_ISO          /* OSI is ISO */
  6413. #define AF_ECMA         8               /* european computer manufacturers */
  6414. #define AF_DATAKIT      9               /* datakit protocols */
  6415. #define AF_CCITT        10              /* CCITT protocols, X.25 etc */
  6416. #define AF_SNA          11              /* IBM SNA */
  6417. #define AF_DECnet       12              /* DECnet */
  6418. #define AF_DLI          13              /* Direct data link interface */
  6419. #define AF_LAT          14              /* LAT */
  6420. #define AF_HYLINK       15              /* NSC Hyperchannel */
  6421. #define AF_APPLETALK    16              /* AppleTalk */
  6422. #define AF_NETBIOS      17              /* NetBios-style addresses */
  6423.  
  6424. #define AF_MAX          18
  6425.  
  6426. /*
  6427.  * Structure used by kernel to store most
  6428.  * addresses.
  6429.  */
  6430. struct sockaddr {
  6431.         u_short sa_family;              /* address family */
  6432.         char    sa_data╤ì14ΓêÖ;            /* up to 14 bytes of direct address */
  6433. };
  6434.  
  6435. /*
  6436.  * Structure used by kernel to pass protocol
  6437.  * information in raw sockets.
  6438.  */
  6439. struct sockproto {
  6440.         u_short sp_family;              /* address family */
  6441.         u_short sp_protocol;            /* protocol */
  6442. };
  6443.  
  6444. /*
  6445.  * Protocol families, same as address families for now.
  6446.  */
  6447. #define PF_UNSPEC       AF_UNSPEC
  6448. #define PF_UNIX         AF_UNIX
  6449. #define PF_INET         AF_INET
  6450. #define PF_IMPLINK      AF_IMPLINK
  6451. #define PF_PUP          AF_PUP
  6452. #define PF_CHAOS        AF_CHAOS
  6453. #define PF_NS           AF_NS
  6454. #define PF_ISO          AF_ISO
  6455. #define PF_OSI          AF_OSI
  6456. #define PF_ECMA         AF_ECMA
  6457. #define PF_DATAKIT      AF_DATAKIT
  6458. #define PF_CCITT        AF_CCITT
  6459. #define PF_SNA          AF_SNA
  6460. #define PF_DECnet       AF_DECnet
  6461. #define PF_DLI          AF_DLI
  6462. #define PF_LAT          AF_LAT
  6463. #define PF_HYLINK       AF_HYLINK
  6464. #define PF_APPLETALK    AF_APPLETALK
  6465.  
  6466. #define PF_MAX          AF_MAX
  6467.  
  6468. /*
  6469.  * Structure used for manipulating linger option.
  6470.  */
  6471. struct  linger {
  6472.         u_short l_onoff;                /* option on/off */
  6473.         u_short l_linger;               /* linger time */
  6474. };
  6475.  
  6476. /*
  6477.  * Level number for (get/set)sockopt() to apply to socket itself.
  6478.  */
  6479. #define SOL_SOCKET      0xffff          /* options for socket level */
  6480.  
  6481. /*
  6482.  * Maximum queue length specifiable by listen.
  6483.  */
  6484. #define SOMAXCONN       5
  6485.  
  6486. #define MSG_OOB         0x1             /* process out-of-band data */
  6487. #define MSG_PEEK        0x2             /* peek at incoming message */
  6488. #define MSG_DONTROUTE   0x4             /* send without using routing tables */
  6489.  
  6490. #define MSG_MAXIOVLEN   16
  6491.  
  6492. /*
  6493.  * Define constant based on rfc883, used by gethostbyxxxx() calls.
  6494.  */
  6495. #define MAXGETHOSTSTRUCT        1024
  6496.  
  6497. /*
  6498.  * Define flags to be used with the WSAAsyncSelect() call.
  6499.  */
  6500. #define FD_READ         0x01
  6501. #define FD_WRITE        0x02
  6502. #define FD_OOB          0x04
  6503. #define FD_ACCEPT       0x08
  6504. #define FD_CONNECT      0x10
  6505. #define FD_CLOSE        0x20
  6506.  
  6507. /*
  6508.  * All Windows Sockets error constants are biased by WSABASEERR from
  6509.  * the "normal"
  6510.  */
  6511. #define WSABASEERR              10000
  6512. /*
  6513.  * Windows Sockets definitions of regular Microsoft C error constants
  6514.  */
  6515. #define WSAEINTR                (WSABASEERR+4)
  6516. #define WSAEBADF                (WSABASEERR+9)
  6517. #define WSAEACCES               (WSABASEERR+13)
  6518. #define WSAEFAULT               (WSABASEERR+14)
  6519. #define WSAEINVAL               (WSABASEERR+22)
  6520. #define WSAEMFILE               (WSABASEERR+24)
  6521.  
  6522. /*
  6523.  * Windows Sockets definitions of regular Berkeley error constants
  6524.  */
  6525. #define WSAEWOULDBLOCK          (WSABASEERR+35)
  6526. #define WSAEINPROGRESS          (WSABASEERR+36)
  6527. #define WSAEALREADY             (WSABASEERR+37)
  6528. #define WSAENOTSOCK             (WSABASEERR+38)
  6529. #define WSAEDESTADDRREQ         (WSABASEERR+39)
  6530. #define WSAEMSGSIZE             (WSABASEERR+40)
  6531. #define WSAEPROTOTYPE           (WSABASEERR+41)
  6532. #define WSAENOPROTOOPT          (WSABASEERR+42)
  6533. #define WSAEPROTONOSUPPORT      (WSABASEERR+43)
  6534. #define WSAESOCKTNOSUPPORT      (WSABASEERR+44)
  6535. #define WSAEOPNOTSUPP           (WSABASEERR+45)
  6536. #define WSAEPFNOSUPPORT         (WSABASEERR+46)
  6537. #define WSAEAFNOSUPPORT         (WSABASEERR+47)
  6538. #define WSAEADDRINUSE           (WSABASEERR+48)
  6539. #define WSAEADDRNOTAVAIL        (WSABASEERR+49)
  6540. #define WSAENETDOWN             (WSABASEERR+50)
  6541. #define WSAENETUNREACH          (WSABASEERR+51)
  6542. #define WSAENETRESET            (WSABASEERR+52)
  6543. #define WSAECONNABORTED         (WSABASEERR+53)
  6544. #define WSAECONNRESET           (WSABASEERR+54)
  6545. #define WSAENOBUFS              (WSABASEERR+55)
  6546. #define WSAEISCONN              (WSABASEERR+56)
  6547. #define WSAENOTCONN             (WSABASEERR+57)
  6548. #define WSAESHUTDOWN            (WSABASEERR+58)
  6549. #define WSAETOOMANYREFS         (WSABASEERR+59)
  6550. #define WSAETIMEDOUT            (WSABASEERR+60)
  6551. #define WSAECONNREFUSED         (WSABASEERR+61)
  6552. #define WSAELOOP                (WSABASEERR+62)
  6553. #define WSAENAMETOOLONG         (WSABASEERR+63)
  6554. #define WSAEHOSTDOWN            (WSABASEERR+64)
  6555. #define WSAEHOSTUNREACH         (WSABASEERR+65)
  6556. #define WSAENOTEMPTY            (WSABASEERR+66)
  6557. #define WSAEPROCLIM             (WSABASEERR+67)
  6558. #define WSAEUSERS               (WSABASEERR+68)
  6559. #define WSAEDQUOT               (WSABASEERR+69)
  6560. #define WSAESTALE               (WSABASEERR+70)
  6561. #define WSAEREMOTE              (WSABASEERR+71)
  6562.  
  6563. /*
  6564.  * Extended Windows Sockets error constant definitions
  6565.  */
  6566. #define WSASYSNOTREADY          (WSABASEERR+91)
  6567. #define WSAVERNOTSUPPORTED      (WSABASEERR+92)
  6568. #define WSANOTINITIALISED       (WSABASEERR+93)
  6569.  
  6570. /*
  6571.  * Error return codes from gethostbyname() and gethostbyaddr()
  6572.  * (when using the resolver). Note that these errors are
  6573.  * retrieved via WSAGetLastError() and must therefore follow
  6574.  * the rules for avoiding clashes with error numbers from
  6575.  * specific implementations or language run-time systems.
  6576.  * For this reason the codes are based at WSABASEERR+1001.
  6577.  * Note also that ╤ìWSAΓêÖNO_ADDRESS is defined only for
  6578.  * compatibility purposes.
  6579.  */
  6580.  
  6581. #define h_errno         WSAGetLastError()
  6582.  
  6583. /* Authoritative Answer: Host not found */
  6584. #define WSAHOST_NOT_FOUND       (WSABASEERR+1001)
  6585. #define HOST_NOT_FOUND          WSAHOST_NOT_FOUND
  6586.  
  6587. /* Non-Authoritative: Host not found, or SERVERFAIL */
  6588. #define WSATRY_AGAIN            (WSABASEERR+1002)
  6589. #define TRY_AGAIN               WSATRY_AGAIN
  6590.  
  6591. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  6592. #define WSANO_RECOVERY          (WSABASEERR+1003)
  6593. #define NO_RECOVERY             WSANO_RECOVERY
  6594.  
  6595. /* Valid name, no data record of requested type */
  6596. #define WSANO_DATA              (WSABASEERR+1004)
  6597. #define NO_DATA                 WSANO_DATA
  6598.  
  6599. /* no address, look for MX record */
  6600. #define WSANO_ADDRESS           WSANO_DATA
  6601. #define NO_ADDRESS              WSANO_ADDRESS
  6602.  
  6603. /*
  6604.  * Windows Sockets errors redefined as regular Berkeley error constants
  6605.  */
  6606. #define EWOULDBLOCK             WSAEWOULDBLOCK
  6607. #define EINPROGRESS             WSAEINPROGRESS
  6608. #define EALREADY                WSAEALREADY
  6609. #define ENOTSOCK                WSAENOTSOCK
  6610. #define EDESTADDRREQ            WSAEDESTADDRREQ
  6611. #define EMSGSIZE                WSAEMSGSIZE
  6612. #define EPROTOTYPE              WSAEPROTOTYPE
  6613. #define ENOPROTOOPT             WSAENOPROTOOPT
  6614. #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
  6615. #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
  6616. #define EOPNOTSUPP              WSAEOPNOTSUPP
  6617. #define EPFNOSUPPORT            WSAEPFNOSUPPORT
  6618. #define EAFNOSUPPORT            WSAEAFNOSUPPORT
  6619. #define EADDRINUSE              WSAEADDRINUSE
  6620. #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
  6621. #define ENETDOWN                WSAENETDOWN
  6622. #define ENETUNREACH             WSAENETUNREACH
  6623. #define ENETRESET               WSAENETRESET
  6624. #define ECONNABORTED            WSAECONNABORTED
  6625. #define ECONNRESET              WSAECONNRESET
  6626. #define ENOBUFS                 WSAENOBUFS
  6627. #define EISCONN                 WSAEISCONN
  6628. #define ENOTCONN                WSAENOTCONN
  6629. #define ESHUTDOWN               WSAESHUTDOWN
  6630. #define ETOOMANYREFS            WSAETOOMANYREFS
  6631. #define ETIMEDOUT               WSAETIMEDOUT
  6632. #define ECONNREFUSED            WSAECONNREFUSED
  6633. #define ELOOP                   WSAELOOP
  6634. #define ENAMETOOLONG            WSAENAMETOOLONG
  6635. #define EHOSTDOWN               WSAEHOSTDOWN
  6636. #define EHOSTUNREACH            WSAEHOSTUNREACH
  6637. #define ENOTEMPTY               WSAENOTEMPTY
  6638. #define EPROCLIM                WSAEPROCLIM
  6639. #define EUSERS                  WSAEUSERS
  6640. #define EDQUOT                  WSAEDQUOT
  6641. #define ESTALE                  WSAESTALE
  6642. #define EREMOTE                 WSAEREMOTE
  6643.  
  6644. /* Socket function prototypes */
  6645.  
  6646. #ifdef __cplusplus
  6647. extern "C" {
  6648. #endif
  6649.  
  6650. SOCKET PASCAL FAR accept (SOCKET s, struct sockaddr FAR *addr,
  6651.                           int FAR *addrlen);
  6652.  
  6653. int PASCAL FAR bind (SOCKET s, const struct sockaddr FAR *addr, int namelen);
  6654.  
  6655. int PASCAL FAR closesocket (SOCKET s);
  6656.  
  6657. int PASCAL FAR connect (SOCKET s, const struct sockaddr FAR *name, int namelen);
  6658.  
  6659. int PASCAL FAR ioctlsocket (SOCKET s, long cmd, u_long FAR *argp);
  6660.  
  6661. int PASCAL FAR getpeername (SOCKET s, struct sockaddr FAR *name,
  6662.                             int FAR * namelen);
  6663.  
  6664. int PASCAL FAR getsockname (SOCKET s, struct sockaddr FAR *name,
  6665.                             int FAR * namelen);
  6666.  
  6667. int PASCAL FAR getsockopt (SOCKET s, int level, int optname,
  6668.                            char FAR * optval, int FAR *optlen);
  6669.  
  6670. u_long PASCAL FAR htonl (u_long hostlong);
  6671.  
  6672. u_short PASCAL FAR htons (u_short hostshort);
  6673.  
  6674. unsigned long PASCAL FAR inet_addr (const char FAR * cp);
  6675.  
  6676. char FAR * PASCAL FAR inet_ntoa (struct in_addr in);
  6677.  
  6678. int PASCAL FAR listen (SOCKET s, int backlog);
  6679.  
  6680. u_long PASCAL FAR ntohl (u_long netlong);
  6681.  
  6682. u_short PASCAL FAR ntohs (u_short netshort);
  6683.  
  6684. int PASCAL FAR recv (SOCKET s, char FAR * buf, int len, int flags);
  6685.  
  6686. int PASCAL FAR recvfrom (SOCKET s, char FAR * buf, int len, int flags,
  6687.                          struct sockaddr FAR *from, int FAR * fromlen);
  6688.  
  6689. int PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set FAR *writefds,
  6690.                        fd_set FAR *exceptfds, const struct timeval FAR *timeout);
  6691.  
  6692. int PASCAL FAR send (SOCKET s, const char FAR * buf, int len, int flags);
  6693.  
  6694. int PASCAL FAR sendto (SOCKET s, const char FAR * buf, int len, int flags,
  6695.                        const struct sockaddr FAR *to, int tolen);
  6696.  
  6697. int PASCAL FAR setsockopt (SOCKET s, int level, int optname,
  6698.                            const char FAR * optval, int optlen);
  6699.  
  6700. int PASCAL FAR shutdown (SOCKET s, int how);
  6701.  
  6702. SOCKET PASCAL FAR socket (int af, int type, int protocol);
  6703.  
  6704. /* Database function prototypes */
  6705.  
  6706. struct hostent FAR * PASCAL FAR gethostbyaddr(const char FAR * addr,
  6707.                                               int len, int type);
  6708.  
  6709. struct hostent FAR * PASCAL FAR gethostbyname(const char FAR * name);
  6710.  
  6711. int PASCAL FAR gethostname (char FAR * name, int namelen);
  6712.  
  6713. struct servent FAR * PASCAL FAR getservbyport(int port, const char FAR * proto);
  6714.  
  6715. struct servent FAR * PASCAL FAR getservbyname(const char FAR * name,
  6716.                                               const char FAR * proto);
  6717.  
  6718. struct protoent FAR * PASCAL FAR getprotobynumber(int proto);
  6719.  
  6720. struct protoent FAR * PASCAL FAR getprotobyname(const char FAR * name);
  6721.  
  6722. /* Microsoft Windows Extension function prototypes */
  6723.  
  6724. int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
  6725.  
  6726. int PASCAL FAR WSACleanup(void);
  6727.  
  6728. void PASCAL FAR WSASetLastError(int iError);
  6729.  
  6730. int PASCAL FAR WSAGetLastError(void);
  6731.  
  6732. BOOL PASCAL FAR WSAIsBlocking(void);
  6733.  
  6734. int PASCAL FAR WSAUnhookBlockingHook(void);
  6735.  
  6736. FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc);
  6737.  
  6738. int PASCAL FAR WSACancelBlockingCall(void);
  6739.  
  6740. HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
  6741.                                         const char FAR * name,
  6742.                                         const char FAR * proto,
  6743.                                         char FAR * buf, int buflen);
  6744.  
  6745. HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
  6746.                                         const char FAR * proto, char FAR * buf,
  6747.                                         int buflen);
  6748.  
  6749. HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
  6750.                                          const char FAR * name, char FAR * buf,
  6751.                                          int buflen);
  6752.  
  6753. HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
  6754.                                            int number, char FAR * buf,
  6755.                                            int buflen);
  6756.  
  6757. HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
  6758.                                         const char FAR * name, char FAR * buf,
  6759.                                         int buflen);
  6760.  
  6761. HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
  6762.                                         const char FAR * addr, int len, int type,
  6763.                                         const char FAR * buf, int buflen);
  6764.  
  6765. int PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
  6766.  
  6767. int PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
  6768.                                long lEvent);
  6769.  
  6770. #ifdef __cplusplus
  6771. }
  6772. #endif
  6773.  
  6774. /* Microsoft Windows Extended data types */
  6775. typedef struct sockaddr SOCKADDR;
  6776. typedef struct sockaddr *PSOCKADDR;
  6777. typedef struct sockaddr FAR *LPSOCKADDR;
  6778.  
  6779. typedef struct sockaddr_in SOCKADDR_IN;
  6780. typedef struct sockaddr_in *PSOCKADDR_IN;
  6781. typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
  6782.  
  6783. typedef struct linger LINGER;
  6784. typedef struct linger *PLINGER;
  6785. typedef struct linger FAR *LPLINGER;
  6786.  
  6787. typedef struct in_addr IN_ADDR;
  6788. typedef struct in_addr *PIN_ADDR;
  6789. typedef struct in_addr FAR *LPIN_ADDR;
  6790.  
  6791. typedef struct fd_set FD_SET;
  6792. typedef struct fd_set *PFD_SET;
  6793. typedef struct fd_set FAR *LPFD_SET;
  6794.  
  6795. typedef struct hostent HOSTENT;
  6796. typedef struct hostent *PHOSTENT;
  6797. typedef struct hostent FAR *LPHOSTENT;
  6798.  
  6799. typedef struct servent SERVENT;
  6800. typedef struct servent *PSERVENT;
  6801. typedef struct servent FAR *LPSERVENT;
  6802.  
  6803. typedef struct protoent PROTOENT;
  6804. typedef struct protoent *PPROTOENT;
  6805. typedef struct protoent FAR *LPPROTOENT;
  6806.  
  6807. typedef struct timeval TIMEVAL;
  6808. typedef struct timeval *PTIMEVAL;
  6809. typedef struct timeval FAR *LPTIMEVAL;
  6810.  
  6811. /*
  6812.  * Windows message parameter composition and decomposition
  6813.  * macros.
  6814.  *
  6815.  * WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
  6816.  * when constructing the response to a WSAAsyncGetXByY() routine.
  6817.  */
  6818. #define WSAMAKEASYNCREPLY(buflen,error)     MAKELONG(buflen,error)
  6819. /*
  6820.  * WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
  6821.  * when constructing the response to WSAAsyncSelect().
  6822.  */
  6823. #define WSAMAKESELECTREPLY(event,error)     MAKELONG(event,error)
  6824. /*
  6825.  * WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
  6826.  * to extract the buffer length from the lParam in the response
  6827.  * to a WSAGetXByY().
  6828.  */
  6829. #define WSAGETASYNCBUFLEN(lParam)           LOWORD(lParam)
  6830. /*
  6831.  * WSAGETASYNCERROR is intended for use by the Windows Sockets application
  6832.  * to extract the error code from the lParam in the response
  6833.  * to a WSAGetXByY().
  6834.  */
  6835. #define WSAGETASYNCERROR(lParam)            HIWORD(lParam)
  6836. /*
  6837.  * WSAGETSELECTEVENT is intended for use by the Windows Sockets application
  6838.  * to extract the event code from the lParam in the response
  6839.  * to a WSAAsyncSelect().
  6840.  */
  6841. #define WSAGETSELECTEVENT(lParam)           LOWORD(lParam)
  6842. /*
  6843.  * WSAGETSELECTERROR is intended for use by the Windows Sockets application
  6844.  * to extract the error code from the lParam in the response
  6845.  * to a WSAAsyncSelect().
  6846.  */
  6847. #define WSAGETSELECTERROR(lParam)           HIWORD(lParam)
  6848.  
  6849. #endif  /* _WINSOCKAPI_ */
  6850.  
  6851.  
  6852. ΓòÉΓòÉΓòÉ 8.2. Notes for Windows Sockets Suppliers ΓòÉΓòÉΓòÉ
  6853.  
  6854. Introduction 
  6855.  
  6856. Windows Sockets Components 
  6857.  
  6858. Multithreadedness and blocking routines. 
  6859.  
  6860. Database Files 
  6861.  
  6862. FD_ISSET 
  6863.  
  6864. Error Codes 
  6865.  
  6866. DLL Ordinal Numbers 
  6867.  
  6868. Validation Suite 
  6869.  
  6870.  
  6871. ΓòÉΓòÉΓòÉ 8.2.1. Introduction ΓòÉΓòÉΓòÉ
  6872.  
  6873. A Windows Sockets implementation must implement ALL the functionality described 
  6874. in the Windows Sockets documentation.  Validation of compliance is discussed in 
  6875. Validation Suite. 
  6876.  
  6877. Windows Sockets Version 1.1 implementations must support both TCP and UDP type 
  6878. sockets.  An implementation may support raw sockets (of type SOCK_RAW), but 
  6879. their use is deprecated. 
  6880.  
  6881. Certain APIs documented above have special notes for Windows Sockets 
  6882. implementors.  A Windows Sockets implementation should pay special attention to 
  6883. conforming to the API as documented.  The Special Notes are provided for 
  6884. assistance and clarification. 
  6885.  
  6886.  
  6887. ΓòÉΓòÉΓòÉ 8.2.2. Windows Sockets Components ΓòÉΓòÉΓòÉ
  6888.  
  6889.  
  6890. ΓòÉΓòÉΓòÉ 8.2.3. Development Components ΓòÉΓòÉΓòÉ
  6891.  
  6892. The Windows Sockets development components for use by Windows Sockets 
  6893. application developers will be provided by each Windows Sockets supplier. These 
  6894. Windows Sockets development components are: 
  6895.  
  6896. Component                 Description
  6897.  
  6898. ------------------------------- -----------------------------------------------
  6899. Windows Sockets Documentation   This document
  6900.  
  6901.  
  6902. WINSOCK.LIB file                Windows Sockets API Import Library
  6903.  
  6904. WINSOCK.H file                  Windows Sockets Header File
  6905.  
  6906.  
  6907. NETDB.H file                    Berkeley Compatible Header File
  6908.  
  6909. ARPA/INET.H file                Berkeley Compatible Header File
  6910.  
  6911.  
  6912. SYS/TIME.H file                 Berkeley Compatible Header File
  6913.  
  6914. SYS/SOCKET.H file               Berkeley Compatible Header File
  6915.  
  6916.  
  6917. NETINET/IN.H file               Berkeley Compatible Header File
  6918.  
  6919.  
  6920. ΓòÉΓòÉΓòÉ 8.2.4. Run Time Components ΓòÉΓòÉΓòÉ
  6921.  
  6922. The run time component provided by each Windows Sockets supplier is: 
  6923.  
  6924. Component                 Description
  6925.  
  6926. ------------------------------- -----------------------------------------------
  6927. WINSOCK.DLL                     The Windows Sockets API implementation DLL
  6928.  
  6929.  
  6930. ΓòÉΓòÉΓòÉ 8.2.5. Multithreadedness and blocking routines. ΓòÉΓòÉΓòÉ
  6931.  
  6932. Data areas returned by, for example, the getXbyY() routines MUST be on a per 
  6933. thread basis. 
  6934.  
  6935. Note that an application MUST be prevented from making multiple nested Windows 
  6936. Sockets function calls.  Only one outstanding function call will be allowed for 
  6937. a particular task.  Any Windows Sockets call performed when an existing 
  6938. blocking call is already outstanding will fail with an error code of 
  6939. WSAEINPROGRESS.  There are two exceptions to this restriction: 
  6940. WSACancelBlockingCall() and WSAIsBlocking() may be called at any time.  Windows 
  6941. Sockets suppliers should note that although preliminary drafts of this 
  6942. specification indicated that the restriction only applied to blocking function 
  6943. calls, and that it would be permissible to make non-blocking calls while a 
  6944. blocking call was in progress, this is no longer true. 
  6945.  
  6946. Regarding the implementation of blocking routines, the solution in Windows 
  6947. Sockets is to simulate the blocking mechanism by having each routine call 
  6948. PeekMessage() as it waits for the completion of its operation.  In anticipation 
  6949. of this, the function WSASetBlockingHook() is provided to allow the programmer 
  6950. to define a special routine to be called instead of the default PeekMessage() 
  6951. loop.  The blocking hook functions are discussed in more detail in 
  6952. WSASetBlockingHook(). 
  6953.  
  6954.  
  6955. ΓòÉΓòÉΓòÉ 8.2.6. Database Files ΓòÉΓòÉΓòÉ
  6956.  
  6957. The database routines in the getXbyY() family (gethostbyaddr(), etc.) were 
  6958. originally designed (in the first Berkeley UNIX releases) as mechanisms for 
  6959. looking up information in text databases.  A Windows Sockets supplier may 
  6960. choose to employ local files OR a name service to provide some or all of this 
  6961. information.  If local files exist, the format of the files must be identical 
  6962. to that used in BSD UNIX, allowing for the differences in text file formats. 
  6963.  
  6964.  
  6965. ΓòÉΓòÉΓòÉ 8.2.7. FD_ISSET ΓòÉΓòÉΓòÉ
  6966.  
  6967. It is necessary to implement the FD_ISSET Berkeley macro using a supporting 
  6968. function: __WSAFDIsSet().  It is the responsibility of a Windows Sockets 
  6969. implementation to make this available as part of the Windows Sockets API. 
  6970. Unlike the other functions exported by a Windows Sockets DLL, however, this 
  6971. function is not intended to be invoked directly by Windows Sockets 
  6972. applications: it should be used only to support the FD_ISSET macro.  The source 
  6973. code for this function is listed below: 
  6974.  
  6975. int FAR
  6976. __WSAFDIsSet(SOCKET fd, fd_set FAR *set)
  6977. {
  6978.     int i = set->count;
  6979.  
  6980.     while (i--)
  6981.         if (set->fd_array╤ìiΓêÖ == fd)
  6982.             return 1;
  6983.  
  6984.     return 0;
  6985. }
  6986.  
  6987.  
  6988. ΓòÉΓòÉΓòÉ 8.2.8. Error Codes ΓòÉΓòÉΓòÉ
  6989.  
  6990. In order to avoid conflict between various compiler environments Windows 
  6991. Sockets implementations MUST return the error codes listed in the API 
  6992. specification, using the manifest constants beginning with "WSA".  The 
  6993. Berkeley-compatible error code definitions are provided solely for 
  6994. compatibility purposes for applications which are being ported from other 
  6995. platforms. 
  6996.  
  6997.  
  6998. ΓòÉΓòÉΓòÉ 8.2.9. DLL Ordinal Numbers ΓòÉΓòÉΓòÉ
  6999.  
  7000. The winsock.def file for use by every Windows Sockets implementation is as 
  7001. follows.  Ordinal values starting at 1000 are reserved for Windows Sockets 
  7002. implementors to use for exporting private interfaces to their DLLs.  A Windows 
  7003. Sockets implementation must not use any ordinals 999 and below except for those 
  7004. APIs listed below.  An application which wishes to work with any Windows 
  7005. Sockets DLL must use only those routines listed below; using a private export 
  7006. makes an application dependent on a particular Windows Sockets implementation. 
  7007.  
  7008. ;
  7009. ;         File: winsock.def
  7010. ;       System: MS-Windows 3.x
  7011. ;      Summary: Module definition file for Windows Sockets DLL.
  7012. ;
  7013.  
  7014. LIBRARY         WINSOCK         ; Application's module name
  7015.  
  7016. DESCRIPTION     'BSD Socket API for Windows'
  7017.  
  7018. EXETYPE         WINDOWS         ; required for all windows applications
  7019.  
  7020. STUB            'WINSTUB.EXE'   ; generates error message if application
  7021.                                 ; is run without Windows
  7022.  
  7023. ;CODE can be FIXED in memory because of potential upcalls
  7024. CODE            PRELOAD         FIXED
  7025.  
  7026. ;DATA must be SINGLE and at a FIXED location since this is a DLL
  7027. DATA            PRELOAD         FIXED           SINGLE
  7028.  
  7029. HEAPSIZE        1024
  7030. STACKSIZE       16384
  7031.  
  7032. ; All functions that will be called by any Windows routine
  7033. ; must be exported.  Any additional exports beyond those defined
  7034. ; here must have ordinal numbers 1000 or above.
  7035.  
  7036. EXPORTS
  7037.         accept                         @1
  7038.         bind                           @2
  7039.         closesocket                    @3
  7040.         connect                        @4
  7041.         getpeername                    @5
  7042.         getsockname                    @6
  7043.         getsockopt                     @7
  7044.         htonl                          @8
  7045.         htons                          @9
  7046.         inet_addr                      @10
  7047.         inet_ntoa                      @11
  7048.         ioctlsocket                    @12
  7049.         listen                         @13
  7050.         ntohl                          @14
  7051.         ntohs                          @15
  7052.         recv                           @16
  7053.         recvfrom                       @17
  7054.         select                         @18
  7055.         send                           @19
  7056.         sendto                         @20
  7057.         setsockopt                     @21
  7058.         shutdown                       @22
  7059.         socket                         @23
  7060.  
  7061.         gethostbyaddr                  @51
  7062.         gethostbyname                  @52
  7063.         getprotobyname                 @53
  7064.         getprotobynumber               @54
  7065.         getservbyname                  @55
  7066.         getservbyport                  @56
  7067.         gethostname                    @57
  7068.  
  7069.         WSAAsyncSelect                 @101
  7070.         WSAAsyncGetHostByAddr          @102
  7071.         WSAAsyncGetHostByName          @103
  7072.         WSAAsyncGetProtoByNumber       @104
  7073.         WSAAsyncGetProtoByName         @105
  7074.         WSAAsyncGetServByPort          @106
  7075.         WSAAsyncGetServByName          @107
  7076.         WSACancelAsyncRequest          @108
  7077.         WSASetBlockingHook             @109
  7078.         WSAUnhookBlockingHook          @110
  7079.         WSAGetLastError                @111
  7080.         WSASetLastError                @112
  7081.         WSACancelBlockingCall          @113
  7082.         WSAIsBlocking                  @114
  7083.         WSAStartup                     @115
  7084.         WSACleanup                     @116
  7085.  
  7086.         __WSAFDIsSet                   @151
  7087.  
  7088.         WEP                            @500    RESIDENTNAME
  7089.  
  7090. ;eof
  7091.  
  7092.  
  7093. ΓòÉΓòÉΓòÉ 8.2.10. Validation Suite ΓòÉΓòÉΓòÉ
  7094.  
  7095. The Windows Sockets API Tester (WSAT) to ensure Windows Sockets compatibility 
  7096. between Windows Sockets DLL implementations is currently in beta test.  This 
  7097. beta version includes functionality testing of the Windows Sockets interface 
  7098. and is supported by a comprehensive scripting language.  The final version of 
  7099. WSAT will be available in Spring 1993.  If you wish to receive the tester or 
  7100. more information on the beta, send email to wsat@microsoft.com. 
  7101.  
  7102.  
  7103. ΓòÉΓòÉΓòÉ 8.3. For Further Reference ΓòÉΓòÉΓòÉ
  7104.  
  7105. This specification is intended to cover the Windows Sockets interface to TCP/IP 
  7106. in detail.  Many details of TCP/IP and Windows, however, are intentionally 
  7107. omitted in the interest of brevity, and this specification often assumes 
  7108. background knowledge of these topics.  For more information, the following 
  7109. references may be helpful: 
  7110.  
  7111. Braden, R.[1989], RFC 1122, Requirements for Internet Hosts--Communication 
  7112. Layers, Internet Engineering Task Force. 
  7113.  
  7114. Comer, D. [1991], Internetworking with TCP/IP Volume I: Principles, Protocols, 
  7115. and Architecture, Prentice Hall, Englewood Cliffs, New Jersey. 
  7116.  
  7117. Comer, D. and Stevens, D. [1991], Internetworking with TCP/IP Volume II: 
  7118. Design, Implementation, and Internals, Prentice Hall, Englewood Cliffs, New 
  7119. Jersey. 
  7120.  
  7121. Comer, D. and Stevens, D. [1991], Internetworking with TCP/IP Volume III: 
  7122. Client-Server Programming and Applications, Prentice Hall, Englewood Cliffs, 
  7123. New Jersey. 
  7124.  
  7125. Leffler, S. et al., An Advanced 4.3BSD Interprocess Communication Tutorial. 
  7126.  
  7127. Petzold, C. [1992], Programming Windows 3.1, Microsoft Press, Redmond, 
  7128. Washington. 
  7129.  
  7130. Stevens, W.R. [1990], Unix Network Programming, Prentice Hall, Englewood 
  7131. Cliffs, New Jersey. 
  7132.  
  7133.  
  7134. ΓòÉΓòÉΓòÉ 8.4. Background Information ΓòÉΓòÉΓòÉ
  7135.  
  7136.  
  7137. ΓòÉΓòÉΓòÉ 8.4.1. Origins of Windows Sockets ΓòÉΓòÉΓòÉ
  7138.  
  7139. The Windows Sockets project had its origins in a Birds Of A Feather session 
  7140. held at Interop '91 in San Jose on October 10, 1991.  A committee was 
  7141. established, and an intensive debate via email resulted in the creation of a 
  7142. first draft specification, which was largely based on submissions from JSB and 
  7143. NetManage.  This draft, and issues arising from it, were debated at a committee 
  7144. meeting hosted by Microsoft in Redmond, WA on December 9, 1991.  Following 
  7145. further email discussions, a working group was established to develop the 
  7146. specification into its current form. 
  7147.  
  7148. The following people participated in the process as committee members, in 
  7149. working meetings, or in email review.  The authors would like to thank everyone 
  7150. who participated in any way, and apologize in advance if we have omitted 
  7151. anyone. 
  7152.  
  7153. Martin Hall     (Moderator)     JSB Corporation         martinh@jsbus.com
  7154. Mark Towfiq (Coordinator)   Microdyne Corporation   towfiq@microdyne.com
  7155. Geoff Arnold                    Sun Microsystems, Inc.  geoff@east.sun.com
  7156. Alistair Banks                  Microsoft               alistair@microsoft.com
  7157. Carl Beame                      Beame & Whiteside   beame@mcmaster,ca
  7158. David Beaver                    Microsoft               dbeaver@microsoft.com
  7159. Amatzia BenArtzi                NetManage, Inc.         amatzia@netmanage.com
  7160. Mark Beyer                      Ungermann-Bass          mbeyer@ub.com
  7161. James Van Bokkelen              FTP Software            jbvb@ftp.com
  7162. Nelson Bolyard                  Silicon Graphics, Inc.  nelson@sgi.com
  7163. Pat Bonner                      Hewlett-Packard         p_bonner@cnd.hp.com
  7164. Isaac Chan                      Microsoft               isaacc@microsoft.com
  7165. Nestor Fesas                    Hughes LAN Systems      nestor@hls.com
  7166. Gary Gere                       Gupta                   ggere@gupta.com
  7167. Bill Hayes                      Hewlett-Packard         billh@hpchdpc.cnd.hp.com
  7168. Hoek Law                        Citicorp                law@dcc.tti.com
  7169. Paul Hill                       MIT                     pbh@athena.mit.edu
  7170. Graeme Le Roux                  Moresdawn P/L           -
  7171. Terry Lister                    Hewlett-Packard         tel@cnd.hp.com
  7172. Lee Murach                      Network Research        lee@nrc.com
  7173. David Pool                      Spry, Inc.              dave@spry.com
  7174. Brad Rice                       Age                     rice@age.com
  7175. Allen Rochkind                  3Com                    -
  7176. Henry Sanders                   Microsoft               henrysa@microsoft.com
  7177. David Treadwell                 Microsoft               davidtr@microsoft.com
  7178. Miles Wu                        Wollongong              wu@twg.com
  7179. Boris Yanovsky                  NetManage, Inc.         boris@netmanage.com
  7180. J Allard                        Microsoft Corporation   jallard@microsoft.com
  7181.  
  7182.  
  7183. ΓòÉΓòÉΓòÉ 8.4.2. Legal Status of Windows Sockets ΓòÉΓòÉΓòÉ
  7184.  
  7185. The copyright for the Windows Sockets specification is owned by the 
  7186. specification authors listed on the title page.  Permission is granted to 
  7187. redistribute this specification in any form, provided that the contents of the 
  7188. specification are not modified.  Windows Sockets implementors are encouraged to 
  7189. include this specification with their product documentation. 
  7190.  
  7191. The Windows Sockets logo on the title page of this document is meant for use on 
  7192. both Windows Sockets implementations and for applications that use the Windows 
  7193. Sockets interface.  Use of the logo is encouraged on packaging, documentation, 
  7194. collateral, and advertising.  The logo is available on SunSite.UNC.Edu in 
  7195. /pub/micro/pc-stuff/ms-windows/winsock/winsock-1.1 as winsock.bmp.  The 
  7196. suggested color for the logo's title bar is blue, the electrical socket grey, 
  7197. and the text and outline black. 
  7198.  
  7199.  
  7200. ΓòÉΓòÉΓòÉ 8.4.3. The Story Behind the Windows Sockets Icon ΓòÉΓòÉΓòÉ
  7201.  
  7202.  
  7203. (by Alistair Banks, Microsoft Corporation) 
  7204.  
  7205. We thought we'd do a "Wind Sock" at one stage--but you try to get that into 
  7206. 32x32 bits] It would have had to look wavy and colorful, and... well, it just 
  7207. didn't work. Also, our graphics designers have "opinions" about the icons truly 
  7208. representing what they are--people would have thought this was "The colorful 
  7209. wavy tube specification 1.0]" 
  7210.  
  7211. I tried to explain "API" "Programming Interface" to the artist--we ended up 
  7212. with toolbox icons with little flying windows. 
  7213.  
  7214. Then we came to realise that we should be going after the shortened form of the 
  7215. name, rather the name in full... Windows Sockets... And so we went for that -- 
  7216. so she drew (now remember I'm English and you're probably American) "Windows 
  7217. Spanner", a.k.a. a socket wrench.  In the U.S. you'd have been talking about 
  7218. the "Windows Socket spec" OK, but in England that would have been translatated 
  7219. as "Windows Spanner Spec 1.0" -- so we went to Electrical sockets -- well the 
  7220. first ones came out looking like "Windows Pignose Spec 1.0"]]]] 
  7221.  
  7222. So how do you use 32x32, get an international electrical socket] You take the 
  7223. square type (American & English OK, Europe & Australia are too rounded)--you 
  7224. choose the American one, because it's on the wall in front of you (and it's 
  7225. more compact (but less safe, IMHO) and then you turn it upside down, thereby 
  7226. compromising its nationality] 
  7227.  
  7228. ╤ìIMHO = "In My Humble Opinion"--ed.ΓêÖ