home *** CD-ROM | disk | FTP | other *** search
/ Internet Standards / CD1.mdf / winsock / winsock.txt < prev    next >
Text File  |  1993-01-20  |  325KB  |  7,849 lines

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