'This is the Winsock API definition file for Visual Basic
'The file is a port from the C header file found in the
'Winsock Version 1.1 API specification.
Global Const FD_SETSIZE% = 64
Type FD_SET
fd_count As Integer
fd_array(FD_SETSIZE) As Integer
End Type 'fd_set
Global Const SZFD_SET = 4
Declare Function FD_ISSET Lib "winsock.dll" Alias "#151" (ByVal s As Integer, passed_set As FD_SET) As Integer
Declare Function x_WSAFDIsSet Lib "winsock.dll" Alias "#151" (ByVal s As Integer, passed_set As FD_SET) As Integer
Type timeval
tv_sec As Long
tv_usec As Long
End Type
Global Const SZTIMEVAL = 8
'Setup the variable type 'hostent' for the WSAStartup command
Type Hostent
h_name As Long
h_aliases As Long
h_addrtype As String * 2
h_length As String * 2
h_addr_list As Long
End Type
Global Const SZHOSTENT = 16
'This section lists the protocol ID's as theu
'are registered with the IANA
'Check RFC1117 for more details
Global Const IPPROTO_IP% = 0 ' dummy for IP
Global Const IPPROTO_ICMP% = 1 ' control message protocol
Global Const IPPROTO_GGP% = 2 ' gateway^2 (deprecated)
Global Const IPPROTO_TCP% = 6 ' tcp
Global Const IPPROTO_PUP% = 12 ' pup
Global Const IPPROTO_UDP% = 17 ' user datagram protocol
Global Const IPPROTO_IDP% = 22 ' xns idp
Global Const IPPROTO_ND% = 77 ' UNOFFICIAL net disk proto
Global Const IPPROTO_RAW% = 255 ' raw IP packet
Global Const IPPROTO_MAX% = 256
'Port numbers for network services
'Check STD2 for more details
Global Const IPPORT_ECHO% = 7
Global Const IPPORT_SYSTAT% = 11
Global Const IPPORT_DAYTIME% = 13
Global Const IPPORT_FTP% = 21
Global Const IPPORT_TELNET% = 23
Global Const IPPORT_SMTP% = 25
Global Const IPPORT_FINGER% = 79
'Set the restricted port floor to 1024 for experimental operations
Global Const IPPORT_RESERVED% = 1024
'Set the Internet address type to a long integer (32-bit)
Type in_addr
s_addr As Long
End Type
'Set Internet address classes (A,B,C)
Global Const IN_CLASSA_NET& = &HFF000000
Global Const IN_CLASSA_NSHIFT& = 24
Global Const IN_CLASSA_HOST& = &HFFFFFF
Global Const IN_CLASSA_MAX& = 128
Global Const IN_CLASSB_NET& = &HFFFF0000
Global Const IN_CLASSB_NSHIFT& = 16
Global Const IN_CLASSB_HOST& = &HFFFF
Global Const IN_CLASSB_MAX& = 65536
Global Const IN_CLASSC_NET& = &HFFFFFF00
Global Const IN_CLASSC_NSHIFT& = 8
Global Const IN_CLASSC_HOST& = &HFF
Global Const INADDR_ANY& = &H0
Global Const INADDR_LOOPBACK& = &H7F000001
Global Const INADDR_BROADCAST& = &HFFFFFFFF
Global Const INADDR_NONE& = &HFFFFFFFF
'A note to those familiar with the C header file for Winsock
'Visual Basic does not permit a user-defined variable type
'to be used as a return structure. In the case of the
'variable definition below, sin_addr must
'be declared as a long integer rather than the user-defined
'variable type of in_addr.
Type sockaddr_in
sin_family As Integer
sin_port As Integer
sin_addr As Long
sin_zero As String * 8
End Type
Global Const WSADESCRIPTION_LEN% = 256
Global Const WSASYS_STATUS_LEN% = 128
'Setup the structure for the information returned from
'the WSAStartup() function.
Type WSAData
wVersion As Integer
wHighVersion As Integer
szDescription As String * 257
szSystemStatus As String * 129
iMaxSockets As Integer
iMaxUdpDg As Integer
lpVendorInfo As String * 200
End Type
'Define socket return codes
Global Const INVALID_SOCKET% = &HFFFF
Global Const SOCKET_ERROR% = -1
'Define socket types
Global Const SOCK_STREAM% = 1 'Stream socket
Global Const SOCK_DGRAM% = 2 'Datagram socket
Global Const SOCK_RAW% = 3 'Raw data socket
Global Const SOCK_RDM% = 4 'Reliable Delivery socket
Global Const SOCK_SEQPACKET% = 5 'Sequenced Packet socket
'Socket option flags
Global Const SO_DEBUG% = &H1 ' turn on debugging info recording
Global Const SO_ACCEPTCONN% = &H2 ' socket has had listen()
Global Const SO_REUSEADDR% = &H4 ' allow local address reuse
Global Const SO_KEEPALIVE% = &H8 ' keep connections alive
Global Const SO_DONTROUTE% = &H10 ' just use interface addresses
Global Const SO_BROADCAST% = &H20 ' permit sending of broadcast msgs
Global Const SO_USELOOPBACK% = &H40 ' bypass hardware when possible
Global Const SO_LINGER% = &H80 ' linger on close if data present
Global Const SO_OOBINLINE% = &H100 ' leave received OOB data in line
Global Const SO_DONTLINGER% = &HFF7F ' same as SO_LINGER
Global Const SO_SNDBUF% = &H1001 ' send buffer size
Global Const SO_RCVBUF% = &H1002 ' receive buffer size
Global Const SO_SNDLOWAT% = &H1003 ' send low-water mark
Global Const SO_RCVLOWAT% = &H1004 ' receive low-water mark
Global Const SO_SNDTIMEO% = &H1005 ' send timeout
Global Const SO_RCVTIMEO% = &H1006 ' receive timeout
Global Const SO_ERROR% = &H1007 ' get error status and clear
Global Const SO_TYPE% = &H1008 ' get socket type
'Define TCP option flag
Global Const TCP_NODELAY% = &H1
'Define address families
Global Const AF_UNSPEC% = 0 ' unspecified
Global Const AF_UNIX% = 1 ' local to host (pipes, portals)
Global Const AF_INET% = 2 ' internetwork: UDP, TCP, etc.
Global Const AF_IMPLINK% = 3 ' arpanet imp addresses
Global Const AF_PUP% = 4 ' pup protocols: e.g. BSP
Global Const AF_CHAOS% = 5 ' mit CHAOS protocols
Global Const AF_NS% = 6 ' XEROX NS protocols
Global Const AF_ISO% = 7 ' ISO protocols
Global Const AF_OSI% = AF_ISO ' OSI is ISO
Global Const AF_ECMA% = 8 ' european computer manufacturers
Global Const AF_DATAKIT% = 9 ' datakit protocols
Global Const AF_CCITT% = 10 ' CCITT protocols, X.25 etc
Global Const AF_SNA% = 11 ' IBM SNA
Global Const AF_DECnet% = 12 ' DECnet
Global Const AF_DLI% = 13 ' Direct data link interface
Global Const AF_LAT% = 14 ' LAT
Global Const AF_HYLINK% = 15 ' NSC Hyperchannel
Global Const AF_APPLETALK% = 16 ' AppleTalk
Global Const AF_NETBIOS% = 17 ' NetBios-style addresses
Global Const AF_MAX% = 18 'Maximum # of address families
'Setup sockaddr data type to store Internet addresses
Type sockaddr
sa_family As Integer
sa_data As String * 14
End Type
Global Const SADDRLEN% = 16
'Setup sockproto type used for socket information
Type sockproto
sp_family As Integer
sp_protocol As Integer
End Type
'Define Protocol families...the same as address families
Global Const PF_UNSPEC% = AF_UNSPEC
Global Const PF_UNIX% = AF_UNIX
Global Const PF_INET% = AF_INET
Global Const PF_IMPLINK% = AF_IMPLINK
Global Const PF_PUP% = AF_PUP
Global Const PF_CHAOS% = AF_CHAOS
Global Const PF_NS% = AF_NS
Global Const PF_ISO% = AF_ISO
Global Const PF_OSI% = AF_OSI
Global Const PF_ECMA% = AF_ECMA
Global Const PF_DATAKIT% = AF_DATAKIT
Global Const PF_CCITT% = AF_CCITT
Global Const PF_SNA% = AF_SNA
Global Const PF_DECnet% = AF_DECnet
Global Const PF_DLI% = AF_DLI
Global Const PF_LAT% = AF_LAT
Global Const PF_HYLINK% = AF_HYLINK
Global Const PF_APPLETALK% = AF_APPLETALK
Global Const PF_MAX% = AF_MAX
'Setup data type used for manipulating linger option.
Type linger
l_onoff As Integer
l_linger As Integer
End Type
'Define level number for (get/set)sockopt() to apply to socket itself.
Global Const SOL_SOCKET% = &HFFFF
'Define maximum queue length specifiable by listen().
Global Const SOMAXCONN% = 5 ' maximum # of queued connections
Global Const MSG_OOB% = &H1 ' process out-of-band data
Global Const MSG_PEEK% = &H2 ' peek at incoming message
Global Const MSG_DONTROUTE% = &H4 ' send without using routing tables
Global Const MSG_MAXIOVLEN% = 16
'Define constant based on rfc883, used by gethostby....() calls.
Global Const MAXGETHOSTSTRUCT% = 1024
'Define flags to be used with the WSAAsyncSelect() call.
Global Const FD_READ% = &H1
Global Const FD_WRITE% = &H2
Global Const FD_OOB% = &H4
Global Const FD_ACCEPT% = &H8
Global Const FD_CONNECT% = &H10
Global Const FD_CLOSE% = &H20
'All Windows Sockets error constants are biased by WSABASEERR from
'the "normal"
Global Const WSABASEERR% = 10000
'Define Windows Sockets definitions of regular Microsoft C error constants
Global Const WSAEINTR% = (WSABASEERR + 4)
Global Const WSAEBADF% = (WSABASEERR + 9)
Global Const WSAEACCES% = (WSABASEERR + 13)
Global Const WSAEFAULT% = (WSABASEERR + 14)
Global Const WSAEINVAL% = (WSABASEERR + 22)
Global Const WSAEMFILE% = (WSABASEERR + 24)
'Define Windows Sockets definitions of error constants
Global Const WSAEWOULDBLOCK% = (WSABASEERR + 35)
Global Const WSAEINPROGRESS% = (WSABASEERR + 36)
Global Const WSAEALREADY% = (WSABASEERR + 37)
Global Const WSAENOTSOCK% = (WSABASEERR + 38)
Global Const WSAEDESTADDRREQ% = (WSABASEERR + 39)
Global Const WSAEMSGSIZE% = (WSABASEERR + 40)
Global Const WSAEPROTOTYPE% = (WSABASEERR + 41)
Global Const WSAENOPROTOOPT% = (WSABASEERR + 42)
Global Const WSAEPROTONOSUPPORT% = (WSABASEERR + 43)
Global Const WSAESOCKTNOSUPPORT% = (WSABASEERR + 44)
Global Const WSAEOPNOTSUPP% = (WSABASEERR + 45)
Global Const WSAEPFNOSUPPORT% = (WSABASEERR + 46)
Global Const WSAEAFNOSUPPORT% = (WSABASEERR + 47)
Global Const WSAEADDRINUSE% = (WSABASEERR + 48)
Global Const WSAEADDRNOTAVAIL% = (WSABASEERR + 49)
Global Const WSAENETDOWN% = (WSABASEERR + 50)
Global Const WSAENETUNREACH% = (WSABASEERR + 51)
Global Const WSAENETRESET% = (WSABASEERR + 52)
Global Const WSAECONNABORTED% = (WSABASEERR + 53)
Global Const WSAECONNRESET% = (WSABASEERR + 54)
Global Const WSAENOBUFS% = (WSABASEERR + 55)
Global Const WSAEISCONN% = (WSABASEERR + 56)
Global Const WSAENOTCONN% = (WSABASEERR + 57)
Global Const WSAESHUTDOWN% = (WSABASEERR + 58)
Global Const WSAETOOMANYREFS% = (WSABASEERR + 59)
Global Const WSAETIMEDOUT% = (WSABASEERR + 60)
Global Const WSAECONNREFUSED% = (WSABASEERR + 61)
Global Const WSAELOOP% = (WSABASEERR + 62)
Global Const WSAENAMETOOLONG% = (WSABASEERR + 63)
Global Const WSAEHOSTDOWN% = (WSABASEERR + 64)
Global Const WSAEHOSTUNREACH% = (WSABASEERR + 65)
Global Const WSAENOTEMPTY% = (WSABASEERR + 66)
Global Const WSAEPROCLIM% = (WSABASEERR + 67)
Global Const WSAEUSERS% = (WSABASEERR + 68)
Global Const WSAEDQUOT% = (WSABASEERR + 69)
Global Const WSAESTALE% = (WSABASEERR + 70)
Global Const WSAEREMOTE% = (WSABASEERR + 71)
'Define Extended Windows Sockets error constant definitions
Global Const WSASYSNOTREADY% = (WSABASEERR + 91)
Global Const WSAVERNOTSUPPORTED% = (WSABASEERR + 92)
Global Const WSANOTINITIALISED% = (WSABASEERR + 93)
'Define error return codes from gethostbyname() and gethostbyaddr()
' Authoritative Answer: Host not found
Global Const WSAHOST_NOT_FOUND% = (WSABASEERR + 1001)
Global Const HOST_NOT_FOUND% = WSAHOST_NOT_FOUND
' Non-Authoritative: Host not found, or SERVERFAIL
Global Const WSATRY_AGAIN% = (WSABASEERR + 1002)
Global Const TRY_AGAIN% = WSATRY_AGAIN
' Non recoverable errors, FORMERR, REFUSED, NOTIMP
Global Const WSANO_RECOVERY% = (WSABASEERR + 1003)
Global Const NO_RECOVERY% = WSANO_RECOVERY
' Valid name, no data record of requested type
Global Const WSANO_DATA% = (WSABASEERR + 1004)
Global Const NO_DATA% = WSANO_DATA
' no address, look for MX record
Global Const WSANO_ADDRESS% = WSANO_DATA
Global Const NO_ADDRESS% = WSANO_ADDRESS
'Define Windows Sockets errors redefined as error constants
Global Const EWOULDBLOCK% = WSAEWOULDBLOCK
Global Const EINPROGRESS% = WSAEINPROGRESS
Global Const EALREADY% = WSAEALREADY
Global Const ENOTSOCK% = WSAENOTSOCK
Global Const EDESTADDRREQ% = WSAEDESTADDRREQ
Global Const EMSGSIZE% = WSAEMSGSIZE
Global Const EPROTOTYPE% = WSAEPROTOTYPE
Global Const ENOPROTOOPT% = WSAENOPROTOOPT
Global Const EPROTONOSUPPORT% = WSAEPROTONOSUPPORT
Global Const ESOCKTNOSUPPORT% = WSAESOCKTNOSUPPORT
Global Const EOPNOTSUPP% = WSAEOPNOTSUPP
Global Const EPFNOSUPPORT% = WSAEPFNOSUPPORT
Global Const EAFNOSUPPORT% = WSAEAFNOSUPPORT
Global Const EADDRINUSE% = WSAEADDRINUSE
Global Const EADDRNOTAVAIL% = WSAEADDRNOTAVAIL
Global Const ENETDOWN% = WSAENETDOWN
Global Const ENETUNREACH% = WSAENETUNREACH
Global Const ENETRESET% = WSAENETRESET
Global Const ECONNABORTED% = WSAECONNABORTED
Global Const ECONNRESET% = WSAECONNRESET
Global Const ENOBUFS% = WSAENOBUFS
Global Const EISCONN% = WSAEISCONN
Global Const ENOTCONN% = WSAENOTCONN
Global Const ESHUTDOWN% = WSAESHUTDOWN
Global Const ETOOMANYREFS% = WSAETOOMANYREFS
Global Const ETIMEDOUT% = WSAETIMEDOUT
Global Const ECONNREFUSED% = WSAECONNREFUSED
Global Const ELOOP% = WSAELOOP
Global Const ENAMETOOLONG% = WSAENAMETOOLONG
Global Const EHOSTDOWN% = WSAEHOSTDOWN
Global Const EHOSTUNREACH% = WSAEHOSTUNREACH
Global Const ENOTEMPTY% = WSAENOTEMPTY
Global Const EPROCLIM% = WSAEPROCLIM
Global Const EUSERS% = WSAEUSERS
Global Const EDQUOT% = WSAEDQUOT
Global Const ESTALE% = WSAESTALE
Global Const EREMOTE% = WSAEREMOTE
'Declare Socket functions
Declare Function accept% Lib "winsock.dll" Alias "#1" (ByVal s As Integer, addr As sockaddr, ByVal namelen As Integer)
Declare Function bind% Lib "winsock.dll" Alias "#2" (ByVal s As Integer, addr As sockaddr_in, ByVal namelen As Integer)
Declare Function closesocket% Lib "winsock.dll" Alias "#3" (ByVal s As Integer)
Declare Function connect% Lib "winsock.dll" Alias "#4" (ByVal s As Integer, addr As sockaddr_in, ByVal namelen As Integer)
Declare Function ioctlsocket% Lib "winsock.dll" Alias "#12" (ByVal s As Integer, ByVal cmd As Long, argp As Long)
Declare Function getpeername% Lib "winsock.dll" Alias "#5" (ByVal s As Integer, peername As sockaddr_in, namelen As Integer)
Declare Function getsockname% Lib "winsock.dll" Alias "#6" (ByVal s As Integer, sockname As sockaddr_in, namelen As Integer)
Declare Function getsockopt% Lib "winsock.dll" Alias "#7" (ByVal s As Integer, ByVal level As Integer, ByVal optname As Integer, ByVal optval As String, optlen As Integer)
Declare Function htonl& Lib "winsock.dll" Alias "#8" (ByVal hostlong As Long)
Declare Function htons% Lib "winsock.dll" Alias "#9" (ByVal hostshort As Integer)
Declare Function inet_addr& Lib "winsock.dll" Alias "#10" (ByVal cp As String)
Declare Function inet_ntoa& Lib "winsock.dll" Alias "#11" (ByVal in As Long)
Declare Function listen& Lib "winsock.dll" Alias "#12" (ByVal s As Integer, ByVal backlog As Integer)
Declare Function ntohl& Lib "winsock.dll" Alias "#14" (ByVal netlong As Long)
Declare Function ntohs% Lib "winsock.dll" Alias "#15" (ByVal netshort As Integer)
Declare Function recv% Lib "winsock.dll" Alias "#16" (ByVal s As Integer, ByVal buf As String, ByVal buflen As Integer, ByVal flags As Integer)
Declare Function recvfrom% Lib "winsock.dll" Alias "#17" (ByVal s As Integer, ByVal buf As String, ByVal buflen As Integer, ByVal flags As Integer, fromaddr As sockaddr_in, fromlen As Integer)
' Visual Basic note...since select is a keyword in Visual Basic the function has been renamed
Declare Function WSASelect% Lib "winsock.dll" Alias "#18" (ByVal nfds As Integer, readfds As FD_SET, writefds As FD_SET, exceptfds As FD_SET, timeout As timeval)
Declare Function send% Lib "winsock.dll" Alias "#19" (ByVal s As Integer, ByVal buf As String, ByVal buflen As Integer, ByVal flags As Integer)
Declare Function sendto% Lib "winsock.dll" Alias "#20" (ByVal s As Integer, ByVal buf As String, ByVal buflen As Integer, ByVal flags As Integer, toaddr As sockaddr_in, ByVal tolen As Integer)
Declare Function setsockopt% Lib "winsock.dll" Alias "#21" (ByVal s As Integer, ByVal level As Integer, ByVal optname As Integer, optval As Long, ByVal optlen As Integer)
Declare Function shutdown% Lib "winsock.dll" Alias "#22" (ByVal s As Integer, ByVal how As Integer)
Declare Function socket% Lib "winsock.dll" Alias "#23" (ByVal af As Integer, ByVal socktype As Integer, ByVal protocol As Integer)
Declare Function gethostbyaddr& Lib "winsock.dll" Alias "#51" (addr As Long, ByVal addrlen As Integer, ByVal addrtype As Integer)
Declare Function GetHostByName& Lib "winsock.dll" Alias "#52" (ByVal hostname As String)
Declare Function GetHostName% Lib "winsock.dll" Alias "#57" (ByVal hostname As Long, ByVal namelen As Integer)
Declare Function getservbyport& Lib "winsock.dll" Alias "#56" (ByVal port As Integer, ByVal protoname As Long)
Declare Function getservbyname& Lib "winsock.dll" Alias "#55" (ByVal servname As Long, ByVal protoname As Long)
Declare Function getprotobynumber& Lib "winsock.dll" Alias "#54" (ByVal protonumber As Integer)
Declare Function getprotobyname& Lib "winsock.dll" Alias "#53" (ByVal protoname As String)
Declare Function WSAStartup% Lib "winsock.dll" Alias "#115" (ByVal wVersionRequired As Integer, lpWSAData As WSAData)
Declare Function WSACleanUp% Lib "winsock.dll" Alias "#116" ()
Declare Function WSASetLastError% Lib "winsock.dll" Alias "#112" (ByVal iError As Integer)
Declare Function WSAGetLastError% Lib "winsock.dll" Alias "#111" ()
Declare Function WSAIsBlocking% Lib "winsock.dll" Alias "#114" ()
Declare Function WSAUnhookBlockingHook% Lib "winsock.dll" Alias "#110" ()
Declare Function WSASetBlockingHook& Lib "winsock.dll" Alias "#109" (lpFunc As Long)
Declare Function WSACancelBlockingCall% Lib "winsock.dll" Alias "#113" ()
Declare Function WSAAsyncGetServByName% Lib "winsock.dll" Alias "#107" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal hostname As String, ByVal proto As String, ByVal buf As String, ByVal buflen As Integer)
Declare Function WSAAsyncGetServByPort% Lib "winsock.dll" Alias "#106" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal port As Integer, ByVal proto As String, ByVal buf As String, ByVal buflen As Integer)
Declare Function WSAAsyncGetProtoByName% Lib "winsock.dll" Alias "#105" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal protoname As String, ByVal buf As String, ByVal buflen As Integer)
Declare Function WSAAsyncGetProtoByNumber% Lib "winsock.dll" Alias "#104" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal number As Integer, ByVal buf As String, ByVal buflen As Integer)
Declare Function WSAAsyncGetHostByName% Lib "winsock.dll" Alias "#103" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal hostname As String, ByVal buf As String, ByVal buflen As Integer)
Declare Function WSAAsyncGetHostByAddr% Lib "winsock.dll" Alias "#102" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal addr As String, ByVal addrlen As Integer, ByVal addrtype As Integer, ByVal buf As String, ByVal buflen As Integer)
Declare Function WSACancelAsyncRequest% Lib "winsock.dll" Alias "#108" (ByVal hAsyncTaskHandle As Integer)
Declare Function WSAAsyncSelect% Lib "winsock.dll" Alias "#101" (ByVal s As Integer, ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal lEvent As Long)
'Winsock Subroutines as described in the Winsock standard
Declare Function GetHostAddressByName Lib "hostname.dll" Alias "GETHOSTADDRESSFROMNAME" (ByVal yourhostname As String) As Long
Sub FD_CLR (ByVal fd As Integer, fdset As FD_SET)
'--------------------
' remove fd from set
'--------------------
Dim i As Integer
For i = 0 To (fdset.fd_count) - 1 'loop thru entries