Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Multicast chat example

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multicast chat example

    Code:
    '==================================================================================================
    ' Multicasting example. You can start multiple instances to chat.
    ' Uses wsock_x.inc: combination of ws2_32 and wsock32
    ' PBWin 7.x example
    '--------------------------------------------------------------------------------------------------
    #Compile Exe
    #Dim All
    #Include "win32api.inc"
    %WSOCK32 = 1
    #Include "Wsock_x.inc"
     
    $HELLO_GROUP    = "233.1.1.1"   'IP address of multicast
    %HELLO_PORT     = 40001         'Port number
    %IDC_LIST1      = 1001
    %IDC_TEXT1      = 1002
     
    %TXQLEN         = 25
     
    Global hDlg As Dword, hRxThread As Long, hTxThread As Long, TxPort As Long
    Global hOldText1 As Dword, hText1 As Dword, ProgramIsRunning As Long
    Global TxQRdPtr As Dword, TxQWrPtr As Dword, TxQueue() As String
     
    '==================================================================================================
    ' Queue functions
    '--------------------------------------------------------------------------------------------------
    Function WriteTxQueue(lData As String) As Long
      TxQueue(TxQWrPtr) = lData
      Incr TxQWrPtr
      If TxQWrPtr > %TXQLEN Then TxQWrPtr = 0
    End Function
     
    Function ReadTxQueue() As String
      If TxQWrPtr <> TxQRdPtr Then
        Function = TxQueue(TxQRdPtr)
        Incr TxQRdPtr
        If TxQRdPtr > %TXQLEN Then TxQRdPtr = 0
      End If
    End Function
    
    Function TxQueueHasData() As Long
      Function = (TxQRdPtr <> TxQWrPtr)
    End Function
     
    '==================================================================================================
    ' Tx thread - Sends packets
    '--------------------------------------------------------------------------------------------------
    Function Tx(ByVal Txt As Long)As Long
      Dim lRet As Long, LSock As Long, LSockAddr_in As SockAddr_in, lTTL As Long
      Dim LDst_SockAddr As SockAddr_In, lOne As Long, lSockout As SockAddr_In
      Dim lLen As Long, lString As String, szStr As Asciiz * 128
     
      LDst_SockAddr.Sin_Family      = %AF_INET
      LDst_SockAddr.Sin_Addr.s_Addr = htonl (%INADDR_ANY)
      LDst_SockAddr.Sin_port        = 0
      LSock = Socket (%AF_INET,%SOCK_DGRAM,ByVal 0)
      If LSock <> %INVALID_SOCKET Then
        lOne = 1
        LRet = SetSockOpt(LSock, %SOL_SOCKET, %SO_REUSEADDR, lOne, SizeOf(lOne))
        lRet = Bind (lSock, lDST_SockAddr, SizeOf (LDST_SockAddr))
        If lRet <> %SOCKET_ERROR Then
          lTTL = 255
          lRet = SetSockOpt(lSock, ByVal %IPPROTO_IP, ByVal %IP_MULTICAST_TTL, ByRef lTTl , SizeOf(lTTl))
          If lRet = 0 Then
            lTTl = 1
            LDst_SockAddr.Sin_Family      = %AF_INET
            LDst_SockAddr.Sin_Addr.s_Addr = Inet_addr ($HELLO_GROUP)
            LDst_SockAddr.Sin_port        = htons (%HELLO_PORT)
            GetSockName lSock, lSockOut, SizeOf(lSockOut)
            TxPort = ntohs(lSockOut.Sin_port)
            GetUserName szStr, SizeOf(szStr)
            While ProgramIsRunning
              If TxQueueHasData Then
                lString = szStr + " : " + Format$(TxPort) + ">" + " " + ReadTxQueue()
                lLen = Len (lString)
                LRet = Sendto (LSock, ByVal StrPtr(lString), ByVal lLen,0, LDst_SockAddr, SizeOf (LDst_SockAddr))
              End If
              Sleep 10
            Wend
          End If
        End If
      End If
    End Function
     
    '==================================================================================================
    ' Rx thread - Receives packets
    '--------------------------------------------------------------------------------------------------
    Function Rx(ByVal Rxt As Long)As Long
      Dim LRet As Long, LSock As Long,LSockAddr_in As SockAddr_in, lLen As Long
      Dim LMReq As Ip_MReq, RMsg As String * 66000, lOne As Long
      Dim lZPtr As Asciiz Ptr, lZCliIp As Asciiz * 15, lport As Long
     
      LSock = Socket (%AF_INET,%SOCK_DGRAM,ByVal 0)
      If LSock <> %INVALID_SOCKET Then
        LSockAddr_In.Sin_Family       = %AF_INET
        LSockAddr_In.Sin_addr.s_Addr  = htonl (%INADDR_ANY)
        LSockAddr_In.Sin_Port         = htons (%HELLO_PORT)
        lOne = 1
        LRet = SetSockOpt(LSock, %SOL_SOCKET, %SO_REUSEADDR, lOne, SizeOf(lOne))
        lRet = Bind (lSock, lSockAddr_In, SizeOf (lSockAddr_In))
        If lRet <> %SOCKET_ERROR Then
          LMReq.Imr_MultiAddress.s_Addr = Inet_Addr ($HELLO_GROUP)
          LMreq.Imr_Interface.s_Addr    = htonl (%INADDR_ANY)
          LRet = SetSockOpt(LSock, %IPPROTO_IP, %IP_ADD_MEMBERSHIP, LMReq, SizeOf(LMReq))
          If LRet = 0 Then
            LSockAddr_In.Sin_Family       = %AF_INET
            LSockAddr_In.Sin_addr.s_Addr  = htonl (%INADDR_ANY)
            LSockAddr_In.Sin_Port         = htons (%HELLO_PORT)
            While ProgramIsRunning
              rMsg = ""
              lLen = Len (rMsg)
              LRet = RecvFrom (LSock, rMsg, lLen, 0, LSockAddr_In, SizeOf (LSockAddr_In))
              If LRet > 0 Then
                lZPtr = Inet_NtoA (LSockAddr_In.sin_addr.s_addr)                                       'and originating port
                If lZPtr Then lZCliIp = @lZPtr                                                    '
                lPort = Abs (ntohs(lSockAddr_In.sin_port))
                If lPort <> TxPort Then
                  ListBox Add hDlg, %IDC_LIST1, Left$(rmsg,lRet)
                  Control Send hDlg, %IDC_LIST1, %LB_GETCOUNT, 0, 0 To lRet
                  Control Send hDlg, %IDC_LIST1, %LB_SETCURSEL, lRet-1, 0
                  Control Send hDlg, %IDC_LIST1, %LB_SETSEL, 0, lRet-1
                End If
              End If                                      '
            Wend
            LRet = SetSockOpt(LSock, %IPPROTO_IP, %IP_DROP_MEMBERSHIP, LMReq, SizeOf(LMReq))
          End If
        End If
      End If
      Dialog Set Text hDlg, "RX Thread ended..."
    End Function
     
    '==================================================================================================
    ' Subclass of edit box
    '--------------------------------------------------------------------------------------------------
    Function Text1_SubClass (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
      Local lzStr As Asciiz * 128, lRet As Long
      Static lString As String
      Select Case wMsg
        Case %WM_CHAR
          Select Case wParam
            Case &h20 To &h7f
              lString = lString + Chr$(wParam)
            Case &h0D
              WriteTxQueue lString
              lString = ""
          End Select
      End Select
      Function = CallWindowProc(hOldText1,hWnd,wMsg,wParam,lParam)
    End Function
     
    CallBack Function CbMain
      Select Case CbMsg
        Case %WM_INITDIALOG
          Control Handle hDlg, %IDC_TEXT1 To hText1
          hOldText1 = SetWindowLong(hText1, %GWL_WNDPROC, CodePtr(Text1_SubClass))
          Control Set Focus hDlg, %IDC_TEXT1
        Case %WM_DESTROY
          SetWindowLong hText1, %GWL_WNDPROC, hOldText1
      End Select
    End Function
      
    Function PBMain()As Long
      Dim LRet As Dword, LWsaData As WsaData
      ReDim TxQueue(%TXQLEN) As Global String
      If (WSAStartUp (&h0202,LWsaData)) <> 0 Then
        MsgBox "Unable to initialize Winsock DLL"
        Exit Function
      End If
      ProgramIsRunning = %TRUE
      Thread Create Tx(1) To hTxThread
      Thread Create Rx(1) To hRxThread
      Dialog New 0, "Chatting...",,, 250, 225, %WS_SYSMENU To hDlg
      Control Add Label,   hDlg, -1  , "In:" , 10, 5, 230, 12, %SS_CENTER
      Control Add Label,   hDlg, -1  , "Out:", 10, 100, 230, 12, %SS_CENTER
      Control Add ListBox, hDlg, %IDC_LIST1,, 10, 15, 230, 90, %WS_DISABLED Or %WS_VSCROLL, %WS_EX_CLIENTEDGE
      Control Add TextBox, hDlg, %IDC_TEXT1,"", 10,110, 230, 90, %ES_MULTILINE Or %ES_WANTRETURN Or %WS_VSCROLL Or %ES_AUTOVSCROLL, %WS_EX_CLIENTEDGE
     
      Dialog Show Modal hDlg, Call CbMain
      Thread Close hTxThread To lRet
      Thread Close hRxThread To lRet
      ProgramIsRunning = %FALSE
      Sleep 2000
      WSACleanUp
    End Function
    ------------------
    Regards,
    Peter



    [This message has been edited by Peter Lameijn (edited October 29, 2004).]
    Regards,
    Peter

  • #2
    The include file:
    Code:
    '------------------------------------------------------------------------------
    ' WSOCK_X.INC -- Windows Sockets 1.1 and 2.2 API Declarations for PowerBASIC
    '
    '               Copyright (C)1997-2002 PowerBASIC, Inc.
    '       Portions Copyright (C) 1993-1999 Microsoft Corporation
    '
    ' Last Update: January 21, 2002
    '
    ' This file contains CONSTANT, TYPE, UNION and DECLARE statements for the
    ' 32-bit Windows Sockets 1.1 (wsock32) and 2.2 (ws2_32) API's.
    ' If %WSOCK32 = 1 is defined, then wsock32 (winsock1) is used, else ws_2_32
    ' (winsock2) is used. Default is ws2_32 (winsock2).
    '
    ' This file is incompatible with VisualBasic. Uses correct datatype as defined
    ' in Microsoft SDK for Windows for all APIcalls. This includes datatypes which
    ' aren't natively supported in VB such as unsigned integers and ASCIIZ strings.
    ' You have a royalty-free right to use, modify, reproduce and distribute this
    ' file (and/or any modified version) in any way you find useful, provided that
    ' you agree that PowerBASIC has no warranty, obligation or liability for its
    ' contents. Refer to Microsofts Windows Programmer Reference for further info.
    '------------------------------------------------------------------------------
    #If Not %Def(%WSOCK_X_INC)
     %WSOCK_X_INC = 1                      'Prevent recursive include
    '------------------------------------------------------------------------------
    ' Default: include function prototypes, don't include function typedefs
    '------------------------------------------------------------------------------
     #If Not %Def(%INCL_WINSOCK_API_PROTOTYPES)
       %INCL_WINSOCK_API_PROTOTYPES = 1
     #EndIf
    '------------------------------------------------------------------------------
    ' Include win32api if necessairy
    '------------------------------------------------------------------------------
     #If Not %Def(%WINAPI)
       #Include "win32api.inc"
     #EndIf
    '------------------------------------------------------------------------------
    ' Set winsock version if not set
    '------------------------------------------------------------------------------
    #If Not %Def(%WINSOCK_VERSION)
      %WINSOCK_VERSION = &h0202??
    #EndIf
    '------------------------------------------------------------------------------
    ' Select uses arrays of sockets. These macros manipulate such arrays.
    ' %FD_SETSIZE may be defined by the user before including this file, but the
    ' default here should be >= 64
    '------------------------------------------------------------------------------
    #If Not %Def(%FD_SETSIZE)
      %FD_SETSIZE = 64
    #EndIf
     
    Type FD_SETstruc Dword
      fd_count As Dword
      fd_array (%FD_SETSIZE - 1) As Dword
    End Type
     
    Sub FD_SET (ByVal s As Dword, fds As fd_setstruc)
      Do
        If fds.fd_count < %FD_SETSIZE Then
          fds.fd_array(fds.fd_count) = s
          Incr fds.fd_count
        Else
          Exit Do
        End If
      Loop
    End Sub
    Sub FD_ZERO (fd As fd_setstruc)
        fd.fd_count = 0
    End Sub
     
    Type TimeVal Dword
      Tv_Sec    As Long
      Tv_uSec   As Long
    End Type
    '------------------------------------------------------------------------------
    ' Commands for IoCtlSocket()
    ' IoCtl's have the command encoded in the lower word, and the size of any in or
    ' out parameters in the upper word. The high 2 bits of the upper word are used
    ' to encode the in/out status of the parameter;for now we restrict to 128 bytes
    '------------------------------------------------------------------------------
    %IOCPARM_MASK   = &H7F                  'Parameters must be < 128 bytes
    %IOC_VOID       = &H20000000            'No parameters
    %IOC_OUT        = &H40000000            'Copy out parameters
    %IOC_IN         = &H80000000            'Copy in parameters
    %IOC_INOUT      = (%IOC_IN Or %IOC_OUT) '20000000 distinguishes new & old ioctl's
     
    %FIONBIO        = &h8004667E
    %FIONSYNC       = &h8004667D
    %FIONREAD       = &h4004667F
    '------------------------------------------------------------------------------
    ' Socket i/o control
    '------------------------------------------------------------------------------
    %SIOCSHIWAT   = &h80047300              'set high watermark
    %SIOCGHIWAT   = &h40047301              'get high watermark
    %SIOCSLOWAT   = &h80047302              'set low watermark
    %SIOCGLOWAT   = &h40047303              'get low watermark
    %SIOCATMARK   = &h40047307              'at oob mark?
    '------------------------------------------------------------------------------
    ' Structures returned by network data base library. All addresses are supplied
    ' in host order,and returned in network order.(suitable for use in systemcalls)
    '------------------------------------------------------------------------------
    Type Hostent
      h_name     As Asciiz Ptr              'official name of host
      h_alias    As Dword Ptr               'alias list
      h_addr     As Integer                 'host address type
      h_len      As Integer                 'length of address
      h_list     As Dword Ptr               'list of addresses
    End Type
     
    Type netent Dword
      n_name     As Asciiz Ptr              'official name of net
      n_aliases  As Dword Ptr               'alias list
      n_addrtype As Integer                 'net address type
      n_net      As Dword                   'network #
    End Type
     
    Type servent Dword
      s_name    As Asciiz Ptr               'official service name
      s_aliases As Dword Ptr                'alias list
      s_port    As Integer                  'port #
      s_proto   As Asciiz Ptr               'protocol to use
    End Type
     
    Type protoent Dword
      p_name As Asciiz Ptr                  'official protocol name
      p_aliases As Dword Ptr                'alias list
      p_proto As Integer                    'protocol #
    End Type
    '------------------------------------------------------------------------------
    ' Constants and structures defined by the internet system,per RFC 790,Sept.1981
    ' Protocols
    '------------------------------------------------------------------------------
    %IPPROTO_IP     = 0                     'Dummy for IP
    %IPPROTO_ICMP   = 1                     'Control message protocol
    %IPPROTO_IGMP   = 2                     'Group management protocol
    %IPPROTO_GGP    = 3                     'Gateway^2 (deprecated)
    %IPPROTO_TCP    = 6                     'Tcp
    %IPPROTO_PUP    = 12                    'Pup
    %IPPROTO_UDP    = 17                    'User datagram protocol
    %IPPROTO_IDP    = 22                    'Xns idp
    %IPPROTO_ND     = 77                    'UNOFFICIAL net disk proto
     
    %IPPROTO_RAW    = 255                   'Raw IP packet
    %IPPROTO_MAX    = 256
    '------------------------------------------------------------------------------
    ' Port/socket numbers - standard network functions
    '------------------------------------------------------------------------------
    %IPPORT_ECHO        = 7
    %IPPORT_DISCARD     = 9
    %IPPORT_SYSTAT      = 11
    %IPPORT_DAYTIME     = 13
    %IPPORT_NETSTAT     = 15
    %IPPORT_FTP         = 21
    %IPPORT_TELNET      = 23
    %IPPORT_SMTP        = 25
    %IPPORT_TIMESERVER  = 37
    %IPPORT_NAMESERVER  = 42
    %IPPORT_WHOIS       = 43
    %IPPORT_MTP         = 57
    '------------------------------------------------------------------------------
    ' Port/socket numbers - host specific functions
    '------------------------------------------------------------------------------
    %IPPORT_TFTP        = 69
    %IPPORT_RJE         = 77
    %IPPORT_FINGER      = 79
    %IPPORT_TTYLINK     = 87
    %IPPORT_SUPDUP      = 95
    '------------------------------------------------------------------------------
    ' Unix TCP sockets
    '------------------------------------------------------------------------------
    %IPPORT_EXECSERVER  = 512
    %IPPORT_LOGINSERVER = 513
    %IPPORT_CMDSERVER   = 514
    %IPPORT_EFSSERVER   = 520
    '------------------------------------------------------------------------------
    ' Unix UDP sockets
    '------------------------------------------------------------------------------
    %IPPORT_BIFFUDP     = 512
    %IPPORT_WHOSERVER   = 513
    %IPPORT_ROUTESERVER = 520
    ' 520+1 is also used
    '------------------------------------------------------------------------------
    ' Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root).
    '------------------------------------------------------------------------------
    %IPPORT_RESERVED    = 1024
    '------------------------------------------------------------------------------
    ' Link numbers
    '------------------------------------------------------------------------------
    %IMPLINK_IP         = 155
    %IMPLINK_LOWEXPER   = 156
    %IMPLINK_HIGHEXPER  = 158
    '------------------------------------------------------------------------------
    ' Internet address
    '------------------------------------------------------------------------------
    Type s_un_b_struc
     s_b1   As Byte
     s_b2   As Byte
     s_b3   As Byte
     s_b4   As Byte
    End Type
     
    Type s_un_w_struc
     s_w1   As Word
     s_w2   As Word
    End Type
     
    Union s_un
      s_un_b As s_un_b_struc
      s_un_w As s_un_w_struc
    End Union
     
    Union in_addr
      s_un_b     As s_un_b_struc
      s_un_w     As s_un_w_struc
      s_addr    As Dword
    End Union
    '------------------------------------------------------------------------------
    ' Definition of bits in Internet address integers.
    '------------------------------------------------------------------------------
    Function IN_CLASSA(ByVal i As Dword) As Long
      Function = ((i And &h080000000) = 0)
    End Function
     
    %IN_CLASSA_NET      = &h0FF000000
    %IN_CLASSA_NSHIFT   = 24
    %IN_CLASSA_HOST     = &h000FFFFFF
    %IN_CLASSA_MAX      = 128
     
    Function IN_CLASSB(ByVal i As Dword) As Long
      Function = ((i And &h0C0000000) = &h080000000)
    End Function
     
    %IN_CLASSB_NET      = &h0FFFF0000
    %IN_CLASSB_NSHIFT   = 16
    %IN_CLASSB_HOST     = &h00000FFFF
    %IN_CLASSB_MAX      = 65536
     
    Function IN_CLASSC(ByVal i As Dword) As Long
      Function = ((i And &h0E0000000) = &h0C0000000)
    End Function
     
    %IN_CLASSC_NET      = &h0FFFFFF00
    %IN_CLASSC_NSHIFT   = 8
    %IN_CLASSC_HOST     = &h0000000FF
     
    #If Not %Def(%WSOCK32)
      Function IN_CLASSD(ByVal i As Dword) As Long
        Function = ((i And &h0F0000000) = &h0E0000000)
      End Function
     
      %IN_CLASSD_NET      = &h0F0000000
      %IN_CLASSD_NSHIFT   = 28
      %IN_CLASSD_HOST     = &h00FFFFFFF
    #EndIf
     
    %INADDR_ANY         = &h000000000
    %INADDR_LOOPBACK    = &h07F000001
    %INADDR_BROADCAST   = &h0FFFFFFFF
    %INADDR_NONE        = &h0FFFFFFFF
    %ADDR_ANY           = %INADDR_ANY
    '------------------------------------------------------------------------------
    ' Socket address, internet style
    '------------------------------------------------------------------------------
    Type sockaddr_in
      sin_family As Integer
      sin_port As Word
      sin_addr As in_addr
      sin_zero As String * 8
    End Type
     
    %WSADESCRIPTION_LEN = 256
    %WSASYS_STATUS_LEN  = 128
     
    Type WSAdata
      wVersion As Word
      wHighVersion As Word
      szDescription As Asciiz * %WSADESCRIPTION_LEN + 1
      szSystemStatus As Asciiz * %WSASYS_STATUS_LEN + 1
      iMaxSockets As Word
      iMaxUdpDg As Word
      lpVendorInfo As Asciiz Ptr
    End Type
    '------------------------------------------------------------------------------
    ' Definitions related to sockets.
    '------------------------------------------------------------------------------
    %INVALID_SOCKET     = Not 0
    %SOCKET_ERROR       = -1
    %FROM_PROTOCOL_INFO = -1
    '------------------------------------------------------------------------------
    ' Socket types
    '------------------------------------------------------------------------------
    %SOCK_STREAM        = 1                 'Stream socket
    %SOCK_DGRAM         = 2                 'Datagram socket
    %SOCK_RAW           = 3                 'Raw-protocol interface
    %SOCK_RDM           = 4                 'Reliably-delivered message
    %SOCK_SEQPACKET     = 5                 'Sequenced packet stream
    '------------------------------------------------------------------------------
    ' Option flags per socket
    '------------------------------------------------------------------------------
    %SO_DEBUG           = &H00001           'Turn on debugging info recording
    %SO_ACCEPTCONN      = &H00002           'Socket has had listen()
    %SO_REUSEADDR       = &H00004           'Allow local address reuse
    %SO_KEEPALIVE       = &H00008           'Keep connections alive
    %SO_DONTROUTE       = &H00010           'Just use interface addresses
    %SO_BROADCAST       = &H00020           'Permit sending of broadcast msgs
    %SO_USELOOPBACK     = &H00040           'Bypass hardware when possible
    %SO_LINGER          = &H00080           'Linger on close if data present
    %SO_OOBINLINE       = &H00100           'Leave received OOB data in line
    %SO_DONTLINGER      = Not %SO_LINGER
    %SO_EXCLUSIVEADDRUSE= Not %SO_REUSEADDR
    '------------------------------------------------------------------------------
    ' Additional options
    '------------------------------------------------------------------------------
    %SO_SNDBUF          = &H01001           'Send buffer size
    %SO_RCVBUF          = &H01002           'Receive buffer size
    %SO_SNDLOWAT        = &H01003           'Send low-water mark
    %SO_RCVLOWAT        = &H01004           'Receive low-water mark
    %SO_SNDTIMEO        = &H01005           'Send timeout
    %SO_RCVTIMEO        = &H01006           'Receive timeout
    %SO_ERROR           = &H01007           'Get error status and clear
    %SO_TYPE            = &H01008           'Get socket type
    '------------------------------------------------------------------------------
    ' Options for connect/disconnect data and options. Used only by non-TCP/IP
    ' transports such as DECNet, OSI TP4, etc.
    '------------------------------------------------------------------------------
    %SO_CONNDATA        = &h07000
    %SO_CONNOPT         = &h07001
    %SO_DISCDATA        = &h07002
    %SO_DISCOPT         = &h07003
    %SO_CONNDATALEN     = &h07004
    %SO_CONNOPTLEN      = &h07005
    %SO_DISCDATALEN     = &h07006
    %SO_DISCOPTLEN      = &h07007
    '------------------------------------------------------------------------------
    ' Option for opening sockets for synchronous access.
    '------------------------------------------------------------------------------
    %SO_OPENTYPE                = &h07008
    %SO_SYNCHRONOUS_ALERT       = &h010
    %SO_SYNCHRONOUS_NONALERT    = &h020
    '------------------------------------------------------------------------------
    ' Other NT-specific options.
    '------------------------------------------------------------------------------
    %SO_MAXDG                   = &h07009
    %SO_MAXPATHDG               = &h0700A
    %SO_UPDATE_ACCEPT_CONTEXT   = &h0700B
    %SO_CONNECT_TIME            = &h0700C
    '------------------------------------------------------------------------------
    ' Additional winsock2 options
    '------------------------------------------------------------------------------
      %SO_GROUP_ID            = &H2001        'ID of a socket group
      %SO_GROUP_PRIORITY      = &H2002        'the relative priority within a group
      %SO_MAX_MSG_SIZE        = &H2003        'maximum message size
      %SO_PROTOCOL_INFO       = &H2004        'WSAPROTOCOL_INFO structure
      %SO_PROTOCOL_INFOA      = &H2004        'WSAPROTOCOL_INFO structure
      %SO_PROTOCOL_INFOW      = &H2005        'WSAPROTOCOL_INFO structure
      %PVD_CONFIG             = &H3001        'configuration info for serviceprovider
      %SO_CONDITIONAL_ACCEPT  = &H3002        'enable true conditional accept:
                                              'connection is not ack-ed to the
                                              'other side until conditional
                                              'function returns %CF_ACCEPT
    '------------------------------------------------------------------------------
    ' Option for opening sockets for synchronous access.
    '------------------------------------------------------------------------------
    %SO_OPENTYPE             = &h07008
    %SO_SYNCHRONOUS_ALERT    = &h010
    %SO_SYNCHRONOUS_NONALERT = &h020
    '------------------------------------------------------------------------------
    ' Other NT-specific options.
    '------------------------------------------------------------------------------
    %SO_MAXDG                   = &h07009
    %SO_MAXPATHDG               = &h0700A
    %SO_UPDATE_ACCEPT_CONTEXT   = &h0700B
    %SO_CONNECT_TIME            = &h0700C
    '------------------------------------------------------------------------------
    ' TCP Options
    '------------------------------------------------------------------------------
    %TCP_NODELAY        = &H00001
    %TCP_BSDURGENT      = &H07000
    '------------------------------------------------------------------------------
    'Address families.
    '------------------------------------------------------------------------------
    %AF_UNSPEC          = 0                 'Unspecified
    %AF_UNIX            = 1                 'Local to host (pipes, portals)
    %AF_INET            = 2                 'Internetwork: UDP, TCP, etc.
    %AF_IMPLINK         = 3                 'Arpanet imp addresses
    %AF_PUP             = 4                 'Pup protocols: e.g. BSP
    %AF_CHAOS           = 5                 'Mit CHAOS protocols
    %AF_NS              = 6                 'XEROX NS protocols
    %AF_IPX             = %AF_NS            'IPX and SPX
    %AF_ISO             = 7                 'ISO protocols
    %AF_OSI             = %AF_ISO           'OSI is ISO
    %AF_ECMA            = 8                 'European computer manufacturers
    %AF_DATAKIT         = 9                 'Datakit protocols
    %AF_CCITT           = 10                'CCITT protocols, X.25 etc
    %AF_SNA             = 11                'IBM SNA
    %AF_DECnet          = 12                'DECnet
    %AF_DLI             = 13                'Direct data link interface
    %AF_LAT             = 14                'LAT
    %AF_HYLINK          = 15                'NSC Hyperchannel
    %AF_APPLETALK       = 16                'AppleTalk
    %AF_NETBIOS         = 17                'NetBios-style addresses
    %AF_VOICEVIEW       = 18                'VoiceView
    %AF_FIREFOX         = 19                'FireFox
    %AF_UNKNOWN         = 20                'Somebody is using this!
    %AF_BAN             = 21                'Banyan
    #If Not %Def(%WSOCK32)
      %AF_ATM           = 22                'Native ATM services
      %AF_INET6         = 23                'InterNetwork Version 6
      %AF_CLUSTER       = 24                'MicroSoft WolfPack
      %AF_12844         = 25                'IEEE 1284.4 WG AF
      %AF_IRDA          = 26                'IrDA
      %AF_NETDES        = 28                'Network designers OSI and Gateway
      %AF_MAX           = 29                '
    #Else
      %AF_MAX           = 22                '
    #EndIf
    '------------------------------------------------------------------------------
    ' Structure used by kernel to store most addresses
    '------------------------------------------------------------------------------
    Type sockaddr
      sa_family As Word
      sa_data   As String * 14
    End Type
    '------------------------------------------------------------------------------
    ' Structure used by kernel to pass protocol information in raw sockets
    '------------------------------------------------------------------------------
    Type sockproto
      sp_family As Word
      sp_protocol As Word
    End Type
    '------------------------------------------------------------------------------
    'Protocol families, same as address families for now.
    '------------------------------------------------------------------------------
    %PF_UNSPEC          = %AF_UNSPEC
    %PF_UNIX            = %AF_UNIX
    %PF_INET            = %AF_INET
    %PF_IMPLINK         = %AF_IMPLINK
    %PF_PUP             = %AF_PUP
    %PF_CHAOS           = %AF_CHAOS
    %PF_NS              = %AF_NS
    %PF_IPX             = %AF_IPX
    %PF_ISO             = %AF_ISO
    %PF_OSI             = %AF_OSI
    %PF_ECMA            = %AF_ECMA
    %PF_DATAKIT         = %AF_DATAKIT
    %PF_CCITT           = %AF_CCITT
    %PF_SNA             = %AF_SNA
    %PF_DECnet          = %AF_DECnet
    %PF_DLI             = %AF_DLI
    %PF_LAT             = %AF_LAT
    %PF_HYLINK          = %AF_HYLINK
    %PF_APPLETALK       = %AF_APPLETALK
    %PF_VOICEVIEW       = %AF_VOICEVIEW
    %PF_FIREFOX         = %AF_FIREFOX
    %PF_UNKNOWN         = %AF_UNKNOWN
    %PF_BAN             = %AF_BAN
    #If Not %Def(%WSOCK32)
      %PF_ATM             = %AF_ATM
      %PF_INET6           = %AF_INET6
    #EndIf
    %PF_MAX             = %AF_MAX
    '------------------------------------------------------------------------------
    ' Structure used for manipulation linger option
    '------------------------------------------------------------------------------
    Type linger Dword
      l_onoff As Word                       'Option on/off
      l_linger As Word                      'Linger time
    End Type
    '------------------------------------------------------------------------------
    ' Level number for get/setsockopt() to apply to socket itself
    '------------------------------------------------------------------------------
    %SOL_SOCKET         =   &H0000FFFF      'options for socket level
    '------------------------------------------------------------------------------
    'Options for use with [gs]etsockopt at the IP level.
    '------------------------------------------------------------------------------
    %IP_OPTIONS                 = 1         'Set/get IP per-packet options
    %IP_MULTICAST_IF            = 2         'Set/get IP multicast interface
    %IP_MULTICAST_TTL           = 3         'Set/get IP multicast timetolive
    %IP_MULTICAST_LOOP          = 4         'Set/get IP multicast loopback
    %IP_ADD_MEMBERSHIP          = 5         'Add  an IP group membership
    %IP_DROP_MEMBERSHIP         = 6         'Drop an IP group membership
    %IP_TTL                     = 7         'Set/get IP Time To Live
    %IP_TOS                     = 8         'Set/get IP Type Of Service
    %IP_DONTFRAGMENT            = 9         'Set/get IP Don't Fragment flag
     
    %IP_DEFAULT_MULTICAST_TTL   = 1         'Normally limit m'casts to 1 hop
    %IP_DEFAULT_MULTICAST_LOOP  = 1         'Normally hear sends if a member
    %IP_MAX_MEMBERSHIPS         = 20        'Per socket; must fit in one mbuf
     
    Type Ip_MREQ
      Imr_MultiAddress As In_Addr
      Imr_Interface    As In_Addr
    End Type
    '------------------------------------------------------------------------------
    ' Maximum queue length specifiable by listen
    '------------------------------------------------------------------------------
    #If Not %Def(%WSOCK32)
      %SOMAXCONN        = &h7FFFFFFF        '
    #Else
      %SOMAXCONN        = 5                 '
    #EndIf
    %MSG_OOB            = &H01              'Process out-of-band data
    %MSG_PEEK           = &H02              'Peek at incoming message
    %MSG_DONTROUTE      = &H04              'Send without using routing tables
    %MSG_PARTIAL        = &H08000           'Partial send or recv msg export
    %MSG_MAXIOVLEN      = 16
    %MSG_INTERRUPT      = &h10              'Send/recv in interrupt context
    '------------------------------------------------------------------------------
    'Define constant based on rfc883, used by gethostbyxxxx() calls.
    '------------------------------------------------------------------------------
    %MAXGETHOSTSTRUCT   = 1024
    '------------------------------------------------------------------------------
    ' WinSock 2 extension -- bit values and indices for FD_XXX network events
    '------------------------------------------------------------------------------
    %FD_READ_BIT        = 0
    %FD_READ            = 1
    %FD_WRITE_BIT       = 1
    %FD_WRITE           = 2
    %FD_OOB_BIT         = 2
    %FD_OOB             = 4
    %FD_ACCEPT_BIT      = 3
    %FD_ACCEPT          = 8
    %FD_CONNECT_BIT     = 4
    %FD_CONNECT         = 16
    %FD_CLOSE_BIT       = 5
    %FD_CLOSE           = 32
    #If Not %Def(%WSOCK32)
      %FD_QOS_BIT         = 6
      %FD_QOS             = 64
      %FD_GROUP_QOS_BIT   = 7
      %FD_GROUP_QOS       = 128
      %FD_ROUTING_INTERFACE_CHANGE_BIT = 8
      %FD_ROUTING_INTERFACE_CHANGE     = 256
      %FD_ADDRESS_LIST_CHANGE_BIT      = 9
      %FD_ADDRESS_LIST_CHANGE          = 512
    #EndIf
      %FD_MAX_EVENTS                   = 10
      %FD_ALL_EVENTS                   = 1024 - 1
    '------------------------------------------------------------------------------
    ' All Windows Socketerror constants are biased by WSABASEERR from the "normal"
    '------------------------------------------------------------------------------
    %WSABASEERR         = 10000
    '------------------------------------------------------------------------------
    ' Windows Sockets definitions of regular Microsoft C error constants
    '------------------------------------------------------------------------------
    %WSAEINTR           = %WSABASEERR + 4
    %WSAEBADF           = %WSABASEERR + 9
    %WSAEACCES          = %WSABASEERR + 13
    %WSAEFAULT          = %WSABASEERR + 14
    %WSAEINVAL          = %WSABASEERR + 22
    %WSAEMFILE          = %WSABASEERR + 24
    '------------------------------------------------------------------------------
    'Windows Sockets definitions of regular Berkeley error constants
    '------------------------------------------------------------------------------
    %WSAEWOULDBLOCK     = %WSABASEERR + 35
    %WSAEINPROGRESS     = %WSABASEERR + 36
    %WSAEALREADY        = %WSABASEERR + 37
    %WSAENOTSOCK        = %WSABASEERR + 38
    %WSAEDESTADDRREQ    = %WSABASEERR + 39
    %WSAEMSGSIZE        = %WSABASEERR + 40
    %WSAEPROTOTYPE      = %WSABASEERR + 41
    %WSAENOPROTOOPT     = %WSABASEERR + 42
    %WSAEPROTONOSUPPORT = %WSABASEERR + 43
    %WSAESOCKTNOSUPPORT = %WSABASEERR + 44
    %WSAEOPNOTSUPP      = %WSABASEERR + 45
    %WSAEPFNOSUPPORT    = %WSABASEERR + 46
    %WSAEAFNOSUPPORT    = %WSABASEERR + 47
    %WSAEADDRINUSE      = %WSABASEERR + 48
    %WSAEADDRNOTAVAIL   = %WSABASEERR + 49
    %WSAENETDOWN        = %WSABASEERR + 50
    %WSAENETUNREACH     = %WSABASEERR + 51
    %WSAENETRESET       = %WSABASEERR + 52
    %WSAECONNABORTED    = %WSABASEERR + 53
    %WSAECONNRESET      = %WSABASEERR + 54
    %WSAENOBUFS         = %WSABASEERR + 55
    %WSAEISCONN         = %WSABASEERR + 56
    %WSAENOTCONN        = %WSABASEERR + 57
    %WSAESHUTDOWN       = %WSABASEERR + 58
    %WSAETOOMANYREFS    = %WSABASEERR + 59
    %WSAETIMEDOUT       = %WSABASEERR + 60
    %WSAECONNREFUSED    = %WSABASEERR + 61
    %WSAELOOP           = %WSABASEERR + 62
    %WSAENAMETOOLONG    = %WSABASEERR + 63
    %WSAEHOSTDOWN       = %WSABASEERR + 64
    %WSAEHOSTUNREACH    = %WSABASEERR + 65
    %WSAENOTEMPTY       = %WSABASEERR + 66
    %WSAEPROCLIM        = %WSABASEERR + 67
    %WSAEUSERS          = %WSABASEERR + 68
    %WSAEDQUOT          = %WSABASEERR + 69
    %WSAESTALE          = %WSABASEERR + 70
    %WSAEREMOTE         = %WSABASEERR + 71
    '------------------------------------------------------------------------------
    'Extended Windows Sockets error constant definitions
    '------------------------------------------------------------------------------
    %WSASYSNOTREADY         = %WSABASEERR + 91
    %WSAVERNOTSUPPORTED     = %WSABASEERR + 92
    %WSANOTINITIALISED      = %WSABASEERR + 93
    %WSAEDISCON             = %WSABASEERR + 101
    #If Not %Def(%WSOCK32)
      %WSAENOMORE             = %WSABASEERR + 102
      %WSAECANCELLED          = %WSABASEERR + 103
      %WSAEINVALIDPROCTABLE   = %WSABASEERR + 104
      %WSAEINVALIDPROVIDER    = %WSABASEERR + 105
      %WSAEPROVIDERFAILEDINIT = %WSABASEERR + 106
      %WSASYSCALLFAILURE      = %WSABASEERR + 107
      %WSASERVICE_NOT_FOUND   = %WSABASEERR + 108
      %WSATYPE_NOT_FOUND      = %WSABASEERR + 109
      %WSA_E_NO_MORE          = %WSABASEERR + 110
      %WSA_E_CANCELLED        = %WSABASEERR + 111
      %WSAEREFUSED            = %WSABASEERR + 112
    #EndIf
    '------------------------------------------------------------------------------
    'Error return codes from gethostbyname() and gethostbyaddr() (when using the
    'resolver). Note that these errors are retrieved via WSAGetLastError() and must
    'therefore follow the rules for avoiding clashes with error numbers from
    'specific implementations or language run-time systems. For this reason the
    'codes are based at WSABASEERR + 1001.
    'Note also that [WSA]NO_ADDRESS is defined only for compatibility purposes.
    '------------------------------------------------------------------------------
    %WSAHOST_NOT_FOUND  = %WSABASEERR + 1001
    %HOST_NOT_FOUND     = %WSAHOST_NOT_FOUND
     
    %WSATRY_AGAIN       = %WSABASEERR + 1002
    %TRY_AGAIN          = %WSATRY_AGAIN
     
    %WSANO_RECOVERY     = %WSABASEERR + 1003
    %NO_RECOVERY        = %WSANO_RECOVERY
     
    %WSANO_DATA         = %WSABASEERR + 1004
    %NO_DATA            = %WSANO_DATA
     
    %WSANO_ADDRESS      = %WSANO_DATA
    %NO_ADDRESS         = %WSANO_ADDRESS
    '------------------------------------------------------------------------------
    ' Define QOS related error return codes
    '------------------------------------------------------------------------------
    #If Not %Def(%WSOCK32)
      %WSA_QOS_RECEIVERS          = %WSABASEERR + 1005    'At least 1 Reserve arrived
      %WSA_QOS_SENDERS            = %WSABASEERR + 1006    'At least 1 Path arrived
      %WSA_QOS_NO_SENDERS         = %WSABASEERR + 1007    'There are no senders
      %WSA_QOS_NO_RECEIVERS       = %WSABASEERR + 1008    'There are no receivers
      %WSA_QOS_REQUEST_CONFIRMED  = %WSABASEERR + 1009    'Reserve has been confirmed
      %WSA_QOS_ADMISSION_FAILURE  = %WSABASEERR + 1010    'Error: lack of resources
      %WSA_QOS_POLICY_FAILURE     = %WSABASEERR + 1011    'Reject for bad credentials
      %WSA_QOS_BAD_STYLE          = %WSABASEERR + 1012    'Unknown/conflicting style
      %WSA_QOS_BAD_OBJECT         = %WSABASEERR + 1013    'Problem with filter/buffer
      %WSA_QOS_TRAFFIC_CTRL_ERROR = %WSABASEERR + 1014    'Problem with part flowspec
      %WSA_QOS_GENERIC_ERROR      = %WSABASEERR + 1015    'General error
      %WSA_QOS_ESERVICETYPE       = %WSABASEERR + 1016    'Invalid servicetype
      %WSA_QOS_EFLOWSPEC          = %WSABASEERR + 1017    'Invalid flowspec
      %WSA_QOS_EPROVSPECBUF       = %WSABASEERR + 1018    'Invalid provider buffer
      %WSA_QOS_EFILTERSTYLE       = %WSABASEERR + 1019    'Invalid filter style
      %WSA_QOS_EFILTERTYPE        = %WSABASEERR + 1020    'Invalid filter type
      %WSA_QOS_EFILTERCOUNT       = %WSABASEERR + 1021    'Incorrect number of filters
      %WSA_QOS_EOBJLENGTH         = %WSABASEERR + 1022    'Invalid object length
      %WSA_QOS_EFLOWCOUNT         = %WSABASEERR + 1023    'Incorrect number of flows
      %WSA_QOS_EUNKOWNPSOBJ       = %WSABASEERR + 1024    'Unkn.obj.in providerbuffer
      %WSA_QOS_EPOLICYOBJ         = %WSABASEERR + 1025    'Inval.policyobject in providerbuffer
      %WSA_QOS_EFLOWDESC          = %WSABASEERR + 1026    'Invalid flowdescriptor in list
      %WSA_QOS_EPSFLOWSPEC        = %WSABASEERR + 1027    'Inconsistent flowspec in providerbuffer
      %WSA_QOS_EPSFILTERSPEC      = %WSABASEERR + 1028    'Invalid filter spec in providerbuffer
      %WSA_QOS_ESDMODEOBJ         = %WSABASEERR + 1029    'Invalid shape discard mode object in providerbuffer
      %WSA_QOS_ESHAPERATEOBJ      = %WSABASEERR + 1030    'Invalid shaping rate object in providerbuffer
      %WSA_QOS_RESERVED_PETYPE    = %WSABASEERR + 1031    'Reserved policy element in providerbuffer
    '------------------------------------------------------------------------------
    ' Compatibility constants
    '------------------------------------------------------------------------------
      %HOST_NOT_FOUND     = %WSAHOST_NOT_FOUND
      %TRY_AGAIN          = %WSATRY_AGAIN
      %NO_RECOVERY        = %WSANO_RECOVERY
      %NO_DATA            = %WSANO_DATA
    ' no address, look for MX record
      %WSANO_ADDRESS      = %WSANO_DATA
      %NO_ADDRESS         = %WSANO_ADDRESS
    #EndIf
    '------------------------------------------------------------------------------
    'Windows Sockets errors redefined as regular Berkeley error constants
    '------------------------------------------------------------------------------
    %EWOULDBLOCK        = %WSAEWOULDBLOCK
    %EINPROGRESS        = %WSAEINPROGRESS
    %EALREADY           = %WSAEALREADY
    %ENOTSOCK           = %WSAENOTSOCK
    %EDESTADDRREQ       = %WSAEDESTADDRREQ
    %EMSGSIZE           = %WSAEMSGSIZE
    %EPROTOTYPE         = %WSAEPROTOTYPE
    %ENOPROTOOPT        = %WSAENOPROTOOPT
    %EPROTONOSUPPORT    = %WSAEPROTONOSUPPORT
    %ESOCKTNOSUPPORT    = %WSAESOCKTNOSUPPORT
    %EOPNOTSUPP         = %WSAEOPNOTSUPP
    %EPFNOSUPPORT       = %WSAEPFNOSUPPORT
    %EAFNOSUPPORT       = %WSAEAFNOSUPPORT
    %EADDRINUSE         = %WSAEADDRINUSE
    %EADDRNOTAVAIL      = %WSAEADDRNOTAVAIL
    %ENETDOWN           = %WSAENETDOWN
    %ENETUNREACH        = %WSAENETUNREACH
    %ENETRESET          = %WSAENETRESET
    %ECONNABORTED       = %WSAECONNABORTED
    %ECONNRESET         = %WSAECONNRESET
    %ENOBUFS            = %WSAENOBUFS
    %EISCONN            = %WSAEISCONN
    %ENOTCONN           = %WSAENOTCONN
    %ESHUTDOWN          = %WSAESHUTDOWN
    %ETOOMANYREFS       = %WSAETOOMANYREFS
    %ETIMEDOUT          = %WSAETIMEDOUT
    %ECONNREFUSED       = %WSAECONNREFUSED
    %ELOOP              = %WSAELOOP
    %ENAMETOOLONG       = %WSAENAMETOOLONG
    %EHOSTDOWN          = %WSAEHOSTDOWN
    %EHOSTUNREACH       = %WSAEHOSTUNREACH
    %ENOTEMPTY          = %WSAENOTEMPTY
    %EPROCLIM           = %WSAEPROCLIM
    %EUSERS             = %WSAEUSERS
    %EDQUOT             = %WSAEDQUOT
    %ESTALE             = %WSAESTALE
    %EREMOTE            = %WSAEREMOTE
    '------------------------------------------------------------------------------
    ' Winsock2 error and type extensions
    '------------------------------------------------------------------------------
    #If Not %Def(%WSOCK32)
    %WSA_IO_PENDING         = %ERROR_IO_PENDING
    %WSA_IO_INCOMPLETE      = %ERROR_IO_INCOMPLETE
    %WSA_INVALID_HANDLE     = %ERROR_INVALID_HANDLE
    %WSA_INVALID_PARAMETER  = %ERROR_INVALID_PARAMETER
    %WSA_NOT_ENOUGH_MEMORY  = %ERROR_NOT_ENOUGH_MEMORY
    %WSA_OPERATION_ABORTED  = %ERROR_OPERATION_ABORTED
     
    %WSA_INVALID_EVENT      = 0???
    %WSA_MAXIMUM_WAIT_EVENTS= %MAXIMUM_WAIT_OBJECTS
    %WSA_WAIT_FAILED        = %WAIT_FAILED
    %WSA_WAIT_EVENT_0       = %WAIT_OBJECT_0
    %WSA_WAIT_IO_COMPLETION = %WAIT_IO_COMPLETION
    %WSA_WAIT_TIMEOUT       = %WAIT_TIMEOUT
    %WSA_INFINITE           = %INFINITE
     
    Type WSABUF
      dLen As Dword                         ' the length of the buffer
      buf As Asciiz Ptr                     ' the pointer to the buffer
    End Type
     
    #If Not %Def(%QOS_INC) '-------------------------------------------------------
     
    %QOS_INC = 1
     
    ' Definitions for valued-based Service Type for each direction of data flow.
     
    %SERVICETYPE_NOTRAFFIC           = &H00000000  ' No data in this direction
    %SERVICETYPE_BESTEFFORT          = &H00000001  ' Best Effort
    %SERVICETYPE_CONTROLLEDLOAD      = &H00000002  ' Controlled Load
    %SERVICETYPE_GUARANTEED          = &H00000003  ' Guaranteed
    %SERVICETYPE_NETWORK_UNAVAILABLE = &H00000004  ' Used to notify change to user
    %SERVICETYPE_GENERAL_INFORMATION = &H00000005  ' corresponds to "General Parameters" defined by IntServ
    %SERVICETYPE_NOCHANGE            = &H00000006  ' used to indicate that the flow spec contains no change from any previous one
    %SERVICETYPE_NONCONFORMING       = &H00000009  ' Non-Conforming Traffic
    %SERVICETYPE_NETWORK_CONTROL     = &H0000000A  ' Network Control traffic
    %SERVICETYPE_QUALITATIVE         = &H0000000D  ' Qualitative applications
     
    ' Definitions for bitmap-based Service Type for each direction of data flow.
     
    %SERVICE_BESTEFFORT              = &H80010000
    %SERVICE_CONTROLLEDLOAD          = &H80020000
    %SERVICE_GUARANTEED              = &H80040000
    %SERVICE_QUALITATIVE             = &H80200000
     
     
    ' Flags to control the usage of RSVP on this flow.
     
    ' to turn off traffic control, 'OR' this flag with the
    ' ServiceType field in the FLOWSPEC
     
    %SERVICE_NO_TRAFFIC_CONTROL = &H81000000
     
     
    ' this flag can be used to prevent any rsvp signaling messages from being
    ' sent. Local traffic control will be invoked, but no RSVP Path messages
    ' will be sent.This flag can also be used in conjunction with a receiving
    ' flowspec to suppress the automatic generation of a Reserve message.
    ' The application would receive notification that a Path  message had arrived
    ' and would then need to alter the QOS by issuing WSAIoctl(%SIO_SET_QOS),
    ' to unset this flag and thereby causing Reserve messages to go out.
     
    %SERVICE_NO_QOS_SIGNALING   = &H40000000
     
    ' Flow Specifications for each direction of data flow.
     
    Type FLOWSPEC Dword
      TokenRate As Dword            ' In Bytes/sec
      TokenBucketSize As Dword      ' In Bytes
      PeakBandwidth As Dword        ' In Bytes/sec
      Latency As Dword              ' In microseconds
      DelayVariation As Dword       ' In microseconds
      ServiceType As Dword
      MaxSduSize As Dword           ' In Bytes
      MinimumPolicedSize As Dword   ' In Bytes
    End Type
     
    
    ' this value can be used in the FLOWSPEC structure to instruct the Rsvp Service
    ' provider to derive the appropriate default value for the parameter.  Note
    ' that not all values in the FLOWSPEC structure can be defaults. In the
    ' ReceivingFlowspec, all parameters can be defaulted except the ServiceType.
    ' In the SendingFlowspec, the MaxSduSize and MinimumPolicedSize can be
    ' defaulted. Other defaults may be possible. Refer to the appropriate
    ' documentation.
     
    %QOS_NOT_SPECIFIED = &HFFFFFFFF
    
     
    ' define a value that can be used for the PeakBandwidth, which will map into
    ' positive infinity when the FLOWSPEC is converted into IntServ floating point
    ' format.  We can't use (-1) because that value was previously defined to mean
    ' "select the default".
     
    %POSITIVE_INFINITY_RATE = &HFFFFFFFE
     
    
    ' the provider specific structure can have a number of objects in it.
    ' Each next structure in the
    ' ProviderSpecific will be the QOS_OBJECT_HDR struct that prefaces the actual
    ' data with a type and length for that object.  This QOS_OBJECT struct can
    ' repeat several times if there are several objects.  This list of objects
    ' terminates either when the buffer length has been reached ( WSABUF ) or
    ' an object of type QOS_END_OF_LIST is encountered.
     
    Type QOS_OBJECT_HDR Dword
      ObjectType As Dword
      ObjectLength As Dword   ' the length of object buffer INCLUDING this header
    End Type
     
    
    ' general QOS objects start at this offset from the base and have a range
    ' of 1000
     
    %QOS_GENERAL_ID_BASE = 2000
     
    %QOS_OBJECT_END_OF_LIST = &H00000001 + %QOS_GENERAL_ID_BASE
              ' QOS_End_of_list structure passed
    %QOS_OBJECT_SD_MODE = &H00000002 + %QOS_GENERAL_ID_BASE
              ' QOS_ShapeDiscard structure passed
    %QOS_OBJECT_SHAPING_RATE = &H00000003 + %QOS_GENERAL_ID_BASE
              ' QOS_ShapingRate structure
    %QOS_OBJECT_DESTADDR = &H00000004 + %QOS_GENERAL_ID_BASE
              ' QOS_DestAddr structure (defined in qossp.h)
    
     
    ' This structure is used to define the behaviour that the traffic
    ' control packet shaper will apply to the flow.
    '
    ' %TC_NONCONF_BORROW - the flow will receive resources remaining
    '  after all higher priority flows have been serviced. If a
    '  TokenRate is specified, packets may be non-conforming and
    '  will be demoted to less than best-effort priority.
    '
    ' %TC_NONCONF_SHAPE - TokenRate must be specified. Non-conforming
    '  packets will be retianed in the packet shaper until they become
    '  conforming.
    '
    ' %TC_NONCONF_DISCARD - TokenRate must be specified. Non-conforming
    '  packets will be discarded.
     
    Type QOS_SD_MODE Dword
      ObjectHdr As QOS_OBJECT_HDR
      ShapeDiscardMode As Dword
    End Type
     
    %TC_NONCONF_BORROW      = 0
    %TC_NONCONF_SHAPE       = 1
    %TC_NONCONF_DISCARD     = 2
    %TC_NONCONF_BORROW_PLUS = 3
     
    ' This structure allows an app to specify a prorated "average token rate" using
    ' by the traffic shaper under SHAPE modehaper queue. It is expressed in bytes
    ' per sec.
    '
    ' ShapingRate (bytes per sec.)
      
    Type QOS_SHAPING_RATE Dword
      ObjectHdr As QOS_OBJECT_HDR
      ShapingRate As Dword
    End Type
     
    #EndIf ' #IF NOT %DEF(%QOS_INC) -----------------------------------------------
     
    Type QOS
      SendingFlowspec As FLOWSPEC      ' the flow spec for data sending
      ReceivingFlowspec As FLOWSPEC    ' the flow spec for data receiving
      ProviderSpecific As WSABUF       ' additional provider-specific stuff
    End Type
     
    '------------------------------------------------------------------------------
    ' WinSock 2 ext. - Manifest constants for return values of condition function
    '------------------------------------------------------------------------------
    %CF_ACCEPT = &H0000
    %CF_REJECT = &H0001
    %CF_DEFER  = &H0002
    '------------------------------------------------------------------------------
    ' WinSock 2 ext. - Manifest constants for shutdown()
    '------------------------------------------------------------------------------
    %SD_RECEIVE = &H00
    %SD_SEND    = &H01
    %SD_BOTH    = &H02
    '------------------------------------------------------------------------------
    ' WinSock 2 extension -- data type and manifest constants for socket groups
    '------------------------------------------------------------------------------
    %SG_UNCONSTRAINED_GROUP = &H01
    %SG_CONSTRAINED_GROUP   = &H02
    '------------------------------------------------------------------------------
    ' WinSock 2 extension -- data type for WSAEnumNetworkEvents()
    '------------------------------------------------------------------------------
    Type WSANetWorkEvents
      lNetworkEvents As Long
      iErrorCode(%FD_MAX_EVENTS - 1) As Long
    End Type
     
    ' WinSock 2 extension -- WSAPROTOCOL_INFO structure and associated
    ' manifest constants
     
    #If Not %Def(%GUID_DEFINED)
      Type GUIDAPI
        Data1 As Dword
        Data2 As Word
        Data3 As Word
        Data4 As String * 8
      End Type
      %GUID_DEFINED = 1
    #EndIf
     
    %MAX_PROTOCOL_CHAIN = 7
    %BASE_PROTOCOL      = 1
    %LAYERED_PROTOCOL   = 0
     
    Type WSAPROTOCOLCHAIN
      ChainLen As Long    ' the length of the chain (=0, layered protocol; =1, base protocol; >1, protocol chain)
      ChainEntries(0 To %MAX_PROTOCOL_CHAIN - 1) As Dword   ' a list of dwCatalogEntryIds
    End Type
     
    %WSAPROTOCOL_LEN = 255
     
    Type WSAPROTOCOL_INFO
      dwServiceFlags1 As Dword
      dwServiceFlags2 As Dword
      dwServiceFlags3 As Dword
      dwServiceFlags4 As Dword
      dwProviderFlags As Dword
      ProviderId As GUIDAPI
      dwCatalogEntryId As Dword
      ProtocolChain As WSAPROTOCOLCHAIN
      iVersion As Long
      iAddressFamily As Long
      iMaxSockAddr As Long
      iMinSockAddr As Long
      iSocketType As Long
      iProtocol As Long
      iProtocolMaxOffset As Long
      iNetworkByteOrder As Long
      iSecurityScheme As Long
      dwMessageSize As Dword
      dwProviderReserved As Dword
      szProtocol As Asciiz * (%WSAPROTOCOL_LEN + 1)
    End Type
     
    ' Flag bit definitions for dwProviderFlags
    %PFL_MULTIPLE_PROTO_ENTRIES  = &H00000001
    %PFL_RECOMMENDED_PROTO_ENTRY = &H00000002
    %PFL_HIDDEN                  = &H00000004
    %PFL_MATCHES_PROTOCOL_ZERO   = &H00000008
     
    ' Flag bit definitions for dwServiceFlags1
    %XP1_CONNECTIONLESS           = &H00000001
    %XP1_GUARANTEED_DELIVERY      = &H00000002
    %XP1_GUARANTEED_ORDER         = &H00000004
    %XP1_MESSAGE_ORIENTED         = &H00000008
    %XP1_PSEUDO_STREAM            = &H00000010
    %XP1_GRACEFUL_CLOSE           = &H00000020
    %XP1_EXPEDITED_DATA           = &H00000040
    %XP1_CONNECT_DATA             = &H00000080
    %XP1_DISCONNECT_DATA          = &H00000100
    %XP1_SUPPORT_BROADCAST        = &H00000200
    %XP1_SUPPORT_MULTIPOINT       = &H00000400
    %XP1_MULTIPOINT_CONTROL_PLANE = &H00000800
    %XP1_MULTIPOINT_DATA_PLANE    = &H00001000
    %XP1_QOS_SUPPORTED            = &H00002000
    %XP1_INTERRUPT                = &H00004000
    %XP1_UNI_SEND                 = &H00008000
    %XP1_UNI_RECV                 = &H00010000
    %XP1_IFS_HANDLES              = &H00020000
    %XP1_PARTIAL_MESSAGE          = &H00040000
     
    %BIGENDIAN    = &H0000
    %LITTLEENDIAN = &H0001
     
    %SECURITY_PROTOCOL_NONE = &H0000
     
    ' WinSock 2 extension -- manifest constants for WSAJoinLeaf()
     
    %JL_SENDER_ONLY   = &H01
    %JL_RECEIVER_ONLY = &H02
    %JL_BOTH          = &H04
     
    ' WinSock 2 extension -- manifest constants for WSASocket()
     
    %WSA_FLAG_OVERLAPPED        = &H01
    %WSA_FLAG_MULTIPOINT_C_ROOT = &H02
    %WSA_FLAG_MULTIPOINT_C_LEAF = &H04
    %WSA_FLAG_MULTIPOINT_D_ROOT = &H08
    %WSA_FLAG_MULTIPOINT_D_LEAF = &H10
     
    ' WinSock 2 extension -- manifest constants for WSAIoctl()
     
    %IOC_UNIX     = &H00000000
    %IOC_WS2      = &H08000000
    %IOC_PROTOCOL = &H10000000
    %IOC_VENDOR   = &H18000000
     
    %SIOCSHIWAT                         = &H80047300
    %SIO_ASSOCIATE_HANDLE               = &H88000001
    %SIO_ENABLE_CIRCULAR_QUEUEING       = &H28000002
    %SIO_FIND_ROUTE                     = &H48000003
    %SIO_FLUSH                          = &H28000004
    %SIO_GET_BROADCAST_ADDRESS          = &H48000005
    %SIO_GET_EXTENSION_FUNCTION_POINTER = &HC8000006
    %SIO_GET_QOS                        = &HC8000007
    %SIO_GET_GROUP_QOS                  = &HC8000008
    %SIO_MULTIPOINT_LOOPBACK            = &H88000009
    %SIO_MULTICAST_SCOPE                = &H8800000A
    %SIO_SET_QOS                        = &H8800000B
    %SIO_SET_GROUP_QOS                  = &H8800000C
    %SIO_TRANSLATE_HANDLE               = &HC800000D
    %SIO_ROUTING_INTERFACE_QUERY        = &HC8000014
    %SIO_ROUTING_INTERFACE_CHANGE       = &H88000015
    %SIO_ADDRESS_LIST_QUERY             = &H48000016
    %SIO_ADDRESS_LIST_CHANGE            = &H28000017
    %SIO_QUERY_TARGET_PNP_HANDLE        = &H48000018
     
    ' WinSock 2 extension -- manifest constants for SIO_TRANSLATE_HANDLE ioctl
     
    %TH_NETDEV = &H00000001
    %TH_TAPI   = &H00000002
     
    ' Manifest constants and type definitions related to name resolution and
    ' registration (RNR) API
     
    #If Not %Def(%BLOB_DEFINED)
      %BLOB_DEFINED = 1
      Type BLOB
        cbSize As Dword
        pBlobData As Byte Ptr
      End Type
    #EndIf
     
    ' Service Install Flags
     
    %SERVICE_MULTIPLE       = &H00000001
     
    ' & Name Spaces
     
    %NS_ALL         = 0
     
    %NS_SAP         = 1
    %NS_NDS         = 2
    %NS_PEER_BROWSE = 3
    %NS_SLP         = 5
    %NS_DHCP        = 6
     
    %NS_TCPIP_LOCAL = 10
    %NS_TCPIP_HOSTS = 11
    %NS_DNS         = 12
    %NS_NETBT       = 13
    %NS_WINS        = 14
     
    %NS_NBP         = 20
     
    %NS_MS          = 30
    %NS_STDA        = 31
    %NS_NTDS        = 32
     
    %NS_X500        = 40
    %NS_NIS         = 41
    %NS_NISPLUS     = 42
     
    %NS_WRQ         = 50
     
    %NS_NETDES      = 60    ' Network Designers Limited
     
     
    ' Resolution flags for WSAGetAddressByName().
    ' Note these are also used by the 1.1 API GetAddressByName, so
    ' leave them around.
     
    %RES_UNUSED_1    = &H00000001
    %RES_FLUSH_CACHE = &H00000002
    #If Not %Def(%RES_SERVICE)
    %RES_SERVICE     = &H00000004
    #EndIf
     
    ' Well known value names for Service Types
     
    $SERVICE_TYPE_VALUE_IPXPORT  = "IpxSocket"
    $SERVICE_TYPE_VALUE_SAPID    = "SapId"
    $SERVICE_TYPE_VALUE_TCPPORT  = "TcpPort"
    $SERVICE_TYPE_VALUE_UDPPORT  = "UdpPort"
    $SERVICE_TYPE_VALUE_OBJECTID = "ObjectId"
     
    #If Not %Def(%CSADDR_DEFINED) '------------------------------------------------
     
    ' SockAddr Information
     
    Type SOCKET_ADDRESS
      lpSocaddr As SOCKADDR Ptr
      iSockaddrLength As Long
    End Type
     
    ' CSAddr Information
     
    Type CSADDR_INFO
      LocalAddr As SOCKET_ADDRESS
      RemoteAddr As SOCKET_ADDRESS
      iSocketType As Long
      iProtocol As Long
    End Type
     
    #EndIf ' #IF NOT %DEF(%CSADDR_DEFINED) ----------------------------------------
     
    ' Address list returned via SIO_ADDRESS_LIST_QUERY
     
    Type SOCKET_ADDRESS_LIST
      iAddressCount As Long
      Address(0 To 0) As SOCKET_ADDRESS
    End Type
     
    ' Address Family/Protocol Tuples
     
    Type AFPROTOCOLS
      iAddressFamily As Long
      iProtocol As Long
    End Type
     
    ' Client Query API Typedefs
     
    ' The comparators
     
    %COMP_EQUAL   = 0
    %COMP_NOTLESS = 1
     
    Type WSAVersion
      dwVersion As Dword
      ecHow As Long
    End Type
     
    Type WSAQUERYSET
      dwSize As Dword
      lpszServiceInstanceName As Asciiz Ptr
      lpServiceClassId As GUIDAPI Ptr
      lpVersion As WSAVERSION Ptr
      lpszComment As Asciiz Ptr
      dwNameSpace As Dword
      lpNSProviderId As GUIDAPI Ptr
      lpszContext As Asciiz Ptr
      dwNumberOfProtocols As Dword
      lpafpProtocols As AFPROTOCOLS Ptr
      lpszQueryString As Asciiz Ptr
      dwNumberOfCsAddrs As Dword
      lpcsaBuffer As CSADDR_INFO Ptr
      dwOutputFlags As Dword
      lpBlob As BLOB Ptr
    End Type
     
    %LUP_DEEP                = &H0001
    %LUP_CONTAINERS          = &H0002
    %LUP_NOCONTAINERS        = &H0004
    %LUP_NEAREST             = &H0008
    %LUP_RETURN_NAME         = &H0010
    %LUP_RETURN_TYPE         = &H0020
    %LUP_RETURN_VERSION      = &H0040
    %LUP_RETURN_COMMENT      = &H0080
    %LUP_RETURN_ADDR         = &H0100
    %LUP_RETURN_BLOB         = &H0200
    %LUP_RETURN_ALIASES      = &H0400
    %LUP_RETURN_QUERY_STRING = &H0800
    %LUP_RETURN_ALL          = &H0FF0
    %LUP_RES_SERVICE         = &H8000
     
    %LUP_FLUSHCACHE          = &H1000
    %LUP_FLUSHPREVIOUS       = &H2000
     
    ' Return flags
     
    %RESULT_IS_ALIAS      = &H0001
     
    ' Service Address Registration and Deregistration Data Types.
     
    %RNRSERVICE_REGISTER = 0
    %RNRSERVICE_DEREGISTER = 1
    %RNRSERVICE_DELETE = 2
     
    ' Service Installation/Removal Data Types.
     
    Type WSANSCLASSINFO
      lpszName As Asciiz Ptr
      dwNameSpace As Dword
      dwValueType As Dword
      dwValueSize As Dword
      lpValue As Byte Ptr
    End Type
     
    Type WSASERVICECLASSINFO
      lpServiceClassId As GUIDAPI Ptr
      lpszServiceClassName As Asciiz Ptr
      dwCount As Dword
      lpClassInfos As WSANSCLASSINFO Ptr
    End Type
     
    Type WSANAMESPACE_INFO
      NSProviderId As GUIDAPI
      dwNameSpace As Dword
      fActive As Long
      dwVersion As Dword
      lpszIdentifier As Asciiz Ptr
    End Type
    #EndIf
    %SOCKET_BUFFER_SIZE = 512
     
    %ICMP_ECHOREPLY =   0 'echo reply
    %ICMP_ECHOREQ   =   8 'echo request
     
     
    Type icmp_hdr
      icmp_type  As Byte
      icmp_code  As Byte
      icmp_cksum As Integer
      icmp_id    As Integer
      icmp_seq   As Integer
      icmp_data  As String * 1
    End Type
     
    Type ip_hdr
      ip_hlv   As Byte        ' header length + version (4 bits each)
      ip_tos   As Byte        ' type of service
      ip_len   As Word        ' total len
      ip_id    As Word        ' id
      ip_off   As Word        ' fragment offset
      ip_ttl   As Byte        ' time to live
      ip_p     As Byte        ' protocol
      ip_cksum As Word
      ip_src   As in_addr     ' source address
      ip_dest  As in_addr     ' dest address
    End Type
    '
    Type ICMP_OPTIONS
      Ttl             As Byte
      Tos             As Byte
      Flags           As Byte
      OptionsSize     As Byte
      OptionsData     As Long
    End Type
     
    Type ICMP_ECHO_REPLY
      Address         As Long
      Status          As Long
      RoundTripTime   As Long
      DataSize        As Integer
      Reserved        As Integer
      DataPointer     As Long
      Options         As ICMP_OPTIONS
      zData           As Asciiz * 250
    End Type
     
    #If (%INCL_WINSOCK_API_PROTOTYPES) '-------------------------------------------
     
    Declare Function IcmpCreateFile Lib "icmp.dll" Alias "IcmpCreateFile" () As Dword
    Declare Function IcmpCloseHandle Lib "icmp.dll" Alias "IcmpCloseHandle" (ByVal IcmpHandle As Dword) As Long
    Declare Function IcmpSendEcho Lib "icmp.dll" Alias "IcmpSendEcho" (ByVal IcmpHandle As Dword, ByVal DestinationAddress As Long, RequestData As Asciiz, ByVal RequestSize As Word, RequestOptions As Any, ReplyBuffer As Any, _
        ByVal ReplySize As Dword, ByVal Tymeout As Dword) As Dword
     
    #If %Def(%WSOCK32)
    Declare Function aaccept Lib "wsock32.dll" Alias "accept" (ByVal s As Dword, address As Any, addrlen As Long) As Dword
    Declare Function bind Lib "wsock32.dll" Alias "bind" (ByVal s As Dword, address As Any, ByVal namelen As Long) As Long
    Declare Function closesocket Lib "wsock32.dll" Alias "closesocket" (ByVal s As Dword) As Long
    Declare Function cconnect Lib "wsock32.dll" Alias "connect" (ByVal s As Dword, address As Any, ByVal namelen As Long) As Long
    Declare Function ioctlsocket Lib "wsock32.dll" Alias "ioctlsocket" (ByVal s As Dword, ByVal cmd As Long, argp As Dword) As Long
    Declare Function getpeername Lib "wsock32.dll" Alias "getpeername" (ByVal s As Dword, sname As Any, namelen As Long) As Long
    Declare Function getsockname Lib "wsock32.dll" Alias "getsockname" (ByVal s As Dword, sname As Any, namelen As Long) As Long
    Declare Function getsockopt Lib "wsock32.dll" Alias "getsockopt" (ByVal s As Dword, ByVal level As Long, ByVal optname As Long, optval As Any, optlen As Long) As Long
    Declare Function htonl Lib "wsock32.dll" Alias "htonl" (ByVal hostlong As Dword) As Dword
    Declare Function htons Lib "wsock32.dll" Alias "htons" (ByVal hostshort As Word) As Word
    Declare Function inet_addr Lib "wsock32.dll" Alias "inet_addr" (cp As Asciiz) As Dword
    Declare Function inet_ntoa Lib "wsock32.dll" Alias "inet_ntoa" (ByVal inn As Long) As Long
    Declare Function listen Lib "wsock32.dll" Alias "listen" (ByVal s As Dword, ByVal backlog As Long) As Long
    Declare Function ntohl Lib "wsock32.dll" Alias "ntohl" (ByVal netlong As Dword) As Dword
    Declare Function ntohs Lib "wsock32.dll" Alias "ntohs" (ByVal netshort As Word) As Word
    Declare Function rrecv Lib "wsock32.dll" Alias "recv" (ByVal s As Dword, buf As Any, ByVal buflen As Long, ByVal flags As Long) As Long
    Declare Function recvfrom Lib "wsock32.dll" Alias "recvfrom" (ByVal s As Dword, buf As Any, ByVal buflen As Long, ByVal flags As Long, Sockstruct As Any, strulen As Long) As Long
    Declare Function ssend Lib "wsock32.dll" Alias "send" (ByVal s As Dword, buf As Any, ByVal buflen As Long, ByVal flags As Long) As Long
    Declare Function sendto Lib "wsock32.dll" Alias "sendto" (ByVal s As Dword, buf As Any, ByVal buflen As Long, ByVal flags As Long, to_addr As Any, ByVal tolen As Long) As Long
    Declare Function setsockopt Lib "wsock32.dll" Alias "setsockopt" (ByVal s As Dword, ByVal level As Long, ByVal optname As Long, optval As Any, ByVal optlen As Long) As Long
    Declare Function shutdown Lib "wsock32.dll" Alias "shutdown" (ByVal s As Dword, ByVal how As Long) As Long
    Declare Function socket Lib "wsock32.dll" Alias "socket" (ByVal af As Long, ByVal s_type As Long, ByVal protocol As Long) As Dword
    Declare Function sselect Lib "wsock32.dll" Alias "select" (ByVal nfds As Long, readfds As fd_setstruc, writefds As fd_setstruc, exceptfds As fd_setstruc, Tymeout As timeval) As Long
     
    'DATABASE FUNCTIONS
    Declare Function gethostbyaddr Lib "wsock32.dll"  Alias "gethostbyaddr" (address As Asciiz, ByVal addr_len As Long, ByVal addr_type As Long) As Dword
    Declare Function gethostbyname Lib "wsock32.dll" Alias "gethostbyname" (ost_name As Asciiz) As Dword
    Declare Function gethostname Lib "wsock32.dll" Alias "gethostname" (host_name As Asciiz, ByVal namelen As Long) As Long
    Declare Function getprotobyname Lib "wsock32.dll" Alias "getprotobyname" (proto_name As Asciiz) As Dword
    Declare Function getprotobynumber Lib "wsock32.dll" Alias "getprotobynumber" (ByVal proto As Long) As Dword
    Declare Function getservbyname Lib "wsock32.dll" Alias "getservbyname" (serv_name As Asciiz, proto As Asciiz) As Dword
    Declare Function getservbyport Lib "wsock32.dll" Alias "getservbyport" (ByVal lPort As Long, proto As Asciiz) As Dword
     
    'WINDOWS EXTENSIONS
    Declare Function WSAAsyncSelect Lib "wsock32.dll" Alias "WSAAsyncSelect" (ByVal s As Dword, ByVal hWnd As Dword, ByVal wMsg As Dword, ByVal lEvent As Long) As Long
    Declare Function WSACancelBlockingCall Lib "wsock32.dll" Alias "WSACancelBlockingCall" () As Long
    Declare Function WSACleanup Lib "wsock32.dll" Alias "WSACleanup" () As Long
    Declare Function WSAGetLastError Lib "wsock32.dll" Alias "WSAGetLastError" () As Long
    Declare Function WSAIsBlocking Lib "wsock32.dll" Alias "WSAIsBlocking" () As Long
    Declare Function WSARecvEx Lib "wsock32.dll" Alias "WSARecvEx" (ByVal s As Dword, buf As Any, ByVal buflen As Long, ByVal flags As Long) As Long
    Declare Function WSASetBlockingHook Lib "wsock32.dll" Alias "WSASetBlockingHook" (ByVal lpBlockFunc As Dword) As Dword
    Declare Function WSAStartup Lib "wsock32.dll" Alias "WSAStartup" (ByVal wVR As Word, lpWSAD As WSAData) As Long
    Declare Function WSAUnhookBlockingHook Lib "wsock32.dll" Alias "WSAUnhookBlockingHook" () As Long
    Declare Sub WSASetLastError Lib "wsock32.dll" Alias "WSASetLastError" (ByVal iError As Long)
     
    'WSAASYNCGETXBYY FUNCTIONS DON'T WORK RELIABLY UNDER 32BIT WINDOWS
    Declare Function WSAAsyncGetServByName Lib "wsock32.dll" Alias "WSAAsyncGetServByName" (ByVal hWnd As Dword, ByVal wMsg As Dword, serv_name As Asciiz, proto As Asciiz, buf As Asciiz, ByVal buflen As Long) As Dword
    Declare Function WSAAsyncGetServByPort Lib "wsock32.dll" Alias "WSAAsyncGetServByPort" (ByVal hWnd As Dword, ByVal wMsg As Dword, ByVal lPort As Long, proto As Asciiz, buf As Asciiz, ByVal buflen As Long) As Dword
    Declare Function WSAAsyncGetProtoByName Lib "wsock32.dll" Alias "WSAAsyncGetProtoByName" (ByVal hWnd As Dword, ByVal wMsg As Dword, proto_name As Asciiz, buf As Asciiz, ByVal buflen As Long) As Dword
    Declare Function WSAAsyncGetProtoByNumber Lib "wsock32.dll" Alias "WSAAsyncGetProtoByNumber" (ByVal hWnd As Dword, ByVal wMsg As Dword, ByVal number As Long, buf As Asciiz, ByVal buflen As Long) As Dword
    Declare Function WSAAsyncGetHostByName Lib "wsock32.dll" Alias "WSAAsyncGetHostByName" (ByVal hWnd As Dword, ByVal wMsg As Dword, host_name As Asciiz, buf As Asciiz, ByVal buflen As Long) As Dword
    Declare Function WSAAsyncGetHostByAddr Lib "wsock32.dll" Alias "WSAAsyncGetHostByAddr" (ByVal hWnd As Dword, ByVal wMsg As Dword, address As Asciiz, ByVal addr_len As Long, ByVal addr_type As Long, buf As Asciiz, ByVal buflen As Long) As Dword
    Declare Function WSACancelAsyncRequest Lib "wsock32.dll" Alias "WSACancelAsyncRequest" (ByVal hAsyncTaskHandle As Dword) As Long
     
    #Else
     
    Declare Function aaccept Lib "ws2_32.dll" Alias "accept" (ByVal s As Dword, saAddr As Any, addrlen As Long) As Dword
    Declare Function bind Lib "ws2_32.dll" Alias "bind" (ByVal s As Dword, sname As Any, ByVal namelen As Long) As Long
    Declare Function closesocket Lib "ws2_32.dll" Alias "closesocket" (ByVal s As Dword) As Long
    Declare Function cconnect Lib "ws2_32.dll" Alias "connect" (ByVal s As Dword, sname As Any, ByVal namelen As Long) As Long
    Declare Function ioctlsocket Lib "ws2_32.dll" Alias "ioctlsocket" (ByVal s As Dword, ByVal cmd As Long, argp As Dword) As Long
    Declare Function getpeername Lib "ws2_32.dll" Alias "getpeername" (ByVal s As Dword, sname As Any, namelen As Long) As Long
    Declare Function getsockname Lib "ws2_32.dll" Alias "getsockname" (ByVal s As Dword, sname As Any, namelen As Long) As Long
    Declare Function getsockopt Lib "ws2_32.dll" Alias "getsockopt" (ByVal s As Dword, ByVal level As Long, ByVal optname As Long, optval As Any, optlen As Long) As Long
    Declare Function htonl Lib "ws2_32.dll" Alias "htonl" (ByVal hostlong As Dword) As Dword
    Declare Function htons Lib "ws2_32.dll" Alias "htons" (ByVal hostshort As Word) As Word
    Declare Function inet_addr Lib "ws2_32.dll" Alias "inet_addr" (cp As Asciiz) As Dword
    Declare Function inet_ntoa Lib "ws2_32.dll" Alias "inet_ntoa" (inn As Long) As Long
    Declare Function listen Lib "ws2_32.dll" Alias "listen" (ByVal s As Dword, ByVal backlog As Long) As Long
    Declare Function ntohl Lib "ws2_32.dll" Alias "ntohl" (ByVal netlong As Dword) As Dword
    Declare Function ntohs Lib "ws2_32.dll" Alias "ntohs" (ByVal netshort As Word) As Word
    Declare Function rrecv Lib "ws2_32.dll" Alias "recv" (ByVal s As Dword, buf As Any, ByVal buflen As Long, ByVal flags As Long) As Long
    Declare Function recvfrom Lib "ws2_32.dll" Alias "recvfrom" (ByVal s As Dword, buf As Any, ByVal buflen As Long, ByVal flags As Long, saFrom As Any, fromlen As Long) As Long
    Declare Function sselect Lib "ws2_32.dll" Alias "select" (ByVal nfds As Long, readfds As fd_setstruc, writefds As fd_setstruc, exceptfds As FD_SETstruc, tymeout As timeval) As Long
    Declare Function ssend Lib "ws2_32.dll" Alias "send" (ByVal s As Dword, buf As Any, ByVal buflen As Long, ByVal flags As Long) As Long
    Declare Function sendto Lib "ws2_32.dll" Alias "sendto" (ByVal s As Dword, buf As Any, ByVal buflen As Long, ByVal flags As Long, to_addr As Any, ByVal tolen As Long) As Long
    Declare Function setsockopt Lib "ws2_32.dll" Alias "setsockopt" (ByVal s As Dword, ByVal level As Long, ByVal optname As Long, optval As Any, ByVal optlen As Long) As Long
    Declare Function shutdown Lib "ws2_32.dll" Alias "shutdown" (ByVal s As Dword, ByVal how As Long) As Long
    Declare Function socket Lib "ws2_32.dll" Alias "socket" (ByVal af As Long, ByVal s_type As Long, ByVal protocol As Long) As Dword
     
    ' Database function prototypes
    Declare Function gethostbyaddr Lib "ws2_32.dll"  Alias "gethostbyaddr" (saAddr As Any, ByVal addr_len As Long, ByVal addr_type As Long) As Dword
    Declare Function gethostbyname Lib "ws2_32.dll" Alias "gethostbyname" (hname As Asciiz) As Dword
    Declare Function gethostname Lib "ws2_32.dll" Alias "gethostname" (host_name As Asciiz, ByVal namelen As Long) As Long
    Declare Function getservbyport Lib "ws2_32.dll" Alias "getservbyport" (ByVal lPort As Long, proto As Asciiz) As Dword
    Declare Function getservbyname Lib "ws2_32.dll" Alias "getservbyname" (serv_name As Asciiz, proto As Asciiz) As Dword
    Declare Function getprotobynumber Lib "ws2_32.dll" Alias "getprotobynumber" (ByVal proto As Long) As Dword
    Declare Function getprotobyname Lib "ws2_32.dll" Alias "getprotobyname" (proto_name As Asciiz) As Dword
     
    ' Microsoft Windows Extension function prototypes
     
    Declare Function WSAStartup Lib "ws2_32.dll" Alias "WSAStartup" (ByVal wVR As Word, lpWSAD As WSADATA) As Long
    Declare Function WSACleanup Lib "ws2_32.dll" Alias "WSACleanup" () As Long
    Declare Sub WSASetLastError Lib "ws2_32.dll" Alias "WSASetLastError" (ByVal iError As Long)
    Declare Function WSAGetLastError Lib "ws2_32.dll" Alias "WSAGetLastError" () As Long
    Declare Function WSAIsBlocking Lib "ws2_32.dll" Alias "WSAIsBlocking" () As Long
    Declare Function WSAUnhookBlockingHook Lib "ws2_32.dll" Alias "WSAUnhookBlockingHook" () As Long
    Declare Function WSASetBlockingHook Lib "ws2_32.dll" Alias "WSASetBlockingHook" (ByVal lpBlockFunc As Dword) As Dword
    Declare Function WSACancelBlockingCall Lib "ws2_32.dll" Alias "WSACancelBlockingCall" () As Long
    Declare Function WSAAsyncGetServByName Lib "ws2_32.dll" Alias "WSAAsyncGetServByName" (ByVal hWnd As Dword, ByVal wMsg As Dword, serv_name As Asciiz, proto As Asciiz, buf As Asciiz, ByVal buflen As Long) As Dword
    Declare Function WSAAsyncGetServByPort Lib "ws2_32.dll" Alias "WSAAsyncGetServByPort" (ByVal hWnd As Dword, ByVal wMsg As Dword, ByVal lPort As Long, proto As Asciiz, buf As Asciiz, ByVal buflen As Long) As Dword
    Declare Function WSAAsyncGetProtoByName Lib "ws2_32.dll" Alias "WSAAsyncGetProtoByName" (ByVal hWnd As Dword, ByVal wMsg As Dword, proto_name As Asciiz, buf As Asciiz, ByVal buflen As Long) As Dword
    Declare Function WSAAsyncGetProtoByNumber Lib "ws2_32.dll" Alias "WSAAsyncGetProtoByNumber" (ByVal hWnd As Dword, ByVal wMsg As Dword, ByVal number As Long, buf As Asciiz, ByVal buflen As Long) As Dword
    Declare Function WSAAsyncGetHostByName Lib "ws2_32.dll" Alias "WSAAsyncGetHostByName" (ByVal hWnd As Dword, ByVal wMsg As Dword, host_name As Asciiz, buf As Asciiz, ByVal buflen As Long) As Dword
    Declare Function WSAAsyncGetHostByAddr Lib "ws2_32.dll" Alias "WSAAsyncGetHostByAddr" (ByVal hWnd As Dword, ByVal wMsg As Dword, address As Asciiz, ByVal addr_len As Long, ByVal addr_type As Long, buf As Asciiz, ByVal buflen As Long) As Dword
    Declare Function WSACancelAsyncRequest Lib "ws2_32.dll" Alias "WSACancelAsyncRequest" (ByVal hAsyncTaskHandle As Dword) As Long
    Declare Function WSAAsyncSelect Lib "ws2_32.dll" Alias "WSAAsyncSelect" (s As Dword, ByVal hWnd As Dword, ByVal wMsg As Dword, ByVal lEvent As Long) As Long
     
    ' WinSock 2 API new function prototypes
     
    Declare Function WSAAccept Lib "ws2_32.dll" Alias "WSAAccept" (ByVal s As Dword, saAddr As SOCKADDR, addrlen As Long, lpfnCondition As Dword, dwCallbackData As Dword) As Dword
    Declare Function WSACloseEvent Lib "ws2_32.dll" Alias "WSACloseEvent" (ByVal h As Dword) As Long
    Declare Function WSAConnect Lib "ws2_32.dll" Alias "WSAConnect" (ByVal s As Dword, sname As SOCKADDR, ByVal namelen As Long, lpCallerData As WSABUF, lpCalleeData As WSABUF, lpSQOS As QOS, lpGQOS As QOS) As Long
    Declare Function WSACreateEvent Lib "ws2_32.dll" Alias "WSACreateEvent" () As Dword
    Declare Function WSADuplicateSocket Lib "ws2_32.dll" Alias "WSADuplicateSocketA" (ByVal s As Dword, ByVal dwProcessId As Dword, lpProtocolInfo As WSAPROTOCOL_INFO) As Long
    Declare Function WSAEnumNetworkEvents Lib "ws2_32.dll" Alias "WSAEnumNetworkEvents" (ByVal s As Dword, ByVal hEventObject As Dword, lpNetworkEvents As WSANETWORKEVENTS) As Long
    Declare Function WSAEnumProtocols Lib "ws2_32.dll" Alias "WSAEnumProtocolsA" (lpiProtocols As Long, lpProtocolBuffer As WSAPROTOCOL_INFO, lpdwBufferLength As Dword) As Long
    Declare Function WSAEventSelect Lib "ws2_32.dll" Alias "WSAEventSelect" (ByVal s As Dword, ByVal hEventObject As Dword, ByVal lNetworkEvents As Long) As Long
    Declare Function WSAGetOverlappedResult Lib "ws2_32.dll" Alias "WSAGetOverlappedResult" (ByVal s As Dword, lpOverlapped As OVERLAPPED, lpcbTransfer As Dword, ByVal fWait As Long, lpdwFlags As Dword) As Long
    Declare Function WSAGetQOSByName Lib "ws2_32.dll" Alias "WSAGetQOSByName" (ByVal s As Dword, lpQOSName As WSABUF, lpQOS As QOS) As Long
    Declare Function WSAHtonl Lib "ws2_32.dll" Alias "WSAHtonl" (ByVal s As Dword, ByVal hostlong As Dword, lpnetlong As Dword) As Long
    Declare Function WSAHtons Lib "ws2_32.dll" Alias "WSAHtons" (ByVal s As Dword, ByVal hostshort As Word, lpnetshort As Word) As Long
    Declare Function WSAIoctl Lib "ws2_32.dll" Alias "WSAIoctl" (ByVal s As Dword, ByVal dwIoControlCode As Dword, lpvInBuffer As Dword, ByVal cbInBuffer As Dword, lpvOutBuffer As Dword, ByVal cbOutBuffer As Dword, _
        lpcbBytesReturned As Dword, lpOverlapped As OVERLAPPED, lpCompletionRoutine As Dword) As Long
    Declare Function WSAJoinLeaf Lib "ws2_32.dll" Alias "WSAJoinLeaf" (ByVal s As Dword, sname As SOCKADDR, ByVal namelen As Long, lpCallerData As WSABUF, lpCalleeData As WSABUF, lpSQOS As QOS, lpGQOS As QOS, ByVal dwFlags As Dword) As Dword
    Declare Function WSANtohl Lib "ws2_32.dll" Alias "WSANtohl" (ByVal s As Dword, ByVal netlong As Dword, lphostlong As Dword) As Long
    Declare Function WSANtohs Lib "ws2_32.dll" Alias "WSANtohs" (ByVal s As Dword, ByVal netshort As Word, lphostshort As Word) As Long
    Declare Function WSARecv Lib "ws2_32.dll" Alias "WSARecv" (ByVal s As Dword, lpBuffers As WSABUF, ByVal dwBufferCount As Dword, lpNumberOfBytesRecvd As Dword, lpFlags As Dword, lpOverlapped As OVERLAPPED, _
        ByVal lpCompletionRoutine As Dword) As Long
    Declare Function WSARecvDisconnect Lib "ws2_32.dll" Alias "WSARecvDisconnect" (ByVal s As Dword, lpInboundDisconnectData As WSABUF) As Long
    Declare Function WSARecvFrom Lib "ws2_32.dll" Alias "WSARecvFrom" (ByVal s As Dword, lpBuffers As WSABUF, ByVal dwBufferCount As Dword, lpNumberOfBytesRecvd As Dword, lpFlags As Dword, lpFrom As SOCKADDR, _
        lpFromlen As Long, lpOverlapped As OVERLAPPED, ByVal lpCompletionRoutine As Dword) As Long
    Declare Function WSAResetEvent Lib "ws2_32.dll" Alias "WSAResetEvent" (ByVal hEvent As Dword) As Long
    Declare Function WSASend Lib "ws2_32.dll" Alias "WSASend" (ByVal s As Dword, lpBuffers As WSABUF, ByVal dwBufferCount As Dword, lpNumberOfBytesSent As Dword, ByVal dwFlags As Dword, lpOverlapped As OVERLAPPED, _
        ByVal lpCompletionRoutine As Dword) As Long
    Declare Function WSASendDisconnect Lib "ws2_32.dll" Alias "WSASendDisconnect" (ByVal s As Dword, lpOutboundDisconnectData As WSABUF) As Long
    Declare Function WSASendTo Lib "ws2_32.dll" Alias "WSASendTo" (ByVal s As Dword, lpBuffers As WSABUF, ByVal dwBufferCount As Dword, lpNumberOfBytesSent As Dword, ByVal dwFlags As Dword, lpTo As SOCKADDR, ByVal iTolen As Long, _
        lpOverlapped As OVERLAPPED, ByVal lpCompletionRoutine As Dword) As Long
    Declare Function WSASetEvent Lib "ws2_32.dll" Alias "WSASetEvent" (ByVal hEvent As Dword) As Long
    Declare Function WSASocket Lib "ws2_32.dll" Alias "WSASocketA" (ByVal af As Long, ByVal ltype As Long, ByVal protocol As Long, lpProtocolInfo As WSAPROTOCOL_INFO, ByVal g As Dword, ByVal dwFlags As Dword) As Dword
    Declare Function WSAWaitForMultipleEvents Lib "ws2_32.dll" Alias "WSAWaitForMultipleEvents" (ByVal cEvents As Dword, ByVal lphEvents As Dword Ptr, ByVal fWaitAll As Long, ByVal dwTimeout As Dword, ByVal fAlertable As Long) As Dword
    Declare Function WSAAddressToString Lib "ws2_32.dll" Alias "WSAAddressToStringA" (lpsaAddress As SOCKADDR, ByVal dwAddressLength As Dword, lpProtocolInfo As WSAPROTOCOL_INFO, lpszAddressString As Asciiz, _
        lpdwAddressStringLength As Dword) As Long
    Declare Function WSAStringToAddress Lib "ws2_32.dll" Alias "WSAStringToAddressA" (AddressString As Asciiz, ByVal AddressFamily As Long, lpProtocolInfo As WSAPROTOCOL_INFO, lpAddress As SOCKADDR, lpAddressLength As Long) As Long
     
    ' Registration and Name Resolution API functions
     
    Declare Function WSALookupServiceBegin Lib "ws2_32.dll" Alias "WSALookupServiceBeginA" (lpqsRestrictions As WSAQUERYSET, ByVal dwControlFlags As Dword, lphLookup As Dword) As Long
    Declare Function WSALookupServiceNext Lib "ws2_32.dll" Alias "WSALookupServiceNextA" (ByVal hLookup As Dword, ByVal dwControlFlags As Dword, lpdwBufferLength As Dword, lpsqResults As WSAQUERYSET) As Long
    Declare Function WSALookupServiceEnd Lib "ws2_32.dll" Alias "WSALookupServiceEnd" (ByVal hLookup As Dword) As Long
    Declare Function WSAInstallServiceClass Lib "ws2_32.dll" Alias "WSAInstallServiceClassA" (lpServiceClassInfo As WSASERVICECLASSINFO) As Long
    Declare Function WSARemoveServiceClass Lib "ws2_32.dll" Alias "WSARemoveServiceClass" (lpServiceClassId As GUIDAPI) As Long
    Declare Function WSAGetServiceClassInfo Lib "ws2_32.dll" Alias "WSAGetServiceClassInfoA" (lpProviderId As GUIDAPI, lpServiceClassId As GUIDAPI, lpdwBufSize As Dword, lpServiceClassInfo As WSASERVICECLASSINFO) As Long
    Declare Function WSAEnumNameSpaceProviders Lib "ws2_32.dll" Alias "WSAEnumNameSpaceProvidersA" (lpdwBufferLength As Dword, lpnspBuffer As WSANAMESPACE_INFO) As Long
    Declare Function WSAGetServiceClassNameByClassId Lib "ws2_32.dll" Alias "WSAGetServiceClassNameByClassIdA" (lpServiceClassId As GUIDAPI, lpszServiceClassName As Asciiz, lpdwBufferLength As Dword) As Long
    Declare Function WSASetService Lib "ws2_32.dll" Alias "WSASetServiceA" (lpqsRegInfo As WSAQUERYSET, ByVal essoperation As Long, ByVal dwControlFlags As Dword) As Long
    Declare Function WSAProviderConfigChange Lib "ws2_32.dll" Alias "WSAProviderConfigChange" (lpNotificationHandle As Dword, lpOverlapped As OVERLAPPED, ByVal lpCompletionRoutine As Dword) As Long
    #EndIf ' #IF (%WSOCK32)
    #EndIf ' #IF (%INCL_WINSOCK_API_PROTOTYPES) -----------------------------------
     
    '------------------------------------------------------------------------------
     
    Function h_errno () As Long
      Function = WSAGetLastError
    End Function
    '------------------------------------------------------------------------------
    ' Windows message parameter composition and decomposition macros.
    '------------------------------------------------------------------------------
    ' WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
    ' when constructing the response to a WSAAsyncGetXByY() routine.
    '------------------------------------------------------------------------------
    Function WSAMAKEASYNCREPLY (ByVal wbuflen As Word, ByVal werror As Word) As Long
      Function = MakLng(wbuflen,werror)
    End Function
    '------------------------------------------------------------------------------
    ' WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
    ' when constructing the response to WSAAsyncSelect().
    '------------------------------------------------------------------------------
    Function WSAMAKESELECTREPLY (ByVal wevent As Word, ByVal werror As Word) As Long
      Function = MakLng(wevent,werror)
    End Function
    '------------------------------------------------------------------------------
    ' WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application to
    ' extract buffer length from the lParam in the response to a WSAAsyncGetXByY().
    '------------------------------------------------------------------------------
    Function WSAGETASYNCBUFLEN (ByVal lParam As Long) As Word
      Function = LoWrd(lParam)
    End Function
    '------------------------------------------------------------------------------
    ' WSAGETASYNCERROR is intended for use by the Windows Sockets application to
    ' extract the error code from the lParam in the response to a WSAGetXByY().
    '------------------------------------------------------------------------------
    Function WSAGETASYNCERROR (ByVal lParam As Long) As Word
      Function = HiWrd(lParam)
    End Function
    '------------------------------------------------------------------------------
    ' WSAGETSELECTEVENT is intended for use by the Windows Sockets application to
    ' extract the event code from the lParam in the response to a WSAAsyncSelect().
    '------------------------------------------------------------------------------
    Function WSAGETSELECTEVENT (ByVal lParam As Long) As Word
      Function = LoWrd(lParam)
    End Function
    '------------------------------------------------------------------------------
    ' WSAGETSELECTERROR is intended for use by the Windows Sockets application to
    ' extract the error code from the lParam in the response to a WSAAsyncSelect().
    '------------------------------------------------------------------------------
    Function WSAGETSELECTERROR (ByVal lParam As Long) As Word
      Function = HiWrd(lParam)
    End Function
    '------------------------------------------------------------------------------
    'Return a pointer to all of the host IP addresses
    '------------------------------------------------------------------------------
    Function GetHostAddr () As Dword
        Dim hhostent As hostent Ptr
        Dim hostname As Asciiz * 32
        Dim result As Long
        result = GetHostName(hostname, SizeOf(hostname))
        If result Then
            If Len(hostname) Then
                hhostent = GetHostByName(hostname)
                If hhostent Then
                    Function = @hhostent.h_list
                End If
            End If
        End If
    End Function
     
    #EndIf ' %IF Not %Def(%WSOCK_X_INC)
    ------------------
    Regards,
    Peter

    ------------------
    Regards,
    Peter
    Regards,
    Peter

    Comment

    Working...
    X