home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / WNSOCK.ZIP / WINSOCK.TXT < prev   
Encoding:
Text File  |  1992-08-05  |  353.8 KB  |  8,625 lines

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