#ifndef _WINSOCK2API_
#define _WINSOCK2API_
#define _WINSOCKAPI_

Const WINSOCK_VERSION = MAKEWORD(2, 2)

TypeDef SOCKET = ULONG_PTR

Const FD_SETSIZE = 64

Type fd_set
	fd_count As DWord
	fd_array[ELM(FD_SETSIZE)] As SOCKET
End Type

Declare Function __WSAFDIsSet Lib "ws2_32" (fd As SOCKET, ByRef set As fd_set) As Long

Sub FD_CLR(fd As SOCKET, ByRef set As fd_set)
	Dim i As DWord
	With set
		For i = 0 To .fd_count
			If .fd_array[i] = fd Then
				While i < .fd_count - 1
					.fd_array[i] = .fd_array[i + 1]
				WEnd
				.fd_count--
				Exit For
			End If
		Next
	End With
End Sub

Sub FD_SET(fd As SOCKET, ByRef set As fd_set)
	Dim i As DWord
	With set
		For i = 0 To ELM(.fd_count)
			If .fd_array[i] = fd Then
				Exit Sub
			End If
		Next
		If i = .fd_count Then
			If .fd_count < FD_SETSIZE Then
				.fd_array[i] = fd
				.fd_count++
			End If
		End If
	End With
End Sub

Sub FD_ZERO(ByRef set As fd_set)
	set.fd_count = 0
End Sub

Const FD_ISSET(fd, set) = __WSAFDIsSet(fd, set)

Type timeval
	tv_sec As  Long
	tv_usec As  Long
End Type

' Operations on timevals.
Function timerisset(ByRef tvp As timeval) As BOOL
	Return tvp.tv_sec Or tvp.tv_usec
End Function

/*
#define timercmp(tvp, uvp, cmp) \
        ((tvp)->tv_sec cmp (uvp)->tv_sec || \
         (tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
*/

Sub timerclear(ByRef tvp As timeval)
	tvp.tv_sec = 0
	tvp.tv_usec = 0
End Sub

' Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
Const IOCPARM_MASK = &h7f
Const IOC_VOID = &h20000000
Const IOC_OUT = &h40000000
Const IOC_IN = &h80000000
Const IOC_INOUT= (IOC_IN Or IOC_OUT)

Const _IO(x ,y) = (IOC_VOID Or (x << 8) Or y)

Const _IOR(x, y, size) = (IOC_OUT Or ((size And IOCPARM_MASK) << 16) Or ((x) << 8) Or (y))

Const _IOW(x, y, size) = (IOC_IN Or ((size And IOCPARM_MASK) << 16) Or ((x) << 8) Or (y))

Const FIONREAD = _IOR(&h66,127, SizeOf (DWord)) '&h66‚Í'f'
Const FIONBIO = _IOW(&h66,126, SizeOf (DWord))
Const FIOASYNC = _IOW(&h66,125, SizeOf (DWord))

' Socket I/O Controls
Const SIOCSHIWAT = _IOW(&h73, 0, SizeOf (DWord)) '&h73‚Í's'
Const SIOCGHIWAT = _IOR(&h73, 1, SizeOf (DWord))
Const SIOCSLOWAT = _IOW(&h73, 2, SizeOf (DWord))
Const SIOCGLOWAT = _IOR(&h73, 3, SizeOf (DWord))
Const SIOCATMARK = _IOR(&h73, 7, SizeOf (DWord))


Type /*Class*/ hostent
'Public
	h_name As *Byte
	h_aliases As **Byte
	h_addrtype As Integer
	h_lengt As Integer
	h_addr_list As **Byte
/*
	Function h_addr() As *Byte
		Return h_addr_list[0]
	End Function

	Sub h_addr(l As *Byte)
		h_addr_list[0] = i
	End Sub
*/
End Type 'Class

Type netent
	n_name As *Byte
	n_aliases As **Byte
	n_addrtyp As Integer
	n_net As DWord
End Type

Type servent
	s_name As *Byte
	s_aliases As **Byte
#ifdef _WIN64
	s_proto As *Byte
	s_port As Integer
#else
	s_port As Integer
	s_proto As *Byte
#endif
End Type

Type protoent
	p_name As *Byte
	p_aliases As **Byte
	p_proto As Integer
End Type

' Protocols
Const IPPROTO_IP = 0
Const IPPROTO_HOPOPTS = 0
Const IPPROTO_ICMP = 1
Const IPPROTO_IGMP = 2
Const IPPROTO_GGP = 3
Const IPPROTO_IPV4 = 4
Const IPPROTO_TCP = 6
Const IPPROTO_PUP = 12
Const IPPROTO_UDP = 17
Const IPPROTO_IDP = 22
Const IPPROTO_IPV6 = 41
Const IPPROTO_ROUTING = 43
Const IPPROTO_FRAGMENT = 44
Const IPPROTO_ESP = 50
Const IPPROTO_AH = 51
Const IPPROTO_ICMPV6 = 58
Const IPPROTO_NONE = 59
Const IPPROTO_DSTOPTS = 60
Const IPPROTO_ND = 77
Const IPPROTO_ICLFXBM = 78

Const IPPROTO_RAW = 255
Const IPPROTO_MAX = 256

' Port/socket numbers: network standard functions
Const IPPORT_ECHO = 7
Const IPPORT_DISCARD = 9
Const IPPORT_SYSTAT = 11
Const IPPORT_DAYTIME = 13
Const IPPORT_NETSTAT = 15
Const IPPORT_FTP = 21
Const IPPORT_TELNET = 23
Const IPPORT_SMTP = 25
Const IPPORT_TIMESERVER = 37
Const IPPORT_NAMESERVER = 42
Const IPPORT_WHOIS = 43
Const IPPORT_MTP = 57

' Port/socket numbers: host specific functions
Const IPPORT_TFTP = 69
Const IPPORT_RJE = 77
Const IPPORT_FINGER = 79
Const IPPORT_TTYLINK = 87
Const IPPORT_SUPDUP = 95

' UNIX TCP sockets
Const IPPORT_EXECSERVER = 512
Const IPPORT_LOGINSERVER = 513
Const IPPORT_CMDSERVER = 514
Const IPPORT_EFSSERVER = 520

' UNIX UDP sockets
Const IPPORT_BIFFUDP = 512
Const IPPORT_WHOSERVER = 513
Const IPPORT_ROUTESERVER = 520
' 520+1 also used

' Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root).
Const IPPORT_RESERVED = 1024

' Link numbers
Const IMPLINK_IP = 155
Const IMPLINK_LOWEXPER = 156
Const IMPLINK_HIGHEXPER = 158

' Internet address (old style... should be updated)
Type /*Class*/ in_addr
'Public
/*
	Union S_un
		S_un_b As Type
			s_b1 As Byte
			s_b2 As Byte
			s_b3 As Byte
			s_b4 As Byte
		End Type
		S_un_w As Type
			s_w1 As Word
			s_w2 As Word
		End Type
		S_addr As DWord
	End Union
*/
	s_addr As DWord
/*
	Function s_host() As Byte
		Return GetByte(VarPtr(s_addr) + 1)
	End Function

	Sub s_host(h As Byte)
		Return SetByte(VarPtr(s_addr) + 2, h)
	End Sub

	Function s_net() As Byte
		Return GetByte(VarPtr(s_addr) + 0)
	End Function

	Sub s_net(n As Byte)
		Return SetByte(VarPtr(s_addr) + 0, n)
	End Sub

	Function s_imp() As Word
		Return GetWord(VarPtr(s_addr) + 1)
	End Function

	Sub s_imp(i As Word)
		Return SetWord(VarPtr(s_addr) + 1, i)
	End Sub

	Function s_impno() As Byte
		Return GetByte(VarPtr(s_addr) + 3)
	End Function

	Sub s_impno(i As Byte)
		Return SetByte(VarPtr(s_addr) + 3, i)
	End Sub

	Function s_lh() As Byte
		Return GetByte(VarPtr(s_addr) + 2)
	End Function

	Sub s_lh(l As Byte)
		Return SetByte(VarPtr(s_addr) + 2, l)
	End Sub
*/
End Type 'Class

Const IN_CLASSA(i) = (((i) As DWord And &h80000000) = 0)
Const IN_CLASSA_NET = &hff000000
Const IN_CLASSA_NSHIFT = 24
Const IN_CLASSA_HOST = &h00ffffff
Const IN_CLASSA_MAX = 128

Const IN_CLASSB(i) = (((i) As DWord & &hc0000000) = &h80000000)
Const IN_CLASSB_NET= &hffff0000
Const IN_CLASSB_NSHIFT = 16
Const IN_CLASSB_HOST = &h0000ffff
Const IN_CLASSB_MAX = 65536

Const IN_CLASSC(i) = (((i) As DWord And &he0000000) = &hc0000000)
Const IN_CLASSC_NET = &hffffff00
Const IN_CLASSC_NSHIFT = 8
Const IN_CLASSC_HOST = &h000000ff

Const IN_CLASSD(i) = (((i) As DWord And &hf0000000) = &he0000000)
Const IN_CLASSD_NET  = &hf0000000
Const IN_CLASSD_NSHIFT = 28
Const IN_CLASSD_HOST = &h0fffffff
Const IN_MULTICAST(i) = IN_CLASSD(i)

Const INADDR_ANY = &h00000000 As DWord
Const INADDR_LOOPBACK = &h7f000001
Const INADDR_BROADCAST = &hffffffff As DWord
Const INADDR_NONE = &hffffffff

Const 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[ELM(8)] As Byte
End Type

Const WSADESCRIPTION_LEN = 256
Const WSASYS_STATUS_LEN = 128

Type WSADATA
	wVersion As Word
	wHighVersion As Word
#ifdef _WIN64
	iMaxSockets As Word
	iMaxUdpDg As Word
	lpVendorInfo As *Byte
	szDescription[WSADESCRIPTION_LEN] As Byte
	szSystemStatus[WSASYS_STATUS_LEN] As Byte
#else
	szDescription[WSADESCRIPTION_LEN] As Byte
	szSystemStatus[WSASYS_STATUS_LEN] As Byte
	iMaxSockets As Word
	iMaxUdpDg As Word
	lpVendorInfo As *Byte
#endif
End Type

TypeDef LPWSADATA = *WSADATA

' Definitions related to sockets: types, address families, options,  taken from the BSD file sys/socket.h.

Const INVALID_SOCKET = (Not 0) As ULONG_PTR
Const SOCKET_ERROR = (-1)

Const FROM_PROTOCOL_INFO = (-1)

' Types
Const SOCK_STREAM = 1
Const SOCK_DGRAM = 2
Const SOCK_RAW = 3
Const SOCK_RDM = 4
Const SOCK_SEQPACKET = 5

' Option flags per-socket.
Const SO_DEBUG = &h0001
Const SO_ACCEPTCONN = &h0002
Const SO_REUSEADDR = &h0004
Const SO_KEEPALIVE = &h0008
Const SO_DONTROUTE = &h0010
Const SO_BROADCAST = &h0020
Const SO_USELOOPBACK = &h0040
Const SO_LINGER = &h0080
Const SO_OOBINLINE = &h0100

Const SO_DONTLINGER = ((Not SO_LINGER) As Long)
Const SO_EXCLUSIVEADDRUSE = ((Not SO_REUSEADDR) As Long)

' Additional options.
Const SO_SNDBUF = &h1001
Const SO_RCVBUF = &h1002
Const SO_SNDLOWAT = &h1003
Const SO_RCVLOWAT = &h1004
Const SO_SNDTIMEO = &h1005
Const SO_RCVTIMEO = &h1006
Const SO_ERROR = &h1007
Const SO_TYPE = &h1008

' WinSock 2 extension -- new options
Const SO_GROUP_ID = &h2001
Const SO_GROUP_PRIORITY = &h2002
Const SO_MAX_MSG_SIZE = &h2003
Const SO_PROTOCOL_INFOA = &h2004
Const SO_PROTOCOL_INFOW = &h2005
#ifdef UNICODE
Const SO_PROTOCOL_INFO = SO_PROTOCOL_INFOW
#else
Const SO_PROTOCOL_INFO = SO_PROTOCOL_INFOA
#endif /* UNICODE */
Const PVD_CONFIG = &h3001
Const SO_CONDITIONAL_ACCEPT = &h3002

' TCP options.
Const TCP_NODELAY = &h0001

' Address families.
Const AF_UNSPEC = 0
Const AF_UNIX = 1
Const AF_INET = 2
Const AF_IMPLINK = 3
Const AF_PUP = 4
Const AF_CHAOS = 5
Const AF_NS = 6
Const AF_IPX = AF_NS
Const AF_ISO = 7
Const AF_OSI = AF_ISO
Const AF_ECMA = 8
Const AF_DATAKIT = 9
Const AF_CCITT = 10
Const AF_SNA = 11
Const AF_DECnet = 12
Const AF_DLI = 13
Const AF_LAT = 14
Const AF_HYLINK = 15
Const AF_APPLETALK = 16
Const AF_NETBIOS = 17
Const AF_VOICEVIEW = 18
Const AF_FIREFOX = 19
Const AF_UNKNOWN1 = 20
Const AF_BAN = 21
Const AF_ATM = 22
Const AF_INET6 = 23
Const AF_CLUSTER = 24
Const AF_12844 = 25
Const AF_IRDA = 26
Const AF_NETDES = 28

Const AF_TCNPROCESS = 29
Const AF_TCNMESSAGE = 30
Const AF_ICLFXBM = 31

Const AF_MAX = 32

' Structure used by kernel to store most addresses.
Type sockaddr
	sa_family As Word
	sa_data[ELM(14)] As Byte
End Type

' Portable socket structure (RFC 2553).

' Desired design of maximum size and alignment.
' These are implementation specific.
Const _SS_MAXSIZE = 128 ' Maximum size.
Const _SS_ALIGNSIZE = (SizeOf (Int64)) 'Desired alignment.

' Definitions used for sockaddr_storage structure paddings design.
Const _SS_PAD1SIZE = (_SS_ALIGNSIZE - SizeOf (Integer))
Const _SS_PAD2SIZE = (_SS_MAXSIZE - (SizeOf (Integer) + _SS_PAD1SIZE + _SS_ALIGNSIZE))

Type sockaddr_storage
	ss_family As Integer
	__ss_pad1[ELM(_SS_PAD1SIZE)] As Byte
	__ss_align As Int64
	__ss_pad2[ELM(_SS_PAD2SIZE)] As Byte
End Type

Type sockproto
	sp_family As Word
	sp_protocol As Word
End Type

' Protocol families, same as address families for now.
Const PF_UNSPEC = AF_UNSPEC
Const PF_UNIX = AF_UNIX
Const PF_INET = AF_INET
Const PF_IMPLINK = AF_IMPLINK
Const PF_PUP = AF_PUP
Const PF_CHAOS = AF_CHAOS
Const PF_NS = AF_NS
Const PF_IPX = AF_IPX
Const PF_ISO = AF_ISO
Const PF_OSI = AF_OSI
Const PF_ECMA = AF_ECMA
Const PF_DATAKIT = AF_DATAKIT
Const PF_CCITT = AF_CCITT
Const PF_SNA = AF_SNA
Const PF_DECnet = AF_DECnet
Const PF_DLI = AF_DLI
Const PF_LAT = AF_LAT
Const PF_HYLINK = AF_HYLINK
Const PF_APPLETALK = AF_APPLETALK
Const PF_VOICEVIEW = AF_VOICEVIEW
Const PF_FIREFOX = AF_FIREFOX
Const PF_UNKNOWN1 = AF_UNKNOWN1
Const PF_BAN = AF_BAN
Const PF_ATM = AF_ATM
Const PF_INET6 = AF_INET6

Const PF_MAX = AF_MAX

' Structure used for manipulating linger option.
Type linger
	l_onoff As Word
	l_linger As Word
End Type

' Level number for (get/set)sockopt() to apply to socket itself.
Const SOL_SOCKET = &hffff

' Maximum queue length specifiable by listen.
Const SOMAXCONN = &h7fffffff

Const MSG_OOB = &h1
Const MSG_PEEK = &h2
Const MSG_DONTROUTE = &h4
Const MSG_WAITALL = &h8

Const MSG_PARTIAL = &h8000

' WinSock 2 extension -- new flags for WSASend(), WSASendTo(), WSARecv() and
'                          WSARecvFrom()
Const MSG_INTERRUPT = &h10

Const MSG_MAXIOVLEN = 16

' Define constant based on rfc883, used by gethostbyxxxx() calls.
Const MAXGETHOSTSTRUCT = 1024

' WinSock 2 extension -- bit values and indices for FD_XXX network events
Const FD_READ_BIT = 0
Const FD_READ = (1 << FD_READ_BIT)

Const FD_WRITE_BIT = 1
Const FD_WRITE = (1 << FD_WRITE_BIT)

Const FD_OOB_BIT = 2
Const FD_OOB = (1 << FD_OOB_BIT)

Const FD_ACCEPT_BIT = 3
Const FD_ACCEPT = (1 << FD_ACCEPT_BIT)

Const FD_CONNECT_BIT = 4
Const FD_CONNECT = (1 << FD_CONNECT_BIT)

Const FD_CLOSE_BIT = 5
Const FD_CLOSE = (1 << FD_CLOSE_BIT)

Const FD_QOS_BIT = 6
Const FD_QOS = (1 << FD_QOS_BIT)

Const FD_GROUP_QOS_BIT = 7
Const FD_GROUP_QOS = (1 << FD_GROUP_QOS_BIT)

Const FD_ROUTING_INTERFACE_CHANGE_BIT = 8
Const FD_ROUTING_INTERFACE_CHANGE = (1 << FD_ROUTING_INTERFACE_CHANGE_BIT)

Const FD_ADDRESS_LIST_CHANGE_BIT = 9
Const FD_ADDRESS_LIST_CHANGE = (1 << FD_ADDRESS_LIST_CHANGE_BIT)

Const FD_MAX_EVENTS = 10
Const FD_ALL_EVENTS = ((1 << FD_MAX_EVENTS) - 1)

#require <api_winerror.sbp>

' Compatibility macros.

'Const h_errno = WSAGetLastError()
Const HOST_NOT_FOUND = WSAHOST_NOT_FOUND
Const TRY_AGAIN = WSATRY_AGAIN
Const NO_RECOVERY = WSANO_RECOVERY
Const NO_DATA = WSANO_DATA
Const WSANO_ADDRESS = WSANO_DATA
Const NO_ADDRESS = WSANO_ADDRESS

' WinSock 2 extension -- new error codes and type definition

'#ifdef _WIN32

TypeDef WSAEVENT = HANDLE
TypeDef LPWSAEVENT = *HANDLE
TypeDef WSAOVERLAPPED = OVERLAPPED
TypeDef LPWSAOVERLAPPED = *OVERLAPPED

Const WSA_IO_PENDING = (ERROR_IO_PENDING)
Const WSA_IO_INCOMPLETE = (ERROR_IO_INCOMPLETE)
Const WSA_INVALID_HANDLE = (ERROR_INVALID_HANDLE)
Const WSA_INVALID_PARAMETER = (ERROR_INVALID_PARAMETER)
Const WSA_NOT_ENOUGH_MEMORY = (ERROR_NOT_ENOUGH_MEMORY)
Const WSA_OPERATION_ABORTED = (ERROR_OPERATION_ABORTED)

Const WSA_INVALID_EVENT = (0 As WSAEVENT)
Const WSA_MAXIMUM_WAIT_EVENTS = (MAXIMUM_WAIT_OBJECTS)
Const WSA_WAIT_FAILED = (WAIT_FAILED)
Const WSA_WAIT_EVENT_0 = (WAIT_OBJECT_0)
Const WSA_WAIT_IO_COMPLETION = (WAIT_IO_COMPLETION)
Const WSA_WAIT_TIMEOUT = (WAIT_TIMEOUT)
Const WSA_INFINITE = (INFINITE)

'#elif defined _WIN16
'#endif

Type WSABUF
	len As DWord
	buf As *Byte
End Type
TypeDef LPWSABUF = *WSABUF

#require <qos.ab>

Type QOS 'struct _QualityOfService
	SendingFlowspec As FLOWSPEC
	ReceivingFlowspec As FLOWSPEC
	ProviderSpecific As WSABUF
End Type
TypeDef LPQOS = *QOS

' WinSock 2 extension -- manifest constants for return values of the condition function
Const CF_ACCEPT = &h0000
Const CF_REJECT = &h0001
Const CF_DEFER = &h0002

' WinSock 2 extension -- manifest constants for shutdown()
Const SD_RECEIVE = &h00
Const SD_SEND = &h01
Const SD_BOTH = &h02

' WinSock 2 extension -- data type and manifest constants for socket groups
TypeDef GROUP = DWord

Const SG_UNCONSTRAINED_GROUP = &h01
Const SG_CONSTRAINED_GROUP = &h02

' WinSock 2 extension -- data type for WSAEnumNetworkEvents()
Type WSANETWORKEVENTS
	lNetworkEvents As Long
	iErrorCode[ELM(FD_MAX_EVENTS)] As Long
End Type
TypeDef LPWSANETWORKEVENTS = *WSANETWORKEVENTS

' WinSock 2 extension -- WSAPROTOCOL_INFO structure and associated
' manifest constants

Const MAX_PROTOCOL_CHAIN = 7

Const BASE_PROTOCOL = 1
Const LAYERED_PROTOCOL = 0

Type WSAPROTOCOLCHAIN
	ChainLen As Long
	ChainEntries[ELM(MAX_PROTOCOL_CHAIN)] As DWord
End Type
TypeDef LPWSAPROTOCOLCHAIN = *WSAPROTOCOLCHAIN

Const WSAPROTOCOL_LEN = 255

Type WSAPROTOCOL_INFOA
	dwServiceFlags1 As DWord
	dwServiceFlags2 As DWord
	dwServiceFlags3 As DWord
	dwServiceFlags4 As DWord
	dwProviderFlags As DWord
	ProviderId As GUID
	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[WSAPROTOCOL_LEN] As Byte
End Type
TypeDef LPWSAPROTOCOL_INFOA = *WSAPROTOCOL_INFOA

Type WSAPROTOCOL_INFOW
	dwServiceFlags1 As DWord
	dwServiceFlags2 As DWord
	dwServiceFlags3 As DWord
	dwServiceFlags4 As DWord
	dwProviderFlags As DWord
	ProviderId As GUID
	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[WSAPROTOCOL_LEN] As WCHAR
End Type
TypeDef LPWSAPROTOCOL_INFOW = *WSAPROTOCOL_INFOW

#ifdef UNICODE
TypeDef WSAPROTOCOL_INFO = WSAPROTOCOL_INFOW
TypeDef LPWSAPROTOCOL_INFO = LPWSAPROTOCOL_INFOW
#else
TypeDef WSAPROTOCOL_INFO = WSAPROTOCOL_INFOA
TypeDef LPWSAPROTOCOL_INFO = LPWSAPROTOCOL_INFOA
#endif

' Flag bit definitions for dwProviderFlags
Const PFL_MULTIPLE_PROTO_ENTRIES = &h00000001
Const PFL_RECOMMENDED_PROTO_ENTRY = &h00000002
Const PFL_HIDDEN = &h00000004
Const PFL_MATCHES_PROTOCOL_ZERO = &h00000008

' Flag bit definitions for dwServiceFlags1
Const XP1_CONNECTIONLESS = &h00000001
Const XP1_GUARANTEED_DELIVERY = &h00000002
Const XP1_GUARANTEED_ORDER = &h00000004
Const XP1_MESSAGE_ORIENTED = &h00000008
Const XP1_PSEUDO_STREAM = &h00000010
Const XP1_GRACEFUL_CLOSE = &h00000020
Const XP1_EXPEDITED_DATA = &h00000040
Const XP1_CONNECT_DATA = &h00000080
Const XP1_DISCONNECT_DATA = &h00000100
Const XP1_SUPPORT_BROADCAST = &h00000200
Const XP1_SUPPORT_MULTIPOINT = &h00000400
Const XP1_MULTIPOINT_CONTROL_PLANE = &h00000800
Const XP1_MULTIPOINT_DATA_PLANE = &h00001000
Const XP1_QOS_SUPPORTED = &h00002000
Const XP1_INTERRUPT = &h00004000
Const XP1_UNI_SEND = &h00008000
Const XP1_UNI_RECV = &h00010000
Const XP1_IFS_HANDLES = &h00020000
Const XP1_PARTIAL_MESSAGE = &h00040000

Const BIGENDIAN = &h0000
Const LITTLEENDIAN = &h0001

Const SECURITY_PROTOCOL_NONE = &h0000

' WinSock 2 extension -- manifest constants for WSAJoinLeaf()
Const JL_SENDER_ONLY = &h01
Const JL_RECEIVER_ONLY = &h02
Const JL_BOTH = &h04

' WinSock 2 extension -- manifest constants for WSASocket()
Const WSA_FLAG_OVERLAPPED = &h01
Const WSA_FLAG_MULTIPOINT_C_ROOT = &h02
Const WSA_FLAG_MULTIPOINT_C_LEAF = &h04
Const WSA_FLAG_MULTIPOINT_D_ROOT = &h08
Const WSA_FLAG_MULTIPOINT_D_LEAF = &h10

' WinSock 2 extension -- manifest constants for WSAIoctl()
Const IOC_UNIX = &h00000000
Const IOC_WS2 = &h08000000
Const IOC_PROTOCOL = &h10000000
Const IOC_VENDOR = &h18000000

Const _WSAIO(x, y) = (IOC_VOID Or (x) Or (y))
Const _WSAIOR(x, y) = (IOC_OUT Or (x) Or (y))
Const _WSAIOW(x, y) = (IOC_IN Or (x) Or (y))
Const _WSAIORW(x, y) = (IOC_INOUT Or (x) Or (y))

Const SIO_ASSOCIATE_HANDLE = _WSAIOW(IOC_WS2, 1)
Const SIO_ENABLE_CIRCULAR_QUEUEING = _WSAIO(IOC_WS2, 2)
Const SIO_FIND_ROUTE = _WSAIOR(IOC_WS2, 3)
Const SIO_FLUSH = _WSAIO(IOC_WS2, 4)
Const SIO_GET_BROADCAST_ADDRESS = _WSAIOR(IOC_WS2, 5)
Const SIO_GET_EXTENSION_FUNCTION_POINTER = _WSAIORW(IOC_WS2, 6)
Const SIO_GET_QOS = _WSAIORW(IOC_WS2, 7)
Const SIO_GET_GROUP_QOS = _WSAIORW(IOC_WS2, 8)
Const SIO_MULTIPOINT_LOOPBACK = _WSAIOW(IOC_WS2, 9)
Const SIO_MULTICAST_SCOPE = _WSAIOW(IOC_WS2, 10)
Const SIO_SET_QOS = _WSAIOW(IOC_WS2, 11)
Const SIO_SET_GROUP_QOS = _WSAIOW(IOC_WS2, 12)
Const SIO_TRANSLATE_HANDLE = _WSAIORW(IOC_WS2, 13)
Const SIO_ROUTING_INTERFACE_QUERY = _WSAIORW(IOC_WS2, 20)
Const SIO_ROUTING_INTERFACE_CHANGE = _WSAIOW(IOC_WS2, 21)
Const SIO_ADDRESS_LIST_QUERY = _WSAIOR(IOC_WS2, 22)
Const SIO_ADDRESS_LIST_CHANGE = _WSAIO(IOC_WS2, 23)
Const SIO_QUERY_TARGET_PNP_HANDLE = _WSAIOR(IOC_WS2, 24)
Const SIO_ADDRESS_LIST_SORT = _WSAIORW(IOC_WS2, 25)

' WinSock 2 extensions -- data types for the condition function in
' WSAAccept() and overlapped I/O completion routine.

TypeDef LPCONDITIONPROC = *Function(
	ByRef CallerId As WSABUF,
	ByRef CallerData As WSABUF,
	ByRef lpSQOS As QOS,
	ByRef lpGQOS As QOS,
	ByRef lpCalleeId As WSABUF,
	ByRef lpCalleeData As WSABUF,
	ByRef g As GROUP,
	dwCallbackData As ULONG_PTR
) As Long

TypeDef LPWSAOVERLAPPED_COMPLETION_ROUTINE = *Sub(
	dwError As DWord,
	cbTransferred As DWord,
	ByRef Overlapped As WSAOVERLAPPED,
	dwFlags As DWord)

' WinSock 2 extension -- manifest constants and associated structures
' for WSANSPIoctl()
Const SIO_NSP_NOTIFY_CHANGE = _WSAIOW(IOC_WS2, 25)

Const Enum WSACOMPLETIONTYPE
	NSP_NOTIFY_IMMEDIATELY = 0
	NSP_NOTIFY_HWND
	NSP_NOTIFY_EVENT
	NSP_NOTIFY_PORT
	NSP_NOTIFY_APC
End Enum

TypeDef PWSACOMPLETIONTYPE = *WSACOMPLETIONTYPE
TypeDef LPWSACOMPLETIONTYPE = *WSACOMPLETIONTYPE

Type _System_WinSock_WSACOMPLETION_WINDOWMESSAGE
	hWnd As HWND
	uMsg As DWord
	context As WPARAM
End Type

Type _System_WinSock_WSACOMPLETION_EVENT
	lpOverlapped As LPWSAOVERLAPPED
End Type

Type _System_WinSock_WSACOMPLETION_APC
	lpOverlapped As LPWSAOVERLAPPED
	lpfnCompletionProc As LPWSAOVERLAPPED_COMPLETION_ROUTINE
End Type

Type _System_WinSock_WSACOMPLETION_PORT
	lpOverlapped As LPWSAOVERLAPPED
	hPort As HANDLE
	Key As ULONG_PTR
End Type

Type /*Class*/ WSACOMPLETION
'Public
	Type_ As WSACOMPLETIONTYPE
/*
	Parameters As Union
		WindowMessage As _System_WinSock_WSACOMPLETION_WINDOWMESSAGE
		Event As _System_WinSock_WSACOMPLETION_EVENT
		Apc As _System_WinSock_WSACOMPLETION_APC
		Port As _System_WinSock_WSACOMPLETION_PORT
	End Union
*/
	Port As _System_WinSock_WSACOMPLETION_PORT
/*
	Function WindowMessage() As _System_WinSock_WSACOMPLETION_WINDOWMESSAGE
		Dim p As *_System_WinSock_WSACOMPLETION_WINDOWMESSAGE
		p = VarPtr(Port) As *_System_WinSock_WSACOMPLETION_WINDOWMESSAGE
		Return p[0]
	End Function

	Sub WindowMessage(w As _System_WinSock_WSACOMPLETION_WINDOWMESSAGE)
		Dim p As *_System_WinSock_WSACOMPLETION_WINDOWMESSAGE
		p = VarPtr(Port) As *_System_WinSock_WSACOMPLETION_WINDOWMESSAGE
		p[0] = w
	End Sub

	Function Event() As _System_WinSock_WSACOMPLETION_EVENT
		Dim p As *_System_WinSock_WSACOMPLETION_EVENT
		p = VarPtr(Port) As *_System_WinSock_WSACOMPLETION_EVENT
		Return p[0]
	End Function

	Sub Event(e As _System_WinSock_WSACOMPLETION_EVENT)
		Dim p As *_System_WinSock_WSACOMPLETION_EVENT
		p = VarPtr(Port) As *_System_WinSock_WSACOMPLETION_EVENT
		p[0] = e
	End Sub

	Function Apc() As _System_WinSock_WSACOMPLETION_APC
		Dim p As *_System_WinSock_WSACOMPLETION_APC
		p = VarPtr(Port) As *_System_WinSock_WSACOMPLETION_APC
		Return p[0]
	End Function

	Sub Apc(a As _System_WinSock_WSACOMPLETION_APC)
		Dim p As *_System_WinSock_WSACOMPLETION_APC
		p = VarPtr(Port) As *_System_WinSock_WSACOMPLETION_APC
		p[0] = a
	End Sub
/*
	Function Port() As _System_WinSock_WSACOMPLETION_PORT
		Dim p As *_System_WinSock_WSACOMPLETION_PORT
		p = VarPtr(Port) As *_System_WinSock_WSACOMPLETION_PORT
		Return p[0]
	End Function

	Sub Port(p As _System_WinSock_WSACOMPLETION_PORT)
		Dim p As *_System_WinSock_WSACOMPLETION_PORT
		p = VarPtr(Port) As *_System_WinSock_WSACOMPLETION_PORT
		p[0] = p
	End Sub
*/
End Type 'Class

TypeDef PWSACOMPLETION = *WSACOMPLETION
TypeDef LPWSACOMPLETION = *WSACOMPLETION

' WinSock 2 extension -- manifest constants for SIO_TRANSLATE_HANDLE ioctl
Const TH_NETDEV = &h00000001
Const TH_TAPI = &h00000002

TypeDef SOCKADDR = sockaddr
TypeDef PSOCKADDR = *sockaddr
TypeDef LPSOCKADDR = *sockaddr

TypeDef SOCKADDR_STORAGE = sockaddr_storage
TypeDef PSOCKADDR_STORAGE = *sockaddr_storage
TypeDef LPSOCKADDR_STORAGE = *sockaddr_storage

' Manifest constants and type definitions related to name resolution and
' registration (RNR) API

Type BLOB
	cbSize As DWord
#ifdef MIDL_PASS
	[size_is(cbSize)] pBlobData As *Byte
#else
	pBlobData As *Byte
#endif
End Type
TypeDef LPBLOB = *BLOB

' Service Install Flags
Const SERVICE_MULTIPLE = (&h00000001)

' Name Spaces

Const NS_ALL = (0)

Const NS_SAP = (1)
Const NS_NDS = (2)
Const NS_PEER_BROWSE = (3)
Const NS_SLP = (5)
Const NS_DHCP = (6)

Const NS_TCPIP_LOCAL = (10)
Const NS_TCPIP_HOSTS = (11)
Const NS_DNS = (12)
Const NS_NETBT = (13)
Const NS_WINS = (14)
Const NS_NLA = (15)

Const NS_NBP = (20)

Const NS_MS = (30)
Const NS_STDA = (31)
Const NS_NTDS = (32)

Const NS_X500 = (40)
Const NS_NIS = (41)
Const NS_NISPLUS = (42)

Const NS_WRQ = (50)

Const NS_NETDES = (60)

' Resolution flags for WSAGetAddressByName().
Const RES_UNUSED_1 = (&h00000001)
Const RES_FLUSH_CACHE = (&h00000002)
Const RES_SERVICE = (&h00000004)

' Well known value names for Service Types

'Const SERVICE_TYPE_VALUE_IPXPORTA = "IpxSocket"
'Const SERVICE_TYPE_VALUE_IPXPORTW = L"IpxSocket"
'Const SERVICE_TYPE_VALUE_SAPIDA = "SapId"
'Const SERVICE_TYPE_VALUE_SAPIDW = L"SapId"

'Const SERVICE_TYPE_VALUE_TCPPORTA = "TcpPort"
'Const SERVICE_TYPE_VALUE_TCPPORTW = L"TcpPort"

'Const SERVICE_TYPE_VALUE_UDPPORTA = "UdpPort"
'Const SERVICE_TYPE_VALUE_UDPPORTW = L"UdpPort"

'Const SERVICE_TYPE_VALUE_OBJECTIDA = "ObjectId"
'Const SERVICE_TYPE_VALUE_OBJECTIDW = L"ObjectId"
/*
#ifdef UNICODE
Const SERVICE_TYPE_VALUE_SAPID = SERVICE_TYPE_VALUE_SAPIDW
Const SERVICE_TYPE_VALUE_TCPPORT = SERVICE_TYPE_VALUE_TCPPORTW
Const SERVICE_TYPE_VALUE_UDPPORT = SERVICE_TYPE_VALUE_UDPPORTW
Const SERVICE_TYPE_VALUE_OBJECTID = SERVICE_TYPE_VALUE_OBJECTIDW
#else
Const SERVICE_TYPE_VALUE_SAPID = SERVICE_TYPE_VALUE_SAPIDA
Const SERVICE_TYPE_VALUE_TCPPORT = SERVICE_TYPE_VALUE_TCPPORTA
Const SERVICE_TYPE_VALUE_UDPPORT = SERVICE_TYPE_VALUE_UDPPORTA
Const SERVICE_TYPE_VALUE_OBJECTID = SERVICE_TYPE_VALUE_OBJECTIDA
#endif
*/
Const SERVICE_TYPE_VALUE_IPXPORT = "IpxSocket"
Const SERVICE_TYPE_VALUE_SAPID = "SapId"
Const SERVICE_TYPE_VALUE_TCPPORT = "TcpPort"
Const SERVICE_TYPE_VALUE_UDPPORT = "UdpPort"
Const SERVICE_TYPE_VALUE_OBJECTID = "ObjectId"

' SockAddr Information
Type SOCKET_ADDRESS
	lpSockaddr As LPSOCKADDR
	iSockaddrLength As Long
End Type
TypeDef PSOCKET_ADDRESS = *SOCKET_ADDRESS
TypeDef LPSOCKET_ADDRESS = *SOCKET_ADDRESS

' CSAddr Information
Type CSADDR_INFO
	LocalAddr As SOCKET_ADDRESS
	RemoteAddr As SOCKET_ADDRESS
	iSocketType As Long
	iProtocol As Long
End Type
TypeDef PCSADDR_INFO = *CSADDR_INFO
TypeDef LPCSADDR_INFO = *CSADDR_INFO

' Address list returned via SIO_ADDRESS_LIST_QUERY
Type SOCKET_ADDRESS_LIST
	iAddressCount As Long
	Address[ELM(1)] As SOCKET_ADDRESS
End Type
TypeDef LPSOCKET_ADDRESS_LIST = *SOCKET_ADDRESS_LIST

' Address Family/Protocol Tuples
Type AFPROTOCOLS
	iAddressFamily As Long
	iProtocol As Long
End Type
TypeDef PAFPROTOCOLS = *AFPROTOCOLS
TypeDef LPAFPROTOCOLS = *AFPROTOCOLS

' Client Query API Typedefs

' The comparators
Const Enum WSAECOMPARATOR
	COMP_EQUAL = 0
	COMP_NOTLESS
End Enum
TypeDef PWSAECOMPARATOR = *WSAECOMPARATOR
TypeDef LPWSAECOMPARATOR = *WSAECOMPARATOR

Type WSAVERSION
	dwVersion As DWord
	ecHow As WSAECOMPARATOR
End Type
TypeDef PWSAVERSION = *WSAVERSION
TypeDef LPWSAVERSION = *WSAVERSION

Type WSAQUERYSETA
	dwSize As DWord
	lpszServiceInstanceName As LPSTR
	lpServiceClassId As *GUID
	lpVersion As LPWSAVERSION
	lpszComment As LPSTR
	dwNameSpace As DWord
	lpNSProviderId As *GUID
	lpszContext As LPSTR
	dwNumberOfProtocols As DWord
	lpafpProtocols As LPAFPROTOCOLS
	lpszQueryString As LPSTR
	dwNumberOfCsAddrs As DWord
	lpcsaBuffer As LPCSADDR_INFO
	dwOutputFlags As DWord
	lpBlob As LPBLOB
End Type
TypeDef PWSAQUERYSETA = *WSAQUERYSETA
TypeDef LPWSAQUERYSETA = *WSAQUERYSETA

Type WSAQUERYSETW
	dwSize As DWord
	lpszServiceInstanceName As LPWSTR
	lpServiceClassId As *GUID
	lpVersion As LPWSAVERSION
	lpszComment As LPWSTR
	dwNameSpace As DWord
	lpNSProviderId As *GUID
	lpszContext As LPWSTR
	dwNumberOfProtocols As DWord
	lpafpProtocols As LPAFPROTOCOLS
	lpszQueryString As LPWSTR
	dwNumberOfCsAddrs As DWord
	lpcsaBuffer As LPCSADDR_INFO
	dwOutputFlags As DWord
	lpBlob As LPBLOB
End Type
TypeDef PWSAQUERYSETW = *WSAQUERYSETW
TypeDef LPWSAQUERYSETW = *WSAQUERYSETW

#ifdef UNICODE
TypeDef WSAQUERYSET = WSAQUERYSETW
TypeDef PWSAQUERYSET = PWSAQUERYSETW
TypeDef LPWSAQUERYSET = LPWSAQUERYSETW
#else
TypeDef WSAQUERYSET = WSAQUERYSETA
TypeDef PWSAQUERYSET = PWSAQUERYSETA
TypeDef LPWSAQUERYSET = LPWSAQUERYSETA
#endif

Const LUP_DEEP = &h0001
Const LUP_CONTAINERS = &h0002
Const LUP_NOCONTAINERS = &h0004
Const LUP_NEAREST = &h0008
Const LUP_RETURN_NAME = &h0010
Const LUP_RETURN_TYPE = &h0020
Const LUP_RETURN_VERSION = &h0040
Const LUP_RETURN_COMMENT = &h0080
Const LUP_RETURN_ADDR = &h0100
Const LUP_RETURN_BLOB = &h0200
Const LUP_RETURN_ALIASES = &h0400
Const LUP_RETURN_QUERY_STRING = &h0800
Const LUP_RETURN_ALL = &h0FF0
Const LUP_RES_SERVICE = &h8000

Const LUP_FLUSHCACHE = &h1000
Const LUP_FLUSHPREVIOUS = &h2000

' Return flags
Const RESULT_IS_ALIAS = &h0001
Const RESULT_IS_ADDED = &h0010
Const RESULT_IS_CHANGED = &h0020
Const RESULT_IS_DELETED = &h0040

' Service Address Registration and Deregistration Data Types.

Const Enum WSAESETSERVICEOP
	RNRSERVICE_REGISTER = 0
	RNRSERVICE_DEREGISTER
	RNRSERVICE_DELETE
End Enum
TypeDef PWSAESETSERVICEOP = *WSAESETSERVICEOP
TypeDef LPWSAESETSERVICEOP = *WSAESETSERVICEOP

' Service Installation/Removal Data Types.

Type WSANSCLASSINFOA
	lpszName As LPSTR
	dwNameSpace As DWord
	dwValueType As DWord
	dwValueSize As DWord
	lpValue As VoidPtr
End Type
TypeDef PWSANSCLASSINFOA = *WSANSCLASSINFOA
TypeDef LPWSANSCLASSINFOA = *WSANSCLASSINFOA

Type WSANSCLASSINFOW
	lpszName As LPWSTR
	dwNameSpace As DWord
	dwValueType As DWord
	dwValueSize As DWord
	lpValue As VoidPtr
End Type
TypeDef PWSANSCLASSINFOW = *WSANSCLASSINFOW
TypeDef LPWSANSCLASSINFOW = *WSANSCLASSINFOW

#ifdef UNICODE
TypeDef WSANSCLASSINFO = WSANSCLASSINFOW
TypeDef PWSANSCLASSINFO = PWSANSCLASSINFOW
TypeDef LPWSANSCLASSINFO = LPWSANSCLASSINFOW
#else
TypeDef WSANSCLASSINFO = WSANSCLASSINFOA
TypeDef PWSANSCLASSINFO = PWSANSCLASSINFOA
TypeDef LPWSANSCLASSINFO = LPWSANSCLASSINFOA
#endif

Type WSASERVICECLASSINFOA
	lpServiceClassId As *GUID
	lpszServiceClassName As LPSTR
	dwCount As DWord
	lpClassInfos As LPWSANSCLASSINFOA
End Type
TypeDef PWSASERVICECLASSINFOA = *WSASERVICECLASSINFOA
TypeDef LPWSASERVICECLASSINFOA = *WSASERVICECLASSINFOA

Type WSASERVICECLASSINFOW
	lpServiceClassId As *GUID
	lpszServiceClassName As LPWSTR
	dwCount As DWord
	lpClassInfos As LPWSANSCLASSINFOA
End Type
TypeDef PWSASERVICECLASSINFOW = *WSASERVICECLASSINFOW
TypeDef LPWSASERVICECLASSINFOW = *WSASERVICECLASSINFOW

#ifdef UNICODE
TypeDef WSASERVICECLASSINFO = WSASERVICECLASSINFOW
TypeDef PWSASERVICECLASSINFO = PWSASERVICECLASSINFOW
TypeDef LPWSASERVICECLASSINFO = LPWSASERVICECLASSINFOW
#else
TypeDef WSASERVICECLASSINFO = WSASERVICECLASSINFOA
TypeDef PWSASERVICECLASSINFO = PWSASERVICECLASSINFOA
TypeDef LPWSASERVICECLASSINFO = LPWSASERVICECLASSINFOA
#endif

Type WSANAMESPACE_INFOA
	NSProviderId As GUID
	dwNameSpace As DWord
	fActive As BOOL
	dwVersion As DWord
	lpszIdentifier As LPSTR
End Type
TypeDef PWSANAMESPACE_INFOA = *WSANAMESPACE_INFOA
TypeDef LPWSANAMESPACE_INFOA = *WSANAMESPACE_INFOA

Type WSANAMESPACE_INFOW
	NSProviderId As GUID
	dwNameSpace As DWord
	fActive As BOOL
	dwVersion As DWord
	lpszIdentifier As LPWSTR
End Type
TypeDef PWSANAMESPACE_INFOW = *WSANAMESPACE_INFOW
TypeDef LPWSANAMESPACE_INFOW = *WSANAMESPACE_INFOW

#ifdef UNICODE
TypeDef WSANAMESPACE_INFO = WSANAMESPACE_INFOW
TypeDef PWSANAMESPACE_INFO = PWSANAMESPACE_INFOW
TypeDef LPWSANAMESPACE_INFO = LPWSANAMESPACE_INFOW
#else
TypeDef WSANAMESPACE_INFO = WSANAMESPACE_INFOA
TypeDef PWSANAMESPACE_INFO = PWSANAMESPACE_INFOA
TypeDef LPWSANAMESPACE_INFO = LPWSANAMESPACE_INFOA
#endif

' Socket function prototypes

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function accept Lib "ws2_32" (s As SOCKET, ByRef addr As sockaddr, ByRef addrlen As Long) As SOCKET
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_ACCEPT = *Function(s As SOCKET, ByRef addr As sockaddr, ByRef addrlen As Long) As SOCKET
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function bind Lib "ws2_32" (s As SOCKET, ByRef name As sockaddr, addrlen As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_BIND = *Function(s As SOCKET, ByRef name As sockaddr, addrlen As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function closesocket Lib "ws2_32" (s As SOCKET) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_CLOSESOCKET = *Function(s As SOCKET) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function connect Lib "ws2_32" (s As SOCKET, ByRef name As sockaddr, namelen As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_CONNECT = *Function(s As SOCKET, ByRef name As sockaddr, namelen As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function ioctlsocket Lib "ws2_32" (s As SOCKET, cmd As Long, ByRef argp As DWord) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_IOCTLSOCKET = *Function(s As SOCKET, cmd As Long, ByRef argp As DWord) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function getpeername Lib "ws2_32" (s As SOCKET, ByRef name As sockaddr, ByRef namelen As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_GETPEERNAME = *Function(s As SOCKET, ByRef name As sockaddr, ByRef namelen As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function getsockname Lib "ws2_32" (s As SOCKET, ByRef name As sockaddr, ByRef namelen As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_GETSOCKNAME = *Function(s As SOCKET, ByRef name As sockaddr, ByRef namelen As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function getsockopt Lib "ws2_32" (s As SOCKET, level As Long, optname As Long, optval As *Byte, ByRef optlen As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_GETSOCKOPT = *Function(s As SOCKET, level As Long, optname As Long, optval As *Byte, ByRef optlen As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function htonl Lib "ws2_32" (hostlong As DWord) As DWord
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_HTONL = *Function(hostlong As DWord) As DWord
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function htons Lib "ws2_32" (hostshort As Word) As Word
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_HTONS = *Function(hostshort As Word) As Word
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function inet_addr Lib "ws2_32" (cp As *Byte) As DWord
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_INET_ADDR = *Function(cp As *Byte) As DWord
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function inet_ntoa Lib "ws2_32" (in As DWord /*in_addr*/ ) As *Byte
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_INET_NTOA = *Function(in As in_addr) As *Byte
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function listen Lib "ws2_32" (s As SOCKET, backlog As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_LISTEN = *Function(s As SOCKET, backlog As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function ntohl Lib "ws2_32" (netlong As DWord) As DWord
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_NTOHL = *Function(netlong As DWord) As DWord
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function ntohs Lib "ws2_32" (netshort As Word) As Word
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_NTOHS = *Function(netshort As Word) As Word
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function recv Lib "ws2_32" (s As SOCKET, buf As *Byte, len As Long, flags As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_RECV = *Function(s As SOCKET, buf As *Byte, len As Long, flags As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function recvfrom Lib "ws2_32" (s As SOCKET, buf As *Byte, len As Long, flags As Long, ByRef from As sockaddr, ByRef fromlen As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_RECVFROM = *Function(s As SOCKET, buf As *Byte, len As Long, flags As Long, ByRef from As sockaddr, ByRef fromlen As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function select Lib "ws2_32" (nfds As Long, ByRef readfds As fd_set, ByRef writefds As fd_set, ByRef exceptfds As fd_set, ByRef timeout As timeval) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_SELECT = *Function(nfds As Long, ByRef readfds As fd_set, ByRef writefds As fd_set, ByRef exceptfds As fd_set, ByRef timeout As timeval) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function send Lib "ws2_32" (s As SOCKET, buf As *Byte, len As Long, flags As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_SEND = *Function(s As SOCKET, buf As *Byte, len As Long, flags As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function sendto Lib "ws2_32" (s As SOCKET, buf As *Byte, len As Long, flags As Long, ByRef to_ As sockaddr, tolen As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_SENDTO = *Function(s As SOCKET, buf As *Byte, len As Long, flags As Long, ByRef to_ As sockaddr, tolen As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function setsockopt Lib "ws2_32" (s As SOCKET, level As Long, optname As Long, optval As *Byte, optlen As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_SETSOCKOPT = *Function(s As SOCKET, level As Long, optname As Long, optval As *Byte, optlen As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function shutdown Lib "ws2_32" (s As SOCKET, how As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_SHUTDOWN = *Function(s As SOCKET, how As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function socket Lib "ws2_32" (af As Long, type_ As Long, protocol As Long) As SOCKET
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_SOCKET = *Function(af As Long, type_ As Long, protocol As Long) As SOCKET
#endif

' Database function prototypes

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function gethostbyaddr Lib "ws2_32" (addr As PCSTR, len As Long, type_ As Long) As *hostent
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_GETHOSTBYADDR = *Function(addr As PCSTR, len As Long, type_ As Long) As *hostent
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function gethostbyname Lib "ws2_32" (name As PCSTR) As *hostent
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_GETHOSTBYNAME = *Function(name As PCSTR) As *hostent
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function gethostname Lib "ws2_32" (name As PCSTR, namelen As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_GETHOSTNAME = *Function(name As PCSTR, namelen As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function getservbyport Lib "ws2_32" (port As Long, proto As PCSTR) As *servent
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_GETSERVBYPORT = *Function(port As Long, proto As PCSTR) As *servent
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function getservbyname Lib "ws2_32" (name As PCSTR, proto As PCSTR) As *servent
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_GETSERVBYNAME = *Function(name As PCSTR, proto As PCSTR) As *servent
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function getprotobynumber Lib "ws2_32" (number As Long) As *protoent
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_GETPROTOBYNUMBER = *Function(number As Long) As *protoent
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function getprotobyname Lib "ws2_32" (name As PCSTR) As *protoent
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_GETPROTOBYNAME = (name As PCSTR) As *protoent
#endif

' Microsoft Windows Extension function prototypes

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAStartup Lib "ws2_32" (wVersionRequested As Word, ByRef WSAData As WSADATA) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSASTARTUP = *Function(wVersionRequested As Word, ByRef WSAData As WSADATA) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSACleanup Lib "ws2_32" () As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSACLEANUP = *Function() As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Sub WSASetLastError Lib "ws2_32" (iError As Long)
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSASETLASTERROR = *Sub(iError As Long)
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAGetLastError Lib "ws2_32" () As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAGETLASTERROR = *Function() As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAIsBlocking Lib "ws2_32" () As BOOL
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAISBLOCKING = *Function() As BOOL
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAUnhookBlockingHook Lib "ws2_32" () As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAUNHOOKBLOCKINGHOOK = *Function() As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSASetBlockingHook Lib "ws2_32" (lpBlockFunc As FARPROC) As FARPROC

#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSASETBLOCKINGHOOK = *Function(lpBlockFunc As FARPROC) As FARPROC
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSACancelBlockingCall Lib "ws2_32" () As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSACANCELBLOCKINGCALL = *Function() As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAAsyncGetServByName Lib "ws2_32" (hwnd As HWND, msg As DWord, name As PCSTR, proto As PCSTR, buf As *Byte, buflen As Long) As HANDLE
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAASYNCGETSERVBYNAME = *Function(hwnd As HWND, msg As DWord, name As PCSTR, proto As PCSTR, buf As *Byte, buflen As Long) As HANDLE
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAAsyncGetServByPort Lib "ws2_32" (hwnd As HWND, msg As DWord, port As Long, proto As PCSTR, buf As *Byte, buflen As Long) As HANDLE
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAASYNCGETSERVBYPORT = *Function(hwnd As HWND, msg As DWord, port As Long, proto As PCSTR, buf As *Byte, buflen As Long) As HANDLE
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAAsyncGetProtoByName Lib "ws2_32" (hwnd As HWND, msg As DWord, name As PCSTR, buf As *Byte, buflen As Long) As HANDLE
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAASYNCGETPROTOBYNAME = *Function(hwnd As HWND, msg As DWord, name As PCSTR, buf As *Byte, buflen As Long) As HANDLE
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAAsyncGetProtoByNumber Lib "ws2_32" (hwnd As HWND, msg As DWord, number As Long, buf As *Byte, buflen As Long) As HANDLE
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAASYNCGETPROTOBYNUMBER = *Function(hwnd As HWND, msg As DWord, number As Long, buf As *Byte, buflen As Long) As HANDLE
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAAsyncGetHostByName Lib "ws2_32" (hwnd As HWND, msg As DWord, name As PCSTR, buf As *Byte, buflen As Long) As HANDLE
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAASYNCGETHOSTBYNAME = *Function(hwnd As HWND, msg As DWord, name As PCSTR, buf As *Byte, buflen As Long) As HANDLE
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAAsyncGetHostByAddr Lib "ws2_32" (hwnd As HWND, msg As DWord, addr As PCSTR, len As Long, type_ As Long, buf As *Byte, buflen As Long) As HANDLE
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAASYNCGETHOSTBYADDR = *Function(hwnd As HWND, msg As DWord, addr As PCSTR, len As Long, type_ As Long, buf As *Byte, buflen As Long) As HANDLE
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSACancelAsyncRequest Lib "ws2_32" (hAsyncTaskHandle As HANDLE) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSACANCELASYNCREQUEST = *Function(hAsyncTaskHandle As HANDLE) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAAsyncSelect Lib "ws2_32" (s As SOCKET, hwnd As HWND, msg As DWord, Event As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAASYNCSELECT = *Function(s As SOCKET, hwnd As HWND, msg As DWord, Event As Long) As Long
#endif

/* WinSock 2 API new function prototypes */

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAAccept Lib "ws2_32" (s As SOCKET, ByRef addr As sockaddr, ByRef addrlen As Long, lpfnCondition As LPCONDITIONPROC, CallbackData As ULONG_PTR) As SOCKET
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAACCEPT = *Function(s As SOCKET, ByRef addr As sockaddr, ByRef addrlen As Long, lpfnCondition As LPCONDITIONPROC, CallbackData As ULONG_PTR) As SOCKET
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSACloseEvent Lib "ws2_32" (hEvent As WSAEVENT) As BOOL
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSACLOSEEVENT = *Function(hEvent As WSAEVENT) As BOOL
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAConnect Lib "ws2_32" (s As SOCKET, ByRef name As sockaddr, namelen As Long, ByRef CallerData As WSABUF, ByRef CalleeData As WSABUF, ByRef SQOS As QOS, ByRef GQOS As QOS) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSACONNECT = *Functions As SOCKET, ByRef name As sockaddr, namelen As Long, ByRef CallerData As WSABUF, ByRef CalleeData As WSABUF, ByRef SQOS As QOS, ByRef GQOS As QOS) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSACreateEvent Lib "ws2_32" () As WSAEVENT
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSACREATEEVENT = *Function() As WSAEVENT
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSADuplicateSocketA Lib "ws2_32" (s As SOCKET, ProcessId As DWord, ByRef ProtocolInfo As WSAPROTOCOL_INFOA) As Long
Declare Function WSADuplicateSocketW Lib "ws2_32" (s As SOCKET, ProcessId As DWord, ByRef ProtocolInfo As WSAPROTOCOL_INFOW) As Long
#ifdef UNICODE
Declare Function WSADuplicateSocket Lib "ws2_32" Alias "WSADuplicateSocketW" (s As SOCKET, ProcessId As DWord, ByRef ProtocolInfo As WSAPROTOCOL_INFO) As Long
#else
Declare Function WSADuplicateSocket Lib "ws2_32" Alias "WSADuplicateSocketA" (s As SOCKET, ProcessId As DWord, ByRef ProtocolInfo As WSAPROTOCOL_INFO) As Long
#endif
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSADUPLICATESOCKETA = *Function(s As SOCKET, ProcessId As DWord, ByRef ProtocolInfo As WSAPROTOCOL_INFOA) As Long
TypeDef LPFN_WSADUPLICATESOCKETW = *Function(s As SOCKET, ProcessId As DWord, ByRef ProtocolInfo As WSAPROTOCOL_INFOW) As Long
#ifdef UNICODE
TypeDef LPFN_WSADUPLICATESOCKET = LPFN_WSADUPLICATESOCKETW
#else
TypeDef LPFN_WSADUPLICATESOCKET = LPFN_WSADUPLICATESOCKETA
#endif
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAEnumNetworkEvents Lib "ws2_32" (s As SOCKET, hEventObject As WSAEVENT, ByRef NetworkEvents As WSANETWORKEVENTS) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAENUMNETWORKEVENTS = *Function(s As SOCKET, hEventObject As WSAEVENT, ByRef NetworkEvents As WSANETWORKEVENTS) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAEnumProtocolsA Lib "ws2_32" (Protocols As *Long, ByRef ProtocolBuffer As WSAPROTOCOL_INFOA, ByRef BufferLength As DWord) As Long
Declare Function WSAEnumProtocolsW Lib "ws2_32" (Protocols As *Long, ByRef ProtocolBuffer As WSAPROTOCOL_INFOW, ByRef BufferLength As DWord) As Long
#ifdef UNICODE
Declare Function WSAEnumProtocols Lib "ws2_32" Alias "WSAEnumProtocolsW" (Protocols As *Long, ByRef ProtocolBuffer As WSAPROTOCOL_INFO, ByRef BufferLength As DWord) As Long
#else
Declare Function WSAEnumProtocols Lib "ws2_32" Alias "WSAEnumProtocolsA" (Protocols As *Long, ByRef ProtocolBuffer As WSAPROTOCOL_INFO, ByRef BufferLength As DWord) As Long
#endif
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAENUMPROTOCOLSA = *Function(Protocols As *Long, ByRef ProtocolBuffer As WSAPROTOCOL_INFOA, ByRef BufferLength As DWord) As Long
TypeDef LPFN_WSAENUMPROTOCOLSW = *Function(Protocols As *Long, ByRef ProtocolBuffer As WSAPROTOCOL_INFOW, ByRef BufferLength As DWord) As Long
#ifdef UNICODE
TypeDef LPFN_WSAENUMPROTOCOLS = LPFN_WSAENUMPROTOCOLSW
#else
TypeDef LPFN_WSAENUMPROTOCOLS = LPFN_WSAENUMPROTOCOLSA
#endif
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAEventSelect Lib "ws2_32" (s As SOCKET, hEventObject As WSAEVENT, NetworkEvents As Long) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAEVENTSELECT = *Function(s As SOCKET, hEventObject As WSAEVENT, NetworkEvents As Long) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAGetOverlappedResult Lib "ws2_32" (s As SOCKET, ByRef Overlapped As WSAOVERLAPPED, ByRef cbTransfer As DWord, Wait As BOOL, ByRef Flags As DWord) As BOOL
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAGETOVERLAPPEDRESULT = *Function(s As SOCKET, ByRef Overlapped As WSAOVERLAPPED, ByRef cbTransfer As DWord, Wait As BOOL, ByRef Flags As DWord) As BOOL
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAGetQOSByName Lib "ws2_32" (s As SOCKET, ByRef QOSName As WSABUF, ByRef qos As QOS) As BOOL
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAGETQOSBYNAME = *Function(s As SOCKET, ByRef QOSName As WSABUF, ByRef qos As QOS) As BOOL
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAHtonl Lib "ws2_32" (s As SOCKET, hostlong As DWord, ByRef netlong As DWord) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAHTONL = *Function(s As SOCKET, hostlong As DWord, ByRef netlong As DWord) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAHtons Lib "ws2_32" (s As SOCKET, hostshort As Word, ByRef netshort As Word) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAHTONS = *Function(s As SOCKET, hostshort As Word, ByRef netshort As Word) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAIoctl Lib "ws2_32" (s As SOCKET, IoControlCode As DWord, pvInBuffer As VoidPtr, cbInBuffer As DWord, pvOutBuffer As VoidPtr, cbOutBuffer As DWord,
	ByRef cbBytesReturned As DWord, ByRef Overlapped As WSAOVERLAPPED, pCompletionRoutine As LPWSAOVERLAPPED_COMPLETION_ROUTINE) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAIOCTL = *Function(s As SOCKET, IoControlCode As DWord, pvInBuffer As VoidPtr, cbInBuffer As DWord, pvOutBuffer As VoidPtr, cbOutBuffer As DWord,
	ByRef cbBytesReturned As DWord, ByRef Overlapped As WSAOVERLAPPED, pCompletionRoutine As LPWSAOVERLAPPED_COMPLETION_ROUTINE) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAJoinLeaf Lib "ws2_32" (s As SOCKET, ByRef name As sockaddr, namelen As Long, ByRef CallerData As WSABUF, ByRef CalleeData As WSABUF,
	ByRef SQOS As QOS, ByRef GQOS AS QOS, Flags As DWord) As SOCKET
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAJOINLEAF = *Function(s As SOCKET, ByRef name As sockaddr, namelen As Long, ByRef CallerData As WSABUF, ByRef CalleeData As WSABUF,
	ByRef SQOS As QOS, ByRef GQOS AS QOS, Flags As DWord) As SOCKET
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSANtohl Lib "ws2_32" (s As SOCKET, netlong As DWord, ByRef hostlong As DWord) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSANTOHL = *Function(s As SOCKET, netlong As DWord, ByRef hostlong As DWord) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSANtohs Lib "ws2_32" (s As SOCKET, netshort As Word, ByRef hostshort As Word) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSANTOHS = *Function(s As SOCKET, netshort As Word, ByRef hostshort As Word) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSARecv Lib "ws2_32" (s As SOCKET, ByRef Buffers As WSABUF, BufferCount As DWord, ByRef NumberOfBytesRecvd As DWord, ByRef Flags As DWord,
	ByRef Overlapped As WSAOVERLAPPED, lpCompletionRoutine As LPWSAOVERLAPPED_COMPLETION_ROUTINE) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSARECV = *Function(s As SOCKET, ByRef Buffers As WSABUF, BufferCount As DWord, ByRef NumberOfBytesRecvd As DWord, ByRef Flags As DWord,
	ByRef Overlapped As WSAOVERLAPPED, lpCompletionRoutine As LPWSAOVERLAPPED_COMPLETION_ROUTINE) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSARecvDisconnect Lib "ws2_32" (s As SOCKET, ByRef InboundDisconnectData As WSABUF) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSARECVDISCONNECT = *Function(s As SOCKET, ByRef InboundDisconnectData As WSABUF) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSARecvFrom Lib "ws2_32" (s As SOCKET, ByRef Buffers As WSABUF, BufferCount As DWord, ByRef NumberOfBytesRecvd As DWord, ByRef Flags As DWord,
	ByRef From As sockaddr, ByRef Fromlen As Long, ByRef Overlapped As WSAOVERLAPPED, lpCompletionRoutine As LPWSAOVERLAPPED_COMPLETION_ROUTINE) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSARECVFROM = *Function(s As SOCKET, ByRef Buffers As WSABUF, BufferCount As DWord, ByRef NumberOfBytesRecvd As DWord, ByRef Flags As DWord,
	ByRef From As sockaddr, ByRef Fromlen As Long, ByRef Overlapped As WSAOVERLAPPED, lpCompletionRoutine As LPWSAOVERLAPPED_COMPLETION_ROUTINE) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAResetEvent Lib "ws2_32" (hEvent As WSAEVENT) As BOOL
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSARESETEVENT = *Function(hEvent As WSAEVENT) As BOOL
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSASend Lib "ws2_32" (s As SOCKET, ByRef Buffers As WSABUF, BufferCount As DWord, ByRef NumberOfBytesSent As DWord, ByRef Flags As DWord,
	ByRef Overlapped As WSAOVERLAPPED, lpCompletionRoutine As LPWSAOVERLAPPED_COMPLETION_ROUTINE) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSASEND = *Function(s As SOCKET, ByRef Buffers As WSABUF, BufferCount As DWord, ByRef NumberOfBytesSent As DWord, ByRef Flags As DWord,
	ByRef Overlapped As WSAOVERLAPPED, lpCompletionRoutine As LPWSAOVERLAPPED_COMPLETION_ROUTINE) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSASendDisconnect Lib "ws2_32" (s As SOCKET, ByRef OutboundDisconnectData As WSABUF) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSASENDDISCONNECT = *Function(s As SOCKET, ByRef OutboundDisconnectData As WSABUF) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSASendTo Lib "ws2_32" (s As SOCKET, ByRef Buffers As WSABUF, BufferCount As DWord, ByRef NumberOfBytesSent As DWord, ByRef Flags As DWord,
	ByRef To_ As sockaddr, ToLen As Long, ByRef Overlapped As WSAOVERLAPPED, lpCompletionRoutine As LPWSAOVERLAPPED_COMPLETION_ROUTINE) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSASENDTO = *Function(s As SOCKET, ByRef Buffers As WSABUF, BufferCount As DWord, ByRef NumberOfBytesSent As DWord, ByRef Flags As DWord,
	ByRef To_ As sockaddr, ToLen As Long, ByRef Overlapped As WSAOVERLAPPED, lpCompletionRoutine As LPWSAOVERLAPPED_COMPLETION_ROUTINE) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSASetEvent Lib "ws2_32" (hEvent As WSAEVENT) As BOOL
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSASETEVENT = *Function(hEvent As WSAEVENT) As BOOL
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSASocketA Lib "ws2_32" (af As Long, type_ As Long, protocol As Long, ByRef ProtocolInfo As WSAPROTOCOL_INFOA, g As GROUP, Flags As DWord) As SOCKET
Declare Function WSASocketW Lib "ws2_32" (af As Long, type_ As Long, protocol As Long, ByRef ProtocolInfo As WSAPROTOCOL_INFOW, g As GROUP, Flags As DWord) As SOCKET
#ifdef UNICODE
Declare Function WSASocket Lib "ws2_32" Alias "WSASocketW" (af As Long, type_ As Long, protocol As Long, ByRef ProtocolInfo As WSAPROTOCOL_INFO, g As GROUP, Flags As DWord) As SOCKET
#else
Declare Function WSASocket Lib "ws2_32" Alias "WSASocketA" (af As Long, type_ As Long, protocol As Long, ByRef ProtocolInfo As WSAPROTOCOL_INFO, g As GROUP, Flags As DWord) As SOCKET
#endif
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSASOCKETA = *Function(af As Long, type_ As Long, protocol As Long, ByRef ProtocolInfo As WSAPROTOCOL_INFOA, g As GROUP, Flags As DWord) As SOCKET
TypeDef LPFN_WSASOCKETW = *Function(af As Long, type_ As Long, protocol As Long, ByRef ProtocolInfo As WSAPROTOCOL_INFOW, g As GROUP, Flags As DWord) As SOCKET
#ifdef UNICODE
TypeDef LPFN_WSASOCKET = LPFN_WSASOCKETW
#else
TypeDef LPFN_WSASOCKET = LPFN_WSASOCKETA
#endif
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAWaitForMultipleEvents Lib "ws2_32" (cEvents As DWord, phEvents As *WSAEVENT, WaitAll As BOOL, Timeout As DWord, Alertable As BOOL) As DWord
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAWAITFORMULTIPLEEVENTS = *Function(cEvents As DWord, phEvents As *WSAEVENT, WaitAll As BOOL, Timeout As DWord, Alertable As BOOL) As DWord
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAAddressToStringA Lib "ws2_32" (ByRef saAddress As SOCKADDR, AddressLength As DWord, ByRef ProtocolInfo As WSAPROTOCOL_INFOA,
	AddressString As PSTR, ByRef dwAddressStringLength As DWord) As Long
Declare Function WSAAddressToStringW Lib "ws2_32" (ByRef saAddress As SOCKADDR, AddressLength As DWord, ByRef ProtocolInfo As WSAPROTOCOL_INFOA,
	AddressString As PWSTR, ByRef dwAddressStringLength As DWord) As Long
#ifdef UNICODE
Declare Function WSAAddressToString Lib "ws2_32" Alias "WSAAddressToStringW" (ByRef saAddress As SOCKADDR, AddressLength As DWord,
	ByRef ProtocolInfo As WSAPROTOCOL_INFO, AddressString As PSTR, ByRef dwAddressStringLength As DWord) As Long
#else
Declare Function WSAAddressToString Lib "ws2_32" Alias "WSAAddressToStringA" (ByRef saAddress As SOCKADDR, AddressLength As DWord,
	ByRef ProtocolInfo As WSAPROTOCOL_INFO, AddressString As PSTR, ByRef dwAddressStringLength As DWord) As Long
#endif
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAADDRESSTOSTRINGA = *Function(ByRef saAddress As SOCKADDR, AddressLength As DWord, ByRef ProtocolInfo As WSAPROTOCOL_INFOA,
	AddressString As PSTR, ByRef dwAddressStringLength As DWord) As Long
TypeDef LPFN_WSAADDRESSTOSTRINGW = *Function(ByRef saAddress As SOCKADDR, AddressLength As DWord, ByRef ProtocolInfo As WSAPROTOCOL_INFOA,
	AddressString As PWSTR, ByRef dwAddressStringLength As DWord) As Long
#ifdef UNICODE
TypeDef LPFN_WSAADDRESSTOSTRING = LPFN_WSAADDRESSTOSTRINGW
#else
TypeDef LPFN_WSAADDRESSTOSTRING = LPFN_WSAADDRESSTOSTRINGA
#endif
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAStringToAddressA Lib "ws2_32" (AddressString As PSTR, AddressFamily As Long, ByRef ProtocolInfo As WSAPROTOCOL_INFOA,
	ByRef Address As SOCKADDR, ByRef AddressLength As Long) As Long
Declare Function WSAStringToAddressW Lib "ws2_32" (AddressString As PWSTR, AddressFamily As Long, ByRef ProtocolInfo As WSAPROTOCOL_INFOW,
	ByRef Address As SOCKADDR, ByRef AddressLength As Long) As Long
#ifdef UNICODE
Declare Function WSAStringToAddress Lib "ws2_32" Alias "WSAStringToAddressW" (AddressString As PSTR, AddressFamily As Long,
	ByRef ProtocolInfo As WSAPROTOCOL_INFO, ByRef Address As SOCKADDR, ByRef AddressLength As Long) As Long
#else
Declare Function WSAStringToAddress Lib "ws2_32" Alias "WSAStringToAddressA" (AddressString As PSTR, AddressFamily As Long,
	ByRef ProtocolInfo As WSAPROTOCOL_INFO, ByRef Address As SOCKADDR, ByRef AddressLength As Long) As Long
#endif
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSASTRINGTOADDRESSA = *Function(AddressString As PSTR, AddressFamily As Long, ByRef ProtocolInfo As WSAPROTOCOL_INFOA,
	ByRef Address As SOCKADDR, ByRef AddressLength As Long) As Long
TypeDef LPFN_WSASTRINGTOADDRESSW = *Function(AddressString As PWSTR, AddressFamily As Long, ByRef ProtocolInfo As WSAPROTOCOL_INFOW,
	ByRef Address As SOCKADDR, ByRef AddressLength As Long) As Long
#ifdef UNICODE
TypeDef LPFN_WSASTRINGTOADDRESS = LPFN_WSASTRINGTOADDRESSW
#else
TypeDef LPFN_WSASTRINGTOADDRESS = LPFN_WSASTRINGTOADDRESSA
#endif
#endif

' Registration and Name Resolution API functions
#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSALookupServiceBeginA Lib "ws2_32" (ByRef qsRestrictions As WSAQUERYSETA, ControlFlags As DWord, ByRef hLookup As HANDLE) As Long
Declare Function WSALookupServiceBeginW Lib "ws2_32" (ByRef qsRestrictions As WSAQUERYSETW, ControlFlags As DWord, ByRef hLookup As HANDLE) As Long
#ifdef UNICODE
Declare Function WSALookupServiceBegin Lib "ws2_32" Alias "WSALookupServiceBeginW" (ByRef qsRestrictions As WSAQUERYSET, ControlFlags As DWord, ByRef hLookup As HANDLE) As Long
#else
Declare Function WSALookupServiceBegin Lib "ws2_32" Alias "WSALookupServiceBeginA" (ByRef qsRestrictions As WSAQUERYSET, ControlFlags As DWord, ByRef hLookup As HANDLE) As Long
#endif
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSALOOKUPSERVICEBEGINA = *Function(ByRef qsRestrictions As WSAQUERYSETA, ControlFlags As DWord, ByRef hLookup As HANDLE) As Long
TypeDef LPFN_WSALOOKUPSERVICEBEGINW = *Function(ByRef qsRestrictions As WSAQUERYSETW, ControlFlags As DWord, ByRef hLookup As HANDLE) As Long
#ifdef UNICODE
TypeDef LPFN_WSALOOKUPSERVICEBEGIN = LPFN_WSALOOKUPSERVICEBEGINW
#else
TypeDef LPFN_WSALOOKUPSERVICEBEGIN = LPFN_WSALOOKUPSERVICEBEGINA
#endif
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSALookupServiceNextA Lib "ws2_32" (hLookup As HANDLE, ControlFlags As DWord, ByRef BufferLength As DWord, ByRef qsResults As WSAQUERYSETA) As Long
Declare Function WSALookupServiceNextW Lib "ws2_32" (hLookup As HANDLE, ControlFlags As DWord, ByRef BufferLength As DWord, ByRef qsResults As WSAQUERYSETW) As Long
#ifdef UNICODE
Declare Function WSALookupServiceNext Lib "ws2_32" Alias "WSALookupServiceNextW" (hLookup As HANDLE, ControlFlags As DWord, ByRef BufferLength As DWord, ByRef qsResults As WSAQUERYSET) As Long
#else
Declare Function WSALookupServiceNext Lib "ws2_32" Alias "WSALookupServiceNextA" (hLookup As HANDLE, ControlFlags As DWord, ByRef BufferLength As DWord, ByRef qsResults As WSAQUERYSET) As Long
#endif
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSALOOKUPSERVICENEXTA = *FunctionhLookup As HANDLE, ControlFlags As DWord, ByRef BufferLength As DWord, ByRef qsResults As WSAQUERYSETA) As Long
TypeDef LPFN_WSALOOKUPSERVICENEXTW = *FunctionhLookup As HANDLE, ControlFlags As DWord, ByRef BufferLength As DWord, ByRef qsResults As WSAQUERYSETW) As Long
#ifdef UNICODE
TypeDef LPFN_WSALOOKUPSERVICENEXT = LPFN_WSALOOKUPSERVICENEXTW
#else
TypeDef LPFN_WSALOOKUPSERVICENEXT = LPFN_WSALOOKUPSERVICENEXTA
#endif
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSANSPIoctl Lib "ws2_32" (hLookup As HANDLE, ControlCode As DWord, pvInBuffer As VoidPtr, cbInBuffer As DWord,
	pvOutBuffer As VoidPtr, cbOutBuffer As DWord, ByRef cbBytesReturned As DWord, ByRef Completion As WSACOMPLETION) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSANSPIOCTL = *Function(hLookup As HANDLE, ControlCode As DWord, pvInBuffer As VoidPtr, cbInBuffer As DWord,
	pvOutBuffer As VoidPtr, cbOutBuffer As DWord, ByRef cbBytesReturned As DWord, ByRef Completion As WSACOMPLETION) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSALookupServiceEnd Lib "ws2_32" (hLookup As HANDLE) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSALOOKUPSERVICEEND = *Function(hLookup As HANDLE) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAInstallServiceClassA Lib "ws2_32" (ByRef ServiceClassInfo As WSASERVICECLASSINFOA) As Long
Declare Function WSAInstallServiceClassW Lib "ws2_32" (ByRef ServiceClassInfo As WSASERVICECLASSINFOW) As Long
#ifdef UNICODE
Declare Function WSAInstallServiceClass Lib "ws2_32" Alias "WSAInstallServiceClassW" (ByRef ServiceClassInfo As WSASERVICECLASSINFO) As Long
#else
Declare Function WSAInstallServiceClass Lib "ws2_32" Alias "WSAInstallServiceClassA" (ByRef ServiceClassInfo As WSASERVICECLASSINFO) As Long
#endif
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAINSTALLSERVICECLASSA = *Function(ByRef ServiceClassInfo As WSASERVICECLASSINFOA) As Long
TypeDef LPFN_WSAINSTALLSERVICECLASSW = *Function(ByRef ServiceClassInfo As WSASERVICECLASSINFOW) As Long
#ifdef UNICODE
TypeDef LPFN_WSAINSTALLSERVICECLASS = LPFN_WSAINSTALLSERVICECLASSW
#else
TypeDef LPFN_WSAINSTALLSERVICECLASS = LPFN_WSAINSTALLSERVICECLASSA
#endif
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSARemoveServiceClass Lib "ws2_32" (ByRef ServiceClassId As GUID) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAREMOVESERVICECLASS = *Function(ByRef ServiceClassId As GUID) As Long
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAGetServiceClassInfoA Lib "ws2_32" (ByRef ProviderId As GUID, ByRef ServiceClassId As GUID, ByRef BufSize As DWord, ByRef ServiceClassInfo As WSASERVICECLASSINFOA) As Long
Declare Function WSAGetServiceClassInfoW Lib "ws2_32" (ByRef ProviderId As GUID, ByRef ServiceClassId As GUID, ByRef BufSize As DWord, ByRef ServiceClassInfo As WSASERVICECLASSINFOW) As Long
#ifdef UNICODE
Declare Function WSAGetServiceClassInfo Lib "ws2_32" Alias "WSAGetServiceClassInfoW" (ByRef ProviderId As GUID, ByRef ServiceClassId As GUID, ByRef BufSize As DWord, ByRef ServiceClassInfo As WSASERVICECLASSINFO) As Long
#else
Declare Function WSAGetServiceClassInfo Lib "ws2_32" Alias "WSAGetServiceClassInfoA" (ByRef ProviderId As GUID, ByRef ServiceClassId As GUID, ByRef BufSize As DWord, ByRef ServiceClassInfo As WSASERVICECLASSINFO) As Long
#endif
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAGETSERVICECLASSINFOA = *Function(ByRef ProviderId As GUID, ByRef ServiceClassId As GUID, ByRef BufSize As DWord, ByRef ServiceClassInfo As WSASERVICECLASSINFOA) As Long
TypeDef LPFN_WSAGETSERVICECLASSINFOW = *Function(ByRef ProviderId As GUID, ByRef ServiceClassId As GUID, ByRef BufSize As DWord, ByRef ServiceClassInfo As WSASERVICECLASSINFOW) As Long
#ifdef UNICODE
TypeDef LPFN_WSAGETSERVICECLASSINFO = LPFN_WSAGETSERVICECLASSINFOW
#else
TypeDef LPFN_WSAGETSERVICECLASSINFO = LPFN_WSAGETSERVICECLASSINFOA
#endif
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAEnumNameSpaceProvidersA Lib "ws2_32" (ByRef BufferLength As DWord, ByRef nspBuffer As WSANAMESPACE_INFOA) As Long
Declare Function WSAEnumNameSpaceProvidersW Lib "ws2_32" (ByRef BufferLength As DWord, ByRef nspBuffer As WSANAMESPACE_INFOW) As Long
#ifdef UNICODE
Declare Function WSAEnumNameSpaceProviders Lib "ws2_32" Alias "WSAEnumNameSpaceProvidersW" (ByRef BufferLength As DWord, ByRef nspBuffer As WSANAMESPACE_INFO) As Long
#else
Declare Function WSAEnumNameSpaceProviders Lib "ws2_32" Alias "WSAEnumNameSpaceProvidersA" (ByRef BufferLength As DWord, ByRef nspBuffer As WSANAMESPACE_INFO) As Long
#endif
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAENUMNAMESPACEPROVIDERSA = *Function(ByRef BufferLength As DWord, ByRef nspBuffer As WSANAMESPACE_INFOA) As Long
TypeDef LPFN_WSAENUMNAMESPACEPROVIDERSW = *Function(ByRef BufferLength As DWord, ByRef nspBuffer As WSANAMESPACE_INFOW) As Long
#ifdef UNICODE
TypeDef LPFN_WSAENUMNAMESPACEPROVIDERS = LPFN_WSAENUMNAMESPACEPROVIDERSW
#else
TypeDef LPFN_WSAENUMNAMESPACEPROVIDERS = LPFN_WSAENUMNAMESPACEPROVIDERSA
#endif
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAGetServiceClassNameByClassIdA Lib "ws2_32" (ByRef ServiceClassId As GUID, ServiceClassName As PSTR, ByRef BufferLength As DWord) As Long
Declare Function WSAGetServiceClassNameByClassIdW Lib "ws2_32" (ByRef ServiceClassId As GUID, ServiceClassName As PWSTR, ByRef BufferLength As DWord) As Long
#ifdef UNICODE
Declare Function WSAGetServiceClassNameByClassId Lib "ws2_32" Alias "WSAGetServiceClassNameByClassIdW" (ByRef ServiceClassId As GUID, ServiceClassName As PWSTR, ByRef BufferLength As DWord) As Long
#else
Declare Function WSAGetServiceClassNameByClassId Lib "ws2_32" Alias "WSAGetServiceClassNameByClassIdA" (ByRef ServiceClassId As GUID, ServiceClassName As PSTR, ByRef BufferLength As DWord) As Long
#endif
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAGETSERVICECLASSNAMEBYCLASSIDA = *Function(ByRef ServiceClassId As GUID, ServiceClassName As PSTR, ByRef BufferLength As DWord) As Long
TypeDef LPFN_WSAGETSERVICECLASSNAMEBYCLASSIDW = *Function(ByRef ServiceClassId As GUID, ServiceClassName As PWSTR, ByRef BufferLength As DWord) As Long
#ifdef UNICODE
TypeDef LPFN_WSAGETSERVICECLASSNAMEBYCLASSID = LPFN_WSAGETSERVICECLASSNAMEBYCLASSIDW
#else
TypeDef LPFN_WSAGETSERVICECLASSNAMEBYCLASSID = LPFN_WSAGETSERVICECLASSNAMEBYCLASSIDA
#endif
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSASetServiceA Lib "ws2_32" (ByRef qsRegInfo As WSAQUERYSETA, essoperation As WSAESETSERVICEOP, ControlFlags As DWord) As Long
Declare Function WSASetServiceW Lib "ws2_32" (ByRef qsRegInfo As WSAQUERYSETW, essoperation As WSAESETSERVICEOP, ControlFlags As DWord) As Long
#ifdef UNICODE
Declare Function WSASetService Lib "ws2_32" Alias "WSASetServiceW" (ByRef qsRegInfo As WSAQUERYSET, essoperation As WSAESETSERVICEOP, ControlFlags As DWord) As Long
#else
Declare Function WSASetService Lib "ws2_32" Alias "WSASetServiceA" (ByRef qsRegInfo As WSAQUERYSET, essoperation As WSAESETSERVICEOP, ControlFlags As DWord) As Long
#endif
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSASETSERVICEA = *Function(ByRef qsRegInfo As WSAQUERYSETA, essoperation As WSAESETSERVICEOP, ControlFlags As DWord) As Long
TypeDef LPFN_WSASETSERVICEW = *Function(ByRef qsRegInfo As WSAQUERYSETW, essoperation As WSAESETSERVICEOP, ControlFlags As DWord) As Long
#ifdef UNICODE
TypeDef LPFN_WSASETSERVICE = LPFN_WSASETSERVICEW
#else
TypeDef LPFN_WSASETSERVICE = LPFN_WSASETSERVICEA
#endif
#endif

#ifndef NO_INCL_WINSOCK_API_PROTOTYPES
Declare Function WSAProviderConfigChange Lib "ws2_32" (ByRef NotificationHandle As HANDLE, ByRef Overlapped As WSAOVERLAPPED, lpCompletionRoutine As LPWSAOVERLAPPED_COMPLETION_ROUTINE) As Long
#endif

#ifdef INCL_WINSOCK_API_TYPEDEFS
TypeDef LPFN_WSAPROVIDERCONFIGCHANGE = *Function(ByRef NotificationHandle As HANDLE, ByRef Overlapped As WSAOVERLAPPED, lpCompletionRoutine As LPWSAOVERLAPPED_COMPLETION_ROUTINE) As Long
#endif

' Microsoft Windows Extended data types
TypeDef SOCKADDR_IN = sockaddr_in
TypeDef PSOCKADDR_IN = *sockaddr_in
TypeDef LPSOCKADDR_IN = *sockaddr_in

TypeDef LINGER = linger
TypeDef PLINGER = *linger
TypeDef LPLINGER = *linger

TypeDef IN_ADDR = in_addr
TypeDef PIN_ADDR = *in_addr
TypeDef LPIN_ADDR = *in_addr

TypeDef FD_SET = fd_set
TypeDef PFD_SET = *fd_set
TypeDef LPFD_SET = *fd_set

TypeDef HOSTENT = hostent
TypeDef PHOSTENT = *hostent
TypeDef LPHOSTENT = *hostent

TypeDef SERVENT = servent
TypeDef PSERVENT = *servent
TypeDef LPSERVENT = *servent

TypeDef PROTOENT = protoent
TypeDef PPROTOENT = *protoent
TypeDef LPPROTOENT = *protoent

TypeDef TIMEVAL = timeval
TypeDef PTIMEVAL = *timeval
TypeDef LPTIMEVAL = *timeval

' Windows message parameter composition and decomposition macros.
Const WSAMAKEASYNCREPLY(buflen, error) = MAKELONG(buflen, error)
Const WSAMAKESELECTREPLY(event, error) = MAKELONG(event, error)
Const WSAGETASYNCBUFLEN(lParam) = LOWORD(lParam)
Const WSAGETASYNCERROR(lParam) = HIWORD(lParam)
Const WSAGETSELECTEVENT(lParam) = LOWORD(lParam)
Const WSAGETSELECTERROR(lParam) = HIWORD(lParam)

'#ifdef IPV6STRICT
'#require <wsipv6ok.ab>
'#endif

#endif
