ifndef _WS2TCPIP_H_
define _WS2TCPIP_H_

include winapifamily.inc

if NOT defined(_WINSOCK_DEPRECATED_BY)
if ((defined(_WINSOCK_DEPRECATED_NO_WARNINGS) OR defined(BUILD_WINDOWS)) AND NOT defined(_WINSOCK_DEPRECATE_WARNINGS)) OR defined(MIDL_PASS)
_WINSOCK_DEPRECATED_BY macro replacement
	endm
else
_WINSOCK_DEPRECATED_BY macro replacement
	exitm<"Use &replacement& instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings">
	endm
endif
endif

include winsock2.inc
include ws2ipdef.inc
include limits.inc

.pragma comment(lib, ws2_32)

UDP_NOCHECKSUM		equ 1
UDP_CHECKSUM_COVERAGE	equ 20

ifdef _MSC_VER
WS2TCPIP_INLINE		equ <>
else
WS2TCPIP_INLINE		equ <extern>
endif

EAI_AGAIN		equ WSATRY_AGAIN
EAI_BADFLAGS		equ WSAEINVA
EAI_FAIL		equ WSANO_RECOVERY
EAI_FAMILY		equ WSAEAFNOSUPPORT
EAI_MEMORY		equ WSA_NOT_ENOUGH_MEMORY
EAI_NOSECURENAME	equ WSA_SECURE_HOST_NOT_FOUND
;;EAI_NODATA		equ WSANO_DATA
EAI_NONAME		equ WSAHOST_NOT_FOUND
EAI_SERVICE		equ WSATYPE_NOT_FOUND
EAI_SOCKTYPE		equ WSAESOCKTNOSUPPORT
EAI_IPSECPOLICY		equ WSA_IPSEC_NAME_POLICY_ERROR

EAI_NODATA		equ EAI_NONAME

ifdef _UNICODE
ADDRINFOT		typedef ADDRINFOW
PADDRINFOT		typedef ptr ADDRINFOW
else
ADDRINFOT		typedef ADDRINFOA
PADDRINFOT		typedef ptr ADDRINFOA
endif

ADDRINFO		typedef ADDRINFOA
LPADDRINFO		typedef ptr ADDRINFOA

if (_WIN32_WINNT GE 0x0600)
ifdef _UNICODE
ADDRINFOEX		typedef ADDRINFOEXW
PADDRINFOEX		typedef ptr ADDRINFOEXW
else
if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
ADDRINFOEX		typedef ADDRINFOEXA
PADDRINFOEX		typedef ptr ADDRINFOEXA
endif
endif
endif

getaddrinfo proto WINAPI :PCSTR, :PCSTR, :ptr, :ptr
if (NTDDI_VERSION GE NTDDI_WINXPSP2) OR (_WIN32_WINNT GE 0x0502)
GetAddrInfoW proto WINAPI :PCWSTR, :PCWSTR, :ptr, :ptr
GetAddrInfoA		equ <getaddrinfo>
ifdef _UNICODE
GetAddrInfo		equ <GetAddrInfoW>
else
GetAddrInfo		equ <GetAddrInfoA>
endif
endif

if INCL_WINSOCK_API_TYPEDEFS
CALLBACK(LPFN_GETADDRINFO, :PCSTR, :PCSTR, :ptr ADDRINFOA, :ptr PADDRINFOA)
CALLBACK(LPFN_GETADDRINFOW, :PCWSTR, :PCWSTR, :ptr ADDRINFOW, :ptr PADDRINFOW)
LPFN_GETADDRINFOA	equ <LPFN_GETADDRINFO>
ifdef _UNICODE
LPFN_GETADDRINFOT	equ <LPFN_GETADDRINFOW>
else
LPFN_GETADDRINFOT	equ <LPFN_GETADDRINFOA>
endif
endif

if (_WIN32_WINNT GE 0x0600)

CALLBACK(LPLOOKUPSERVICE_COMPLETION_ROUTINE, :DWORD, :DWORD, :LPWSAOVERLAPPED)

if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
GetAddrInfoExA proto WINAPI :PCSTR, :PCSTR, :DWORD, :LPGUID, :ptr, :ptr, :ptr, :LPOVERLAPPED, :LPLOOKUPSERVICE_COMPLETION_ROUTINE, :LPHANDLE
endif
GetAddrInfoExW proto WINAPI :PCWSTR, :PCWSTR, :DWORD, :LPGUID, :ptr, :ptr, :ptr, :LPOVERLAPPED, :LPLOOKUPSERVICE_COMPLETION_ROUTINE, :LPHANDLE
GetAddrInfoExCancel proto WINAPI :LPHANDLE
GetAddrInfoExOverlappedResult proto WINAPI :LPOVERLAPPED
ifdef _UNICODE
GetAddrInfoEx		equ <GetAddrInfoExW>
else
GetAddrInfoEx		equ <GetAddrInfoExA>
endif

if INCL_WINSOCK_API_TYPEDEFS

if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
CALLBACK(LPFN_GETADDRINFOEXA, :PCSTR, :PCSTR, :DWORD, :LPGUID, :ptr, :ptr, :ptr, :LPOVERLAPPED, :LPLOOKUPSERVICE_COMPLETION_ROUTINE, :LPHANDLE)
endif
CALLBACK(LPFN_GETADDRINFOEXW, :PCWSTR, :PCWSTR, :DWORD, :LPGUID, :ptr, :ptr, :ptr, :LPOVERLAPPED, :LPLOOKUPSERVICE_COMPLETION_ROUTINE, :LPHANDLE)
CALLBACK(LPFN_GETADDRINFOEXCANCEL, :LPHANDLE)
CALLBACK(LPFN_GETADDRINFOEXOVERLAPPEDRESULT, :LPOVERLAPPED)
ifdef _UNICODE
LPFN_GETADDRINFOEX	equ <LPFN_GETADDRINFOEXW>
else
LPFN_GETADDRINFOEX	equ <LPFN_GETADDRINFOEXA>
endif
endif

endif

if (_WIN32_WINNT GE 0x0600)

if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
SetAddrInfoExA proto WINAPI :PCSTR, :PCSTR, :ptr, :DWORD, :LPBLOB, :DWORD, :DWORD, :LPGUID, :ptr, :LPOVERLAPPED, :LPLOOKUPSERVICE_COMPLETION_ROUTINE, :LPHANDLE
endif
SetAddrInfoExW proto WINAPI :PCWSTR, :PCWSTR, :ptr, :DWORD, :LPBLOB, :DWORD, :DWORD, :LPGUID, :ptr, :LPOVERLAPPED, :LPLOOKUPSERVICE_COMPLETION_ROUTINE, :LPHANDLE
ifdef _UNICODE
SetAddrInfoEx		equ <SetAddrInfoExW>
else
SetAddrInfoEx		equ <SetAddrInfoExA>
endif

if INCL_WINSOCK_API_TYPEDEFS

if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
CALLBACK(LPFN_SETADDRINFOEXA, :LPHANDLE :PCSTR, :PCSTR, :ptr, :DWORD, :LPBLOB, :DWORD, :DWORD, :LPGUID, :ptr, :LPOVERLAPPED, :LPLOOKUPSERVICE_COMPLETION_ROUTINE, :LPHANDLE)
endif
CALLBACK(LPFN_SETADDRINFOEXW, :LPHANDLE, :PCWSTR, :PCWSTR, :ptr, :DWORD, :LPBLOB, :DWORD, :DWORD, :LPGUID, :ptr, :LPOVERLAPPED, :LPLOOKUPSERVICE_COMPLETION_ROUTINE, :LPHANDLE)
ifdef _UNICODE
LPFN_SETADDRINFOEX	equ <LPFN_SETADDRINFOEXW>
else
LPFN_SETADDRINFOEX	equ <LPFN_SETADDRINFOEXA>
endif
endif

endif

freeaddrinfo proto WINAPI :PADDRINFOA

if (NTDDI_VERSION GE NTDDI_WINXPSP2) OR (_WIN32_WINNT GE 0x0502)

FreeAddrInfoW proto WINAPI :PADDRINFOW
FreeAddrInfoA		equ <freeaddrinfo>
ifdef _UNICODE
FreeAddrInfo		equ <FreeAddrInfoW>
else
FreeAddrInfo		equ <FreeAddrInfoA>
endif
endif

if INCL_WINSOCK_API_TYPEDEFS
CALLBACK(LPFN_FREEADDRINFO, pAddrInfo:PADDRINFOA)
CALLBACK(LPFN_FREEADDRINFOW, pAddrInfo:PADDRINFOW)
LPFN_FREEADDRINFOA	equ <LPFN_FREEADDRINFO>
ifdef _UNICODE
LPFN_FREEADDRINFOT	equ <LPFN_FREEADDRINFOW>
else
LPFN_FREEADDRINFOT	equ <LPFN_FREEADDRINFOA>
endif
endif

if (_WIN32_WINNT GE 0x0600)

if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)

;_WINSOCK_DEPRECATED_BY("FreeAddrInfoExW()")

ifndef _UNICODE
FreeAddrInfoEx proto WINAPI :PADDRINFOEXA
endif
endif
FreeAddrInfoExW proto WINAPI :PADDRINFOEXW
FreeAddrInfoExA		equ <FreeAddrInfoEx>
ifdef _UNICODE
FreeAddrInfoEx		equ <FreeAddrInfoExW>
endif

ifdef INCL_WINSOCK_API_TYPEDEFS

if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
CALLBACK(LPFN_FREEADDRINFOEXA, pAddrInfoEx:PADDRINFOEXA)
endif
CALLBACK(LPFN_FREEADDRINFOEXW, pAddrInfoEx:PADDRINFOEXW)
ifdef _UNICODE
LPFN_FREEADDRINFOEX	equ <LPFN_FREEADDRINFOEXW>
else
LPFN_FREEADDRINFOEX	equ <LPFN_FREEADDRINFOEXA>
endif

endif
endif

socklen_t		typedef sdword

getnameinfo proto WINAPI :ptr, :socklen_t, :PCHAR, :DWORD, :PCHAR, :DWORD, :SINT

if (NTDDI_VERSION GE NTDDI_WINXPSP2) OR (_WIN32_WINNT GE 0x0502)

GetNameInfoW proto WINAPI :ptr, :socklen_t, :PWCHAR, :DWORD, :PWCHAR, :DWORD, :SINT
GetNameInfoA		equ <getnameinfo>
ifdef _UNICODE
GetNameInfo		equ <GetNameInfoW>
else
GetNameInfo		equ <GetNameInfoA>
endif
endif

if INCL_WINSOCK_API_TYPEDEFS
CALLBACK(LPFN_GETNAMEINFO, :ptr, :socklen_t, :PCHAR, :DWORD, :PCHAR, :DWORD, :SINT)
CALLBACK(LPFN_GETNAMEINFOW, :ptr, :socklen_t, :PWCHAR, :DWORD, :PWCHAR, :DWORD, :SINT)
LPFN_GETNAMEINFOA	equ <LPFN_GETNAMEINFO>
ifdef _UNICODE
LPFN_GETNAMEINFOT	equ <LPFN_GETNAMEINFOW>
else
LPFN_GETNAMEINFOT	equ <LPFN_GETNAMEINFOA>
endif
endif

if (NTDDI_VERSION GE NTDDI_VISTA)

inet_pton proto WINAPI :SINT, :PCSTR, :ptr
InetPtonW proto WINAPI :SINT, :PCWSTR, :ptr
inet_ntop proto WINAPI :SINT, :ptr, :PSTR, :size_t
InetNtopW proto WINAPI :SINT, :ptr, :PWSTR, :size_t
InetPtonA		equ <inet_pton>
InetNtopA		equ <inet_ntop>
ifdef _UNICODE
InetPton		equ <InetPtonW>
InetNtop		equ <InetNtopW>
else
InetPton		equ <InetPtonA>
InetNtop		equ <InetNtopA>
endif

if INCL_WINSOCK_API_TYPEDEFS

CALLBACK(LPFN_INET_PTONA, :SINT, :PCSTR, :ptr)
CALLBACK(LPFN_INET_PTONW, :SINT, :PCWSTR, :ptr)
CALLBACK(LPFN_INET_NTOPA, :SINT, :ptr, :PSTR, :size_t)
CALLBACK(LPFN_INET_NTOPW, :SINT, :ptr, :PWSTR, :size_t)
ifdef _UNICODE
LPFN_INET_PTON		equ <LPFN_INET_PTONW>
LPFN_INET_NTOP		equ <LPFN_INET_NTOPW>
else
LPFN_INET_PTON		equ <LPFN_INET_PTONA>
LPFN_INET_NTOP		equ <LPFN_INET_NTOPA>
endif

endif  ;;  TYPEDEFS
endif  ;;  (NTDDI_VERSION GE NTDDI_VISTA)


if INCL_WINSOCK_API_PROTOTYPES
ifdef _UNICODE
gai_strerror		equ <gai_strerrorW>
else
gai_strerror		equ <gai_strerrorA>
endif

GAI_STRERROR_BUFFER_SIZE equ 1024

if 0
gai_strerrorA macro ecode
    FormatMessageA(
	FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS or FORMAT_MESSAGE_MAX_WIDTH_MASK,
	NULL,
	ecode,
	MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
	addr _bufin,
	GAI_STRERROR_BUFFER_SIZE,
	NULL)
    mov ecx,eax
    lea rax,_bufin
    retm<rax>
    endm
gai_strerrorW macro ecode
    FormatMessageW(
	FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS or FORMAT_MESSAGE_MAX_WIDTH_MASK,
	NULL,
	ecode,
	MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
	addr _bufin,
	GAI_STRERROR_BUFFER_SIZE,
	NULL)
    mov ecx,eax
    lea rax,_bufin
    retm<rax>
    endm
endif

endif ;; INCL_WINSOCK_API_PROTOTYPES

if (_WIN32_WINNT GE 0x0600)
ifdef _SECURE_SOCKET_TYPES_DEFINED_

if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
WSASetSocketSecurity proto WINAPI :SOCKET, :ptr, :ULONG, :LPWSAOVERLAPPED, :LPWSAOVERLAPPED_COMPLETION_ROUTINE
WSAQuerySocketSecurity proto WINAPI :SOCKET, :ptr, :ULONG, :ptr, :ptr, :LPWSAOVERLAPPED, :LPWSAOVERLAPPED_COMPLETION_ROUTINE
WSASetSocketPeerTargetName proto WINAPI :SOCKET, :ptr, :ULONG, :LPWSAOVERLAPPED, :LPWSAOVERLAPPED_COMPLETION_ROUTINE
WSADeleteSocketPeerTargetName proto WINAPI :SOCKET, :ptr, :ULONG, :LPWSAOVERLAPPED, :LPWSAOVERLAPPED_COMPLETION_ROUTINE
WSAImpersonateSocketPeer proto WINAPI :SOCKET, :ptr,  :ULONG
WSARevertImpersonation proto WINAPI
endif

endif
endif

if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)

if NOT defined(_WIN32_WINNT) OR (_WIN32_WINNT LE 0x0500)
include wspiapi.inc
endif
endif

endif
