Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

getaddrinfo

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

  • getaddrinfo

    Does anyone have an example of this ws2_32.dll function? I cant even get it declared properly.

    Thanks
    Rick

  • #2
    The following is some of my production code that uses "getaddrinfo()". Feel free to use, modify, do whatever, with the code provided. Any questions, just ask, but it's been ages since I came up with the code, so it might take a while so I can research it again before I can answer.

    Code:
    FUNCTION GetIpAddresses2 (optional byval count as long, byval B as string) EXPORT AS STRING
        function = ""
        if B = "" then B = gethostname2
        if B = "" then exit function
        if count < 1 then count = %maxlong
        local xptr1 as hostent ptr, xptr2 as hostent ptr
        local L as long
        local s1 as string, s2 as string, s3 as string
        local htcp as dword
        local L135 as long
        local flag as long
        local L1 as long
        local flag4 as long
        local count2 as long
        count2 = count
        xptr1 = gethostbyname(bycopy B)
        if xptr1 then
            count = count2
            reset L
            do
                reset flag4
                if @[email protected]@h_list[L] = 0 then exit do
                s3 = iptostring(@[email protected]@h_list[L])
                xptr2 = gethostbyaddr(@[email protected]@h_list[L], 4, %af_inet)
                if xptr2 then
                    if @xptr2.h_addr = %af_inet then
                        s2 = s2 + s3 + crlf
                        decr count
                        if count = 0 then
                            exit do
                        end if
                        flag4 = -1
                    end if
                end if
                incr L
            loop
        end if
        s2 = trim2(s2, crlf())
        if count2 <> %maxlong then
            s2 = parse2(s2, count2, crlf())
        end if
        function = s2
    end function
    
    TYPE addrinfo
        ai_flags as long
        ai_family as long
        ai_sockettype as long
        ai_protocol as long
        ai_addrlen as long
        ai_canonname as asciiz ptr
        ai_addr as sockaddr ptr
        ai_next as addrinfo ptr
    END TYPE
    
    declare function getaddrinfo2 (asciiz, asciiz, addrinfo, byval paddrinfo as addrinfo ptr) as long
    
    declare sub freeaddrinfo2 (byval paddrinfo as addrinfo ptr)
    
    FUNCTION GetIpAddresses (optional byval count as long, byval B as string) EXPORT AS STRING
        function = ""
        if turnonwsa() then exit function
        if windowsversion > -5.01## then function = getipaddresses2(count, B) : exit function
        local L1 as long, s1 as string, A as long, L2 as long, flag as long, s2 as string
        local xptr as hostent ptr, xptr2 as hostent ptr
        local hproc as dword, s3 as string
        local htcp as dword
        if B = "" then B = gethostname2
        if B = "" then exit function
        if count < 1 then count = %maxlong
        local count2 as long
        count2 = count
        hproc = gpa("ws2_32.dll", "getaddrinfo")
        if hproc = 0 then exit function
        local x as addrinfo, x1 as sockaddr, paddrinfo1 as addrinfo ptr, d as dword
        x.ai_family = %af_inet
        s1 = string$(100000, 0)
        paddrinfo1 = strptr(s1)
        d = varptr(paddrinfo1)
        call dword hproc using getaddrinfo2 (bycopy B, "", x, byval d) to L1
        if L1 = 0 then
            copymemory varptr(x), byval paddrinfo1, len(x)
            do
                if x.ai_addr then
                    if [email protected]_addr.sa_family = %af_inet then
                        s3 = iptostring(cvl(mid$([email protected]_addr.sa_data, 3)))
                        s2 = s2 + crlf() + s3
                        decr count
                        if count = 0 then
                            exit do
                        end if
                    end if
                end if
                if x.ai_next = 0 then exit do
                copymemory varptr(x), byval x.ai_next, len(x)
            loop
            hproc = gpa("ws2_32.dll", "freeaddrinfo")
            if hproc = 0 then exit function
            call dword hproc using freeaddrinfo2 (paddrinfo1)
        end if
        s2 = trim2(s2, crlf())
        if count2 <> %maxlong then
            s2 = parse2(s2, count2, crlf())
        end if
        function = s2
    END FUNCTION
    
    function IpToString (BYVAL A AS long) EXPORT AS STRING
        function = ""
        if A = 0 then exit function
        LOCAL s AS STRING, bptr AS BYTE PTR
        bptr = VARPTR(A)
        s = USING$("#_.#_.#_.#", @bptr[0], @bptr[1], @bptr[2], @bptr[3])
        FUNCTION = s
    END FUNCTION

    Comment


    • #3
      moving right along!

      Thanks Clay,

      That was a huge help. I just couldn't get the getaddrinfo function declared at all. Your example got me that far. Now I'm stuck on my next point. (It's a never ending story w/me!)

      I have the function declared and I can call it. It returns successfully. But I don't seem to be getting the data I think should be returned in the "TYPE addrinfo" structure.

      The flags returned don't seem to be logical, and I can't get it to return anything in the ai_canonname field.

      Also. it returns in a linked list. I think I should be getting more links. I only get one, the original.

      Here is my "code". See what you think.

      Thanks for the help.

      Code:
      #COMPILE EXE
      #DIM ALL
      #INCLUDE "Winsock_X.INC"
      
      %dbug = 1  ' 1 to use dbug, 0 to disuse
      
      'define UDTs here, can't do it in a function/sub
      
      '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      'used for getaddrinfo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
          TYPE aiHints
              ai_flags AS INTEGER
              ai_family AS INTEGER
              ai_socktype AS INTEGER
              ai_protocol AS INTEGER
          END TYPE
      
          TYPE addrinfo
              ai_flags AS LONG
              ai_family AS LONG
              ai_sockettype AS LONG
              ai_protocol AS LONG
              ai_addrlen AS LONG
              ai_canonname AS ASCIIZ PTR
              ai_addr AS sockaddr PTR
              ai_next AS addrinfo PTR
          END TYPE
      
          'ai_flags - Flags that indicate options used in the getaddrinfo function.
          %AI_PASSIVE                 =     &h01  ' The socket address will be used in a call to the bind  function.
          %AI_CANONNAME               =     &h02  ' The canonical name is returned in the first ai_canonname member.
          %AI_NUMERICHOST             =     &h04  ' The nodename parameter passed to the getaddrinfo function must be a numeric string.
          %AI_ADDRCONFIG              =   &h0400  ' (Vista or later)The getaddrinfo will resolve only if a global address is configured. The IPv6 and IPv4 loopback address is not considered a valid global address.
          %AI_NON_AUTHORITATIVE       =  &h04000  ' (Vista or later)The address information can be from a non-authoritative namespace provider. Windows Vista or later for the NS_EMAIL namespace.
          %AI_SECURE                  =  &h08000  ' (Vista or later)The address information is from a secure channel. Windows Vista or later for the NS_EMAIL namespace.
          %AI_RETURN_PREFERRED_NAMES  = &h010000  ' (Vista or later)The address information is for a preferred name for a user. Windows Vista or later for the NS_EMAIL namespace.
      
          DECLARE FUNCTION getaddrinfo LIB "ws2_32.dll" ALIAS "getaddrinfo"(ASCIIZ, ASCIIZ, addrinfo, BYVAL paddrinfo AS addrinfo PTR) AS LONG
          DECLARE FUNCTION freeaddrinfo LIB "ws2_32.dll" ALIAS "freeaddrinfo"(BYVAL freeAddrData AS addrinfo PTR) AS LONG
      '______________________________________________________________________________
      
      
      '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      'PBMain +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      FUNCTION PBMAIN()
      
          DIM WinsockData AS WSADATA 'WSADATA is declared in "Winsock_X.inc"
          DIM wsAddrData AS addrinfo
          DIM ptrWsAddrData AS DWORD
          DIM pntr AS addrinfo POINTER
          DIM result AS LONG
      
          ptrWSAddrData = VARPTR(wsAddrData)
      
          'call wsaStartup to initialize winsock
          IF WSAStartup( MAKDWD(2,2), WinsockData) THEN ' if WSA Startup fails then...
              IF %dbug THEN
                  MessageBox %HWND_DESKTOP, BYCOPY "WSAStartup FAILED",    BYCOPY " WSAStartup", %MB_ICONINFORMATION OR %MB_OK
              END IF
          ELSE                                          ' if WSA Startup Successful then...
              IF %dbug THEN                             ' Display Winsock Ver and Status
                  MessageBox %HWND_DESKTOP, BYCOPY "WSAStartup Succeeded" + CHR$(13) + CHR$(10) + _
                      CHR$(13) + CHR$(10) + _
                      WinsockData.szDescription + CHR$(13) + CHR$(10) +_  ' UDT for WSADATA(WinsockData) defined in Winsock_X.inc
                      WinsockData.szSystemStatus + CHR$(13) + CHR$(10), _
                      BYCOPY " WSAStartup", %MB_ICONINFORMATION OR %MB_OK
              END IF
          END IF
      
          'initializewsAddrData for getaddrinfo
          wsAddrData.ai_flags      = %AI_CANONNAME    ' retrieve the canonical name
          wsAddrData.ai_family     = %AF_INET         ' IPv4 only. 0=IPv4 AND IPv6
          wsAddrData.ai_sockettype = 0                ' accept any socket type
          wsAddrData.ai_protocol   = 0                ' accept any protocol
          wsAddrData.ai_addrlen    = 0                ' initialize w/zero
          wsAddrData.ai_next       = 0                ' initialize w/zero
          wsAddrData.ai_canonname  = 0                ' initialize w/zero
      
          IF getaddrinfo("localhost" + $NUL, $NUL, wsAddrData, BYVAL ptrWsAddrData) THEN
              IF %dbug THEN
                  MessageBox %HWND_DESKTOP, BYCOPY "getaddrinfo FAILED",    BYCOPY " WSAStartup", %MB_ICONINFORMATION OR %MB_OK
              END IF
          ELSE
              IF %dbug THEN                             ' Display getaddrinfo
                  LOCAL msg AS STRING
                  pntr = ptrWsAddrData
                  
                  DO
                      msg = msg + "This TYPE: " + STR$(pntr)                + $CRLF + _
                          "Flags: "             + STR$(@pntr.ai_flags)      + $CRLF + _ 'seems an odd number to return
                          "Family: "            + STR$(@pntr.ai_family)     + $CRLF + _
                          "Socket Type: "       + STR$(@pntr.ai_sockettype) + $CRLF + _
                          "Protocol: "          + STR$(@pntr.ai_protocol)   + $CRLF + _
                          "Addr Len: "          + STR$(@pntr.ai_addrlen)    + $CRLF + _
                          "Canonical Name: "    + STR$(@pntr.ai_canonname)  + $CRLF + _ 'should return canonical name?
                          "Addr Ptr: "          + STR$(@pntr.ai_addr)       + $CRLF + _
                          "Next TYPE: "         + STR$(@pntr.ai_next)       + $CRLF + $CRLF
      
                      pntr = @pntr.ai_next
      
                  LOOP UNTIL  pntr = 0
      
                  MessageBox %HWND_DESKTOP, BYCOPY msg, BYCOPY " getaddrinfo", %MB_OK
      
              END IF
          END IF
      
          ' free mem used by getaddrinfo
          freeaddrinfo(ptrWsAddrData)
      
          'call wsaCleanup to shutdown winsock
          WSACleanup()
      
      END FUNCTION
      '______________________________________________________________________________
      Also, here is the file Winsock_X.inc. Seems to be more comprehensive than the include files shipped w/PB.

      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 (%WSOCK32)
       MACRO WSockLib = "WS2_32.DLL"
      #ELSE
       MACRO WSockLib = "WSOCK32.DLL"
      #ENDIF
      
      #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
      
      
      DECLARE FUNCTION aaccept     LIB WSockLib ALIAS "accept"      (BYVAL s AS DWORD, saAddr AS ANY, addrlen AS LONG) AS DWORD
      DECLARE FUNCTION bind        LIB WSockLib ALIAS "bind"        (BYVAL s AS DWORD, sname AS ANY, BYVAL namelen AS LONG) AS LONG
      DECLARE FUNCTION closesocket LIB WSockLib ALIAS "closesocket" (BYVAL s AS DWORD) AS LONG
      DECLARE FUNCTION cconnect    LIB WSockLib ALIAS "connect"     (BYVAL s AS DWORD, sname AS ANY, BYVAL namelen AS LONG) AS LONG
      DECLARE FUNCTION ioctlsocket LIB WSockLib ALIAS "ioctlsocket" (BYVAL s AS DWORD, BYVAL cmd AS LONG, argp AS DWORD) AS LONG
      DECLARE FUNCTION getpeername LIB WSockLib ALIAS "getpeername" (BYVAL s AS DWORD, sname AS ANY, namelen AS LONG) AS LONG
      DECLARE FUNCTION getsockname LIB WSockLib ALIAS "getsockname" (BYVAL s AS DWORD, sname AS ANY, namelen AS LONG) AS LONG
      DECLARE FUNCTION getsockopt  LIB WSockLib 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 WSockLib ALIAS "htonl"       (BYVAL hostlong AS DWORD) AS DWORD
      DECLARE FUNCTION htons       LIB WSockLib ALIAS "htons"       (BYVAL hostshort AS WORD) AS WORD
      DECLARE FUNCTION inet_addr   LIB WSockLib ALIAS "inet_addr"   (cp AS ASCIIZ) AS DWORD
      DECLARE FUNCTION inet_ntoa   LIB WSockLib ALIAS "inet_ntoa"   (inn AS LONG) AS LONG
      DECLARE FUNCTION listen      LIB WSockLib ALIAS "listen"      (BYVAL s AS DWORD, BYVAL backlog AS LONG) AS LONG
      DECLARE FUNCTION ntohl       LIB WSockLib ALIAS "ntohl"       (BYVAL netlong AS DWORD) AS DWORD
      DECLARE FUNCTION ntohs       LIB WSockLib ALIAS "ntohs"       (BYVAL netshort AS WORD) AS WORD
      DECLARE FUNCTION rrecv       LIB WSockLib ALIAS "recv"        (BYVAL s AS DWORD, buf AS ANY, BYVAL buflen AS LONG, BYVAL flags AS LONG) AS LONG
      DECLARE FUNCTION recvfrom    LIB WSockLib 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 WSockLib 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 WSockLib ALIAS "send"        (BYVAL s AS DWORD, buf AS ANY, BYVAL buflen AS LONG, BYVAL flags AS LONG) AS LONG
      DECLARE FUNCTION sendto      LIB WSockLib 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 WSockLib 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 WSockLib ALIAS "shutdown"    (BYVAL s AS DWORD, BYVAL how AS LONG) AS LONG
      DECLARE FUNCTION socket      LIB WSockLib ALIAS "socket"      (BYVAL af AS LONG, BYVAL s_type AS LONG, BYVAL protocol AS LONG) AS DWORD
      
      'Database Functions
      DECLARE FUNCTION gethostbyaddr    LIB WSockLib ALIAS "gethostbyaddr"    (address AS ASCIIZ, BYVAL addr_len AS LONG, BYVAL addr_type AS LONG) AS DWORD
      DECLARE FUNCTION gethostbyname    LIB WSockLib ALIAS "gethostbyname"    (host_name AS ASCIIZ) AS DWORD
      DECLARE FUNCTION gethostname      LIB WSockLib ALIAS "gethostname"      (host_name AS ASCIIZ, BYVAL namelen AS LONG) AS LONG
      DECLARE FUNCTION getprotobyname   LIB WSockLib ALIAS "getprotobyname"   (proto_name AS ASCIIZ) AS DWORD
      DECLARE FUNCTION getprotobynumber LIB WSockLib ALIAS "getprotobynumber" (BYVAL proto AS LONG) AS DWORD
      DECLARE FUNCTION getservbyname    LIB WSockLib ALIAS "getservbyname"    (serv_name AS ASCIIZ, proto AS ASCIIZ) AS DWORD
      DECLARE FUNCTION getservbyport    LIB WSockLib ALIAS "getservbyport"    (BYVAL lPort AS LONG, proto AS ASCIIZ) AS DWORD
      
      ' Microsoft Windows Extension function prototypes
      
      DECLARE FUNCTION WSAAsyncSelect        LIB WSockLib ALIAS "WSAAsyncSelect"        (BYVAL s AS DWORD, BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL lEvent AS LONG) AS LONG
      DECLARE FUNCTION WSACancelBlockingCall LIB WSockLib ALIAS "WSACancelBlockingCall" () AS LONG
      DECLARE FUNCTION WSACleanup            LIB WSockLib ALIAS "WSACleanup"            () AS LONG
      DECLARE FUNCTION WSAGetLastError       LIB WSockLib ALIAS "WSAGetLastError"       () AS LONG
      DECLARE FUNCTION WSAIsBlocking         LIB WSockLib ALIAS "WSAIsBlocking"         () AS LONG
      DECLARE FUNCTION WSARecvEx             LIB WSockLib ALIAS "WSARecvEx"             (BYVAL s AS DWORD, buf AS ANY, BYVAL buflen AS LONG, BYVAL flags AS LONG) AS LONG
      DECLARE FUNCTION WSASetBlockingHook    LIB WSockLib ALIAS "WSASetBlockingHook"    (BYVAL lpBlockFunc AS DWORD) AS DWORD
      DECLARE FUNCTION WSAStartup            LIB WSockLib ALIAS "WSAStartup"            (BYVAL wVR AS WORD, lpWSAD AS WSAData) AS LONG
      DECLARE SUB      WSASetLastError       LIB WSockLib ALIAS "WSASetLastError"       (BYVAL iError AS LONG)
      DECLARE FUNCTION WSAUnhookBlockingHook LIB WSockLib ALIAS "WSAUnhookBlockingHook" () AS LONG
      
      'WSAAsyncGetXByY Functions don't work reliably under 32Bit Windows
      
      DECLARE FUNCTION WSAAsyncGetServByName    LIB WSockLib 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 WSockLib 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 WSockLib 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 WSockLib 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 WSockLib 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 WSockLib 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 WSockLib ALIAS "WSACancelAsyncRequest"    (BYVAL hAsyncTaskHandle AS DWORD) AS LONG
      
      #IF NOT %DEF(%WSOCK32)
      
      ' 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)
      Rick McNeely
      Rick

      Comment


      • #4
        "localhost" is not an AF_INET URL - try another one, such as "www.powerbasic.com". Also, you need to allocate a large enough buffer for the outgoing addrinfo() linked list. Look more closely at my code. You will see I DIM a 100KB-length dyanmic string, and assign ptraddrinfo to the STRPTR of that string. Lastly, the last argument in the "getaddr()" function is a pointer to a pointer.

        Comment


        • #5
          Hey,

          Here is some code that may also help a little...

          Code:
          #COMPILE EXE '#Win 8.04#
          #DIM ALL
          #INCLUDE "WIN32API.INC" '#2005-01-27#
           
          %SNLEN              =  80
          %MAX_HOSTNAME_LEN   = 128
          %WSADESCRIPTION_LEN = 256
          %WSASYS_STATUS_LEN  = 128
           
          %AI_PASSIVE         = 1
          %AI_CANONNAME       = 2
          %AI_NUMERICHOST     = 4
           
          'ai_flags...
          %AI_PASSIVE                = &h00000001 'The socket address will be used in a call to the bind function.
          %AI_CANONNAME              = &h00000002 'The canonical name is returned in the first ai_canonname member.
          %AI_NUMERICHOST            = &h00000004 'The nodename parameter passed to the getaddrinfo function must be a numeric string.
          %AI_ADDRCONFIG             = &h00000400 'The getaddrinfo will resolve only if a global address is configured. The IPv6 and IPv4 loopback address is not considered a valid global address. This option is only supported on Windows Vista or later.
          %AI_NON_AUTHORITATIVE      = &h00004000 'The address information can be from a non-authoritative namespace provider. This option is only supported on Windows Vista or later for the NS_EMAIL namespace.
          %AI_SECURE                 = &h00008000 'The address information is from a secure channel. This option is only supported on Windows Vista or later for the NS_EMAIL namespace.
          %AI_RETURN_PREFERRED_NAMES = &h00010000 'The address information is for a preferred name for a user. This option is only supported on Windows Vista or later for the NS_EMAIL namespace.
           
          'ai_family...
          %AF_UNSPEC  =  0 'The address family is unspecified.
          %AF_INET    =  2 'The Internet Protocol version 4 (IPv4) address family.
          %AF_NETBIOS = 17 'The NetBIOS address family. This address family is only supported if a Windows Sockets provider for NetBIOS is installed.
          %AF_INET6   = 23 'The Internet Protocol version 6 (IPv6) address family.
          %AF_IRDA    = 26 'The Infrared Data Association (IrDA) address family. This address family is only supported if the computer has an infrared port and driver installed.
          %AF_BTM     = 32 'The Bluetooth address family. This address family is only supported if a Bluetooth adapter is installed on Windows Server 2003 or later.
           
          'ai_sockttype...
          %SOCK_STREAM    = 1 'Provides sequenced, reliable, two-way, connection-based byte streams with an OOB data transmission mechanism. Uses the Transmission Control Protocol (TCP) for the Internet address family (AF_INET or AF_INET6).
                              'If the ai_family member is AF_IRDA, then SOCK_STREAM is the only supported socket type.
          %SOCK_DGRAM     = 2 'Supports datagrams, which are connectionless, unreliable buffers of a fixed (typically small) maximum length. Uses the User Datagram Protocol (UDP) for the Internet address family (AF_INET or AF_INET6).
          %SOCK_RAW       = 3 'Provides a raw socket that allows an application to manipulate the next upper-layer protocol header. To manipulate the IPv4 header, the IP_HDRINCL socket option must be set on the socket. To manipulate the IPv6 header,
                              'the IPV6_HDRINCL socket option must be set on the socket.
          %SOCK_RDM       = 4 'Provides a reliable message datagram. An example of this type is the Pragmatic General Multicast (PGM) multicast protocol implementation in Windows, often referred to as reliable multicast programming.
          %SOCK_SEQPACKET = 5 'Provides a pseudo-stream packet based on datagrams.
           
          'ai_protocol
          %IPPROTO_TCP =   6 'The Transmission Control Protocol (TCP). This is a possible value when the ai_family member is AF_INET or AF_INET6 and the ai_socktype member is SOCK_STREAM.
          %IPPROTO_UDP =  17 'The User Datagram Protocol (UDP). This is a possible value when the ai_family member is AF_INET or AF_INET6 and the type parameter is SOCK_DGRAM.
          %IPPROTO_RM  = 113 'The PGM protocol for reliable multicast. This is a possible value when the ai_family member is AF_INET and the ai_socktype member is SOCK_RDM. On the Windows SDK released for Windows Vista and later, this value is also called IPPROTO_PGM.
           
          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
           
          TYPE S_un_b
            s_b1 AS BYTE
            s_b2 AS BYTE
            s_b3 AS BYTE
            s_b4 AS BYTE
          END TYPE
           
          TYPE S_un_w
            s_w1 AS WORD
            s_w2 AS WORD
          END TYPE
           
          UNION S_addr
            S_un_b
            S_un_w
            S_addr AS DWORD
          END UNION
           
          TYPE in_addr
            S_addr AS DWORD
          END TYPE
           
          TYPE SOCKADDR_IN
            sin_family AS WORD
            sin_port   AS WORD
            sin_addr   AS in_addr
            sin_zero   AS STRING * 8
          END TYPE
           
          TYPE SOCKADDR
            sa_family AS WORD        'Address family
            sa_data   AS STRING * 14 'Up to 14 bytes of direct address
          END TYPE
           
          TYPE ADDRINFO
            ai_flags     AS DWORD        'AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST
            ai_family    AS DWORD        'PF_INET
            ai_sockttype AS DWORD        'SOCK_RAW, SOCK_STREAM, or SOCK_DGRAM
            ai_protocol  AS DWORD        'IPPROTO_TCP
            ai_addrlen   AS DWORD        'Length in bytes of ai_addr
            ai_canonname AS ASCIIZ PTR   'Canonical name for the host
            ai_addr      AS SOCKADDR PTR 'Binary address
            ai_next      AS ADDRINFO PTR 'Next structure
          END TYPE
           
          DECLARE FUNCTION WSAStartup LIB "wsock32.dll" ALIAS "WSAStartup"( _
            BYVAL wVR AS WORD, _
            lpWSAD    AS WSAData) AS LONG
           
          DECLARE FUNCTION WSACleanup LIB "wsock32.dll" ALIAS "WSACleanup"() AS LONG
           
          DECLARE FUNCTION GetAddrInfo LIB "ws2_32.dll" ALIAS "getaddrinfo"( _
            NodeName   AS ASCIIZ, _
            ServName   AS ASCIIZ, _
            Hints      AS ADDRINFO, _
            BYVAL pRes AS ADDRINFO POINTER) AS LONG
           
          DECLARE FUNCTION FreeAddrInfo LIB "ws2_32.dll" ALIAS "freeaddrinfo"(AddrInfoPointer AS DWORD)AS LONG
          '______________________________________________________________________________
           
          FUNCTION Ai_FlagsToString(ai_flags AS DWORD) AS STRING
           LOCAL sBuffer AS STRING
           
           IF ai_flags THEN
             IF (ai_flags AND %AI_PASSIVE)     THEN sBuffer = "AI_PASSIVE"
             IF (ai_flags AND %AI_CANONNAME)   THEN sBuffer = sBuffer & " AI_CANONNAME"
             IF (ai_flags AND %AI_NUMERICHOST) THEN sBuffer = sBuffer & " AI_NUMERICHOST"
             IF (ai_flags AND %AI_ADDRCONFIG)  THEN sBuffer = sBuffer & " AI_ADDRCONFIG"
             IF (ai_flags AND %AI_SECURE)      THEN sBuffer = sBuffer & " AI_SECURE"
             IF (ai_flags AND %AI_RETURN_PREFERRED_NAMES) THEN
               sBuffer = sBuffer & " AI_RETURN_PREFERRED_NAMES"
             END IF
             FUNCTION = LTRIM$(sBuffer)
           ELSE
             FUNCTION = "AI_NONE"
           END IF
           
          END FUNCTION
          '______________________________________________________________________________
           
          FUNCTION Ai_FamilyToString(ai_family AS DWORD) AS STRING
           
           SELECT CASE ai_family
             CASE %AF_UNSPEC  : FUNCTION = "AF_UNSPEC"
             CASE %AF_INET    : FUNCTION = "AF_INET"
             CASE %AF_NETBIOS : FUNCTION = "AF_NETBIOS"
             CASE %AF_INET6   : FUNCTION = "AF_INET6"
             CASE %AF_IRDA    : FUNCTION = "AF_IRDA"
             CASE %AF_BTM     : FUNCTION = "AF_BTM"
             CASE ELSE        : FUNCTION = "AF_UNKNOWN" & STR$(ai_family)
           END SELECT
           
          END FUNCTION
          '______________________________________________________________________________
           
          FUNCTION Ai_SocktTypeToString(ai_sockttype AS DWORD) AS STRING
           
           SELECT CASE ai_sockttype
             CASE %SOCK_STREAM    : FUNCTION = "SOCK_STREAM"
             CASE %SOCK_DGRAM     : FUNCTION = "SOCK_DGRAM"
             CASE %SOCK_RAW       : FUNCTION = "SOCK_RAW"
             CASE %SOCK_RDM       : FUNCTION = "SOCK_RDM"
             CASE %SOCK_SEQPACKET : FUNCTION = "SOCK_SEQPACKET"
             CASE ELSE            : FUNCTION = "SOCK_UNKNOWN" & STR$(ai_sockttype)
           END SELECT
           
          END FUNCTION
          '______________________________________________________________________________
           
          FUNCTION Ai_ProtocolToString(ai_protocol AS DWORD) AS STRING
           
           SELECT CASE ai_protocol
             CASE 0            : FUNCTION = "IPPROTO_ZERO" 'Not_IPv4_nor_IPv6
             CASE %IPPROTO_TCP : FUNCTION = "IPPROTO_TCP"
             CASE %IPPROTO_UDP : FUNCTION = "IPPROTO_UDP"
             CASE %IPPROTO_RM  : FUNCTION = "IPPROTO_RM"
             CASE ELSE         : FUNCTION = "IPPROTO_UNKNOWN" & STR$(ai_protocol)
           END SELECT
           
          END FUNCTION
          '______________________________________________________________________________
           
          FUNCTION ipDwordToDot(ip AS DWORD) AS STRING
           LOCAL pByte AS BYTE PTR
           
           pByte = VARPTR(ip)
           FUNCTION = USING$("#_.#_.#_.#", @pByte, @pByte[1], @pByte[2], @pByte[3])
           
          END FUNCTION
          '______________________________________________________________________________
           
          FUNCTION WinErrMsg(BYVAL ErrNum AS DWORD)AS STRING
           LOCAL hLib      AS DWORD
           LOCAL errorFlag AS DWORD
           LOCAL os        AS OSVERSIONINFO
           LOCAL zError    AS ASCIIZ * 1024
           
           SELECT CASE AS LONG ErrNum
           
             CASE 2100 TO 2999    'NT, Network, thank Greg Turgeon %NETWORK_ERROR_FIRST TO %NETWORK_ERROR_LAST
               os.dwOSVersionInfoSize = SIZEOF(os)
               GetVersionEx os
               IF os.dwPlatformId = %VER_PLATFORM_WIN32_NT THEN _
                 hLib = LoadLibraryEx("NETMSG.DLL", BYVAL 0, %LOAD_LIBRARY_AS_DATAFILE)
           
             CASE 12000 TO 12171 'Internet %INTERNET_ERROR_FIRST TO %NTERNET_ERROR_LAST
               hLib = LoadLibraryEx("WININET.DLL", BYVAL 0, %LOAD_LIBRARY_AS_DATAFILE)
           
           END SELECT
           
           errorFlag = %FORMAT_MESSAGE_FROM_SYSTEM OR %FORMAT_MESSAGE_IGNORE_INSERTS OR _
                       %FORMAT_MESSAGE_MAX_WIDTH_MASK
           IF hLib THEN errorFlag = errorFlag OR %FORMAT_MESSAGE_FROM_HMODULE
           
           IF FormatMessage(errorFlag, BYVAL hLib, ErrNum, MakeLangID(%LANG_NEUTRAL, %SUBLANG_DEFAULT), _
                            zError, SIZEOF(zError), BYVAL 0) THEN
             FUNCTION = "Error" & STR$(ErrNum) & ":" & $SPC & zError
           ELSE
             FUNCTION = "Error" & STR$(ErrNum) & ", unknown."
           END IF
           IF hLib THEN FreeLibrary hLib
           
          END FUNCTION
          '______________________________________________________________________________
           
          FUNCTION Memo(TxtDef AS STRING, TxtVar AS STRING) AS STRING
           STATIC sBuffer AS STRING
           
           sBuffer = sBuffer & TxtDef & $TAB & TxtVar & $CRLF
           REPLACE $NUL WITH "." IN sBuffer
           FUNCTION = sBuffer
           
          END FUNCTION
          '______________________________________________________________________________
           
          FUNCTION PBMAIN() AS LONG
           LOCAL WsaInfo     AS WsaData
           LOCAL Retval      AS LONG
           LOCAL NodeName    AS ASCIIZ * %MAX_HOSTNAME_LEN
           LOCAL ServName    AS ASCIIZ * %SNLEN
           LOCAL Hints       AS ADDRINFO
           LOCAL pResFirst   AS ADDRINFO POINTER
           LOCAL pRes        AS ADDRINFO POINTER
           LOCAL pAi_Addr_In AS SOCKADDR_IN POINTER
           LOCAL pAi_Addr    AS SOCKADDR PTR
           LOCAL sBuffer     AS STRING
           
           NodeName    = "microsoft.com" 'Microsoft.com or ip 67.17.204.214
          'NodeName    = "ibm.com"
          'NodeName    = "powerbasic.com"
           ServName    = "http"  'Either a service name or port number. FTP-21, HTTP-80
           
           WSAStartUp &h0202, WsaInfo
           
           Retval = GetAddrInfo(NodeName, ServName, Hints, BYVAL VARPTR(pResFirst))
           
           Memo "NodeName:         ", (NodeName)
           Memo "ServName:         ", (ServName)
           Memo "Error:            ", WinErrMsg(Retval) 'Success returns zero. Failure returns a nonzero Windows Sockets error code
           
           WSACleanUp
           
           IF Retval = %ERROR_SUCCESS THEN
             pRes = pResFirst
             DO
               Memo " ", $CRLF
               Memo "addr info pointer:", HEX$(pRes)
               Memo "flags:            ", Ai_FlagsToString(@pRes.ai_flags)
               Memo "family:           ", Ai_FamilyToString(@pRes.ai_family)
               Memo "sockttype:        ", Ai_sockttypeToString(@pRes.ai_sockttype)
               Memo "protocol:         ", Ai_ProtocolToString(@pRes.ai_protocol)
               Memo "canonical-addr:   ", HEX$(@pRes.ai_canonname)
               IF @pRes.ai_canonname THEN
                 Memo "canonical-string: ", (@[email protected]_canonname)
               END IF
               Memo "addrlen:          ", FORMAT$(@pRes.ai_addrlen)
               pAi_Addr = @pRes.ai_addr
               Memo "addr-sa-family:   ", Ai_FamilyToString((@pAi_Addr.sa_family))
               IF @pAi_Addr.sa_family = %AF_INET THEN
                 pAi_Addr_In = @pRes.ai_addr
                 Memo "addr-sin-family:  ", Ai_FamilyToString((@pAi_Addr_In.sin_family))
                 Memo "addr-sin-port:    ", FORMAT$(@pAi_Addr_In.sin_port)
                 Memo "addr-sin-addr:    ", ipDwordToDot(@pAi_Addr_In.sin_addr.s_addr)
                 Memo "addr-sin-zero:    ", (@pAi_Addr_In.sin_zero)
               ELSE
                 Memo "addr-sa-family:   ", Ai_FamilyToString((@pAi_Addr.sa_family))
                 Memo "addr-sa-data:     ", (@pAi_Addr.sa_data)
               END IF
               Memo "next addr info:     ", HEX$(@pRes.ai_next)
               pRes = @pRes.ai_next
             LOOP UNTIL pRes = 0
           END IF
           
           FreeAddrInfo pResFirst
           
           MessageBox %HWND_DESKTOP, BYCOPY Memo("", ""), BYCOPY "GetAddrInfo", %MB_ICONINFORMATION OR %MB_OK
           
          END FUNCTION
          '______________________________________________________________________________
          '
          Last edited by Pierre Bellisle; 11 Dec 2007, 11:29 AM.

          Comment


          • #6
            Remove the xFiller1 and xFiller2 members of the WSAdata structure.
            Forum: http://www.jose.it-berater.org/smfforum/index.php

            Comment


            • #7
              Done, thank...

              Comment


              • #8
                Thanks Guys

                Thanks for the excellent help. I'm finally seeing the light. These peer-support forums are the number one reason to use PB, imnsho.

                I realize it would be a massive undertaking, but I would love to see a nice comprehensive tutorial on PB, PB and the Win32 API, PB and the Winsock API.

                These things I would gladly pay for.

                Thanks again

                Rick McNeely
                Rick

                Comment

                Working...
                X