' ########################################################################################
' Microsoft Windows
' File: MSWSock.inc
' Contents: Microsoft-specific extensions to the Windows Sockets API
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_MSWSock_PBI)
#DEFINE PBX_MSWSock_PBI
%EQUATE `MSWSOCK_INC = 1
#INCLUDE ONCE "Legacy/Platform/WinSock2.inc"
' Always include winsock2.inc, never winsock.inc
'/*
' * Options for connect and disconnect data and options. Used only by
' * non-TCP/IP transports such as DECNet, OSI TP4, etc.
' */
%EQUATE `SO_CONNDATA = &H7000
%EQUATE `SO_CONNOPT = &H7001
%EQUATE `SO_DISCDATA = &H7002
%EQUATE `SO_DISCOPT = &H7003
%EQUATE `SO_CONNDATALEN = &H7004
%EQUATE `SO_CONNOPTLEN = &H7005
%EQUATE `SO_DISCDATALEN = &H7006
%EQUATE `SO_DISCOPTLEN = &H7007
'/*
' * Option for opening sockets for synchronous access.
' */
%EQUATE `SO_OPENTYPE = &H7008
%EQUATE `SO_SYNCHRONOUS_ALERT = &H10
%EQUATE `SO_SYNCHRONOUS_NONALERT = &H20
'/*
' * Other NT-specific options.
' */
%EQUATE `SO_MAXDG = &H7009
%EQUATE `SO_MAXPATHDG = &H700A
%EQUATE `SO_UPDATE_ACCEPT_CONTEXT = &H700B
%EQUATE `SO_CONNECT_TIME = &H700C
'#if(_WIN32_WINNT >= 0x0501)
%EQUATE `SO_UPDATE_CONNECT_CONTEXT = &H7010
'#endif //(_WIN32_WINNT >= 0x0501)
'/*
' * TCP options.
' */
%EQUATE `TCP_BSDURGENT = &H7000
'/*
' * MS Transport Provider IOCTL to control
' * reporting PORT_UNREACHABLE messages
' * on UDP sockets via recv/WSARecv/etc.
' * Path TRUE in input buffer to enable (default if supported),
' * FALSE to disable.
' */
%EQUATE `SIO_UDP_CONNRESET = &H9800000C ' _WSAIOW(IOC_VENDOR,12)
'#if((_WIN32_WINNT < 0x0600) && (_WIN32_WINNT >= 0x0501))
'/*
' * MS Transport Provider IOCTL to request
' * notification when a given socket is closed.
' * Input buffer must be a pointer to the socket handle.
' * Input buffer size must be exactly sizeof(HANDLE).
' * Output buffer and output buffer length must be
' * NULL and 0 respectively. This IOCTL must always
' * be issued with an overlapped structure.
' */
%EQUATE `SIO_SOCKET_CLOSE_NOTIFY = &H9800000D ' _WSAIOW(IOC_VENDOR,13)
'#endif //(_WIN32_WINNT < 0x0600 && _WIN32_WINNT >= 0x0501)
'/*
' * MS Transport Provider IOCTL to control
' * reporting NET_UNREACHABLE (TTL expired) messages
' * on UDP sockets via recv/WSARecv/Etc.
' * Pass TRUE in input buffer to enabled (default if supported),
' * FALSE to disable.
' */
%EQUATE `SIO_UDP_NETRESET = &H9800000F ' _WSAIOW(IOC_VENDOR,15)
'/*
' * Microsoft extended APIs.
' */
' There is also a WSARecvEx defined in Winsock.inc
#IF %DEF(%USEPBDECL)
DECLARE FUNCTION WSARecvEx LIB "Mswsock.dll" ALIAS "WSARecvEx" ( BYVAL s AS QUAD, ' SOCKET
 BYVAL buf AS BYTE PTR, BYVAL buflen AS LONG, flags AS LONG ) AS LONG
#ELSE
DECLARE FUNCTION WSARecvEx LIB "mswsock.dll" ALIAS "WSARecvEx" ( BYVAL s AS QUAD , BYREF buf AS ANY , BYVAL len AS LONG , BYREF flags AS LONG ) AS LONG ' int
#ENDIF
' // Size = 16 bytes
TYPE TRANSMIT_FILE_BUFFERS DWORD
 Head AS DWORD
 HeadLength AS DWORD
 Tail AS DWORD
 TailLength AS DWORD
END TYPE
%EQUATE `TF_DISCONNECT = &H01
%EQUATE `TF_REUSE_SOCKET = &H02
%EQUATE `TF_WRITE_BEHIND = &H04
%EQUATE `TF_USE_DEFAULT_WORKER = &H00
%EQUATE `TF_USE_SYSTEM_THREAD = &H10
%EQUATE `TF_USE_KERNEL_APC = &H20
DECLARE FUNCTION TransmitFile LIB "mswsock.dll" ALIAS "TransmitFile" ( BYVAL hSocket AS QUAD , BYVAL hFile AS QUAD , BYVAL nNumberOfBytesToWrite AS QUAD , BYVAL nNumberOfBytesPerSend AS QUAD , BYREF lpOverlapped AS OVERLAPPED , BYREF lpTransmitBuffers AS TRANSMIT_FILE_BUFFERS , BYVAL dwReserved AS QUAD ) AS LONG
' There is also an AcceptEx function defined in Winsock.inc
DECLARE FUNCTION AcceptEx LIB "mswsock.dll" ALIAS "AcceptEx" ( BYVAL sListenSocket AS QUAD , BYVAL sAcceptSocket AS QUAD , BYREF lpOutputBuffer AS ANY , BYVAL dwReceiveDataLength AS QUAD , BYVAL dwLocalAddressLength AS QUAD , BYVAL dwRemoteAddressLength AS QUAD , BYREF lpdwBytesReceived AS QUAD , BYREF lpOverlapped AS OVERLAPPED ) AS LONG
' There is also an GetAcceptExSockaddrs function defined in Winsock.inc
DECLARE SUB GetAcceptExSockaddrs LIB "mswsock.dll" ALIAS "GetAcceptExSockaddrs" ( BYREF lpOutputBuffer AS ANY , BYVAL dwReceiveDataLength AS QUAD , BYVAL dwLocalAddressLength AS QUAD , BYVAL dwRemoteAddressLength AS QUAD , BYREF LocalSockaddr AS ANY , BYREF LocalSockaddrLength AS LONG , BYREF RemoteSockaddr AS ANY , BYREF RemoteSockaddrLength AS LONG ) ' void
'/*
' * "QueryInterface" versions of the above APIs.
' */
'typedef
'(PASCAL FAR * LPFN_TRANSMITFILE)(
' IN SOCKET hSocket,
' IN HANDLE hFile,
' IN DWORD nNumberOfBytesToWrite,
' IN DWORD nNumberOfBytesPerSend,
' IN LPOVERLAPPED lpOverlapped,
' IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers,
' IN DWORD dwReserved
' );
'FUNCTION FN_TRANSMITFILE ( ' BYVAL hSocket AS DWORD
' , BYVAL hFile AS DWORD
' , BYVAL nNumberOfBytesToWrite AS DWORD
' , BYVAL nNumberOfBytesPerSend AS DWORD
' , BYREF lpOverlapped AS OVERLAPPED
' , BYREF lpTransmitBuffers AS TRANSMIT_FILE_BUFFERS
' , BYVAL dwReserved AS DWORD
' ) AS LONG
'#define WSAID_TRANSMITFILE \
' {0xb5367df0,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
$WSAID_TRANSMITFILE = GUID$("{B5367DF0-CBAC-11CF-95CA-00805F48A192}")
'typedef
'(PASCAL FAR * LPFN_ACCEPTEX)(
' IN SOCKET sListenSocket,
' IN SOCKET sAcceptSocket,
' IN PVOID lpOutputBuffer,
' IN DWORD dwReceiveDataLength,
' IN DWORD dwLocalAddressLength,
' IN DWORD dwRemoteAddressLength,
' OUT LPDWORD lpdwBytesReceived,
' IN LPOVERLAPPED lpOverlapped
' );
'FUNCTION FN_ACCEPTEX ( ' BYVAL sListenSocket AS DWORD
' , BYVAL sAcceptSocket AS DWORD
' , BYVAL lpOutputBuffer AS DWORD
' , BYVAL dwReceiveDataLength AS DWORD
' , BYVAL dwLocalAddressLength AS DWORD
' , BYVAL dwRemoteAddressLength AS DWORD
' , BYREF lpdwBytesReceived AS DWORD
' , BYREF lpOverlapped AS OVERLAPPED
' ) AS LONG
'#define WSAID_ACCEPTEX \
' {0xb5367df1,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
$WSAID_ACCEPTEX = GUID$("{B5367DF1-CBAC-11CF-95CA-00805F48A192}")
'typedef
'(PASCAL FAR * LPFN_GETACCEPTEXSOCKADDRS)(
' IN PVOID lpOutputBuffer,
' IN DWORD dwReceiveDataLength,
' IN DWORD dwLocalAddressLength,
' IN DWORD dwRemoteAddressLength,
' OUT struct sockaddr **LocalSockaddr,
' OUT LPINT LocalSockaddrLength,
' OUT struct sockaddr **RemoteSockaddr,
' OUT LPINT RemoteSockaddrLength
' );
'SUB FN_GETACCEPTEXSOCKADDRS ( ' BYVAL lpOutputBuffer AS DWORD
' , BYVAL dwReceiveDataLength AS DWORD
' , BYVAL dwLocalAddressLength AS DWORD
' , BYVAL dwRemoteAddressLength AS DWORD
' , BYREF LocalSockaddr AS SOCKADDR
' , BYREF LocalSockaddrLength AS LONG
' , BYREF RemoteSockaddr AS SOCKADDR
' , BYREF RemoteSockaddrLength AS LONG
' ) ' void
'#define WSAID_GETACCEPTEXSOCKADDRS \
' {0xb5367df2,0xcbac,0x11cf,{0x95,0xca,0x00,0x80,0x5f,0x48,0xa1,0x92}}
$WSAID_GETACCEPTEXSOCKADDRS = GUID$("{B5367DF2-CBAC-11CF-95CA-00805F48A192}")
'#if(_WIN32_WINNT >= 0x0501)
%EQUATE `TP_ELEMENT_MEMORY = 1
%EQUATE `TP_ELEMENT_FILE = 2
%EQUATE `TP_ELEMENT_EOP = 4
' // Size = 16 bytes
TYPE TRANSMIT_PACKETS_ELEMENT_UNION_STRUCT QWORD
 nFileOffset AS QUAD ' LARGE_INTEGER
 hFile AS DWORD
END TYPE
' // Size = 16 bytes
UNION TRANSMIT_PACKETS_ELEMENT_UNION QWORD
 TRANSMIT_PACKETS_ELEMENT_UNION_STRUCT
 pBuffer AS DWORD
END UNION
' // Size = 24 bytes
TYPE TRANSMIT_PACKETS_ELEMENT QWORD FILL
 dwElFlags AS DWORD ' ULONG
 cLength AS DWORD ' ULONG
 TRANSMIT_PACKETS_ELEMENT_UNION
END TYPE
%EQUATE `TP_DISCONNECT = %TF_DISCONNECT
%EQUATE `TP_REUSE_SOCKET = %TF_REUSE_SOCKET
%EQUATE `TP_USE_DEFAULT_WORKER = %TF_USE_DEFAULT_WORKER
%EQUATE `TP_USE_SYSTEM_THREAD = %TF_USE_SYSTEM_THREAD
%EQUATE `TP_USE_KERNEL_APC = %TF_USE_KERNEL_APC
'typedef
'(PASCAL FAR * LPFN_TRANSMITPACKETS) (
' SOCKET hSocket,
' LPTRANSMIT_PACKETS_ELEMENT lpPacketArray,
' DWORD nElementCount,
' DWORD nSendSize,
' LPOVERLAPPED lpOverlapped,
' DWORD dwFlags
' );
'FUNCTION FN_TRANSMITPACKETS ( ' BYVAL hSocket AS DWORD ' SOCKET hSocket
' , BYREF lpPacketArray AS TRANSMIT_PACKETS_ELEMENT ' LPTRANSMIT_PACKETS_ELEMENT lpPacketArray
' , BYVAL nElementCount AS DWORD ' DWORD nElementCount
' , BYVAL nSendSize AS DWORD ' DWORD nSendSize
' , BYREF lpOverlapped AS OVERLAPPED ' LPOVERLAPPED lpOverlapped
' , BYVAL dwFlags AS DWORD ' DWORD dwFlags
' ) AS LONG
'#define WSAID_TRANSMITPACKETS \
' {0xd9689da0,0x1f90,0x11d3,{0x99,0x71,0x00,0xc0,0x4f,0x68,0xc8,0x76}}
$WSAID_TRANSMITPACKETS = GUID$("{D9689DA0-1F90-11D3-9971-00C04F68C876}")
'typedef
'(PASCAL FAR * LPFN_CONNECTEX) (
' );
'FUNCTION FN_CONNECTEX ( ' BYVAL s AS DWORD
' , BYREF name AS SOCKADDR
' , BYVAL namelen AS LONG
' , BYVAL lpSendBuffer AS DWORD
' , BYVAL dwSendDataLength AS DWORD
' , BYREF lpdwBytesSent AS DWORD
' , BYREF lpOverlapped AS OVERLAPPED
' ) AS LONG
'#define WSAID_CONNECTEX \
' {0x25a207b9,0xddf3,0x4660,{0x8e,0xe9,0x76,0xe5,0x8c,0x74,0x06,0x3e}}
$WSAID_CONNECTEX = GUID$("{25A207B9-DDF3-4660-8EE9-76E58C74063E}")
'typedef
'(PASCAL FAR * LPFN_DISCONNECTEX) (
' );
'FUNCTION FN_DISCONNECTEX ( ' BYVAL s AS DWORD
' , BYREF lpOverlapped AS OVERLAPPED
' , BYVAL dwFlags AS DWORD
' , BYVAL dwReserved AS DWORD
' ) AS LONG
'#define WSAID_DISCONNECTEX \
' {0x7fda2e11,0x8630,0x436f,{0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57}}
$WSAID_DISCONNECTEX = GUID$("{7FDA2E11-8630-436F-A031-F536-A6EEC157}")
%EQUATE `DE_REUSE_SOCKET = %TF_REUSE_SOCKET
'/*
' * Network-location awareness -- Name registration values for use
' * with WSASetService and other structures.
' */
$NLA_NAMESPACE_GUID = GUID$("{6642243A-3BA8-4AA6-BAA5-2E0BD71FDD83}")
$NLA_SERVICE_CLASS_GUID = GUID$("{6642243A-3BA8-4AA6-BAA5-2E0BD71FDD83}")
%EQUATE `NLA_ALLUSERS_NETWORK = &H00000001
%EQUATE `NLA_FRIENDLY_NAME = &H00000002
' enum _NLA_BLOB_DATA_TYPE
%EQUATE `NLA_RAW_DATA = 0
%EQUATE `NLA_INTERFACE = 1
%EQUATE `NLA_802_1X_LOCATION = 2
%EQUATE `NLA_CONNECTIVITY = 3
%EQUATE `NLA_ICS = 4
' enum _NLA_CONNECTIVITY_TYPE
%EQUATE `NLA_NETWORK_AD_HOC = 0
%EQUATE `NLA_NETWORK_MANAGED = 1
%EQUATE `NLA_NETWORK_UNMANAGED = 2
%EQUATE `NLA_NETWORK_UNKNOWN = 3
' enum _NLA_INTERNET
%EQUATE `NLA_INTERNET_UNKNOWN = 0
%EQUATE `NLA_INTERNET_NO = 1
%EQUATE `NLA_INTERNET_YES = 2
'typedef struct _NLA_BLOB {
' struct {
' NLA_BLOB_DATA_TYPE type;
' DWORD dwSize;
' DWORD nextOffset;
' } header;
' union {
' // header.type -> NLA_RAW_DATA
' CHAR rawData[1];
' // header.type -> NLA_INTERFACE
' struct {
' DWORD dwType;
' DWORD dwSpeed;
' CHAR adapterName[1];
' } interfaceData;
' // header.type -> NLA_802_1X_LOCATION
' struct {
' CHAR information[1];
' } locationData;
' // header.type -> NLA_CONNECTIVITY
' struct {
' NLA_CONNECTIVITY_TYPE type;
' NLA_INTERNET internet;
' } connectivity;
' // header.type -> NLA_ICS
' struct {
' struct {
' DWORD speed;
' DWORD type;
' DWORD state;
' WCHAR machineName[256];
' WCHAR sharedAdapterName[256];
' } remote;
' } ICS;
' } data;
'} NLA_BLOB, *PNLA_BLOB, * FAR LPNLA_BLOB;
' // Size = 12 bytes
TYPE NLA_BLOB_HEADER DWORD
 type AS LONG ' NLA_BLOB_DATA_TYPE
 dwSize AS DWORD
 nextOffset AS DWORD
END TYPE
' // Size = 12 bytes
TYPE NLA_BLOB_INTERFACEDATA DWORD
 dwType AS DWORD
 dwSpeed AS DWORD
 adapterName(0) AS BYTE ' CHAR
END TYPE
' // Size = 1 byte
TYPE NLA_BLOB_LOCATIONDATA BYTE
 information(0) AS BYTE ' CHAR
END TYPE
' // Size = 8 bytes
TYPE NLA_BLOB_CONNECTIVITY DWORD
 type AS LONG ' NLA_CONNECTIVITY_TYPE
 internet AS LONG ' NLA_INTERNET
END TYPE
' // Size = 1036 bytes
TYPE NLA_BLOB_ICS_REMOTE DWORD
 speed AS DWORD
 type AS DWORD
 state AS DWORD
 machineName AS WSTRINGZ * 256 ' WCHAR
 sharedAdapterName AS WSTRINGZ * 256 ' WCHAR
END TYPE
' // Size = 1036 bytes
TYPE NLA_BLOB_ICS DWORD
 remote AS NLA_BLOB_ICS_REMOTE
END TYPE
' // Size = 1036 bytes
UNION NLA_BLOB_DATA DWORD
 ' // header.type -> NLA_RAW_DATA
 rawData(0) AS BYTE ' CHAR
 ' // header.type -> NLA_INTERFACE
 interfaceData AS NLA_BLOB_INTERFACEDATA
 ' // header.type -> NLA_802_1X_LOCATION
 locationData AS NLA_BLOB_LOCATIONDATA
 ' // header.type -> NLA_CONNECTIVITY
 connectivity AS NLA_BLOB_CONNECTIVITY
 ' // header.type -> NLA_ICS
 ICS AS NLA_BLOB_ICS
END UNION
' // Size = 1048 bytes
TYPE NLA_BLOB DWORD
 header AS NLA_BLOB_HEADER
 data AS NLA_BLOB_DATA
END TYPE
'typedef
'INT
'(PASCAL FAR * LPFN_WSARECVMSG) (
' );
'FUNCTION FN_WSARECVMSG ( ' BYVAL s AS DWORD
' , BYREF lpMsg AS WSAMSG
' , BYREF lpdwNumberOfBytesRecvd AS DWORD
' , BYREF lpOverlapped AS WSAOVERLAPPED
' , BYVAL lpCompletionRoutine AS DWORD
' ) AS LONG ' int
'#define WSAID_WSARECVMSG \
' {0xf689d7c8,0x6f1f,0x436b,{0x8a,0x53,0xe5,0x4f,0xe3,0x51,0xc3,0x22}}
$WSAID_WSARECVMSG = GUID$("{F689D7C8-6F1F-436B-8A53-E54FE351C322}")
'#endif //(_WIN32_WINNT >= 0x0501)
'#if(_WIN32_WINNT >= 0x0600)
'/*
' * Ioctl codes for translating socket handles to the base provider handle.
' * This is performed to prevent breaking non-IFS LSPs when new Winsock extension
' * funtions are added.
' */
%EQUATE `SIO_BSP_HANDLE = &H4800001B ' _WSAIOR(IOC_WS2,27)
%EQUATE `SIO_BSP_HANDLE_SELECT = &H4800001C ' _WSAIOR(IOC_WS2,28)
%EQUATE `SIO_BSP_HANDLE_POLL = &H4800001D ' _WSAIOR(IOC_WS2,29)
'/*
' * Ioctl code used to translate a socket handle into the base provider's handle.
' * This is not used by any Winsock extension function and should not be intercepted
' * by Winsock LSPs.
' */
'%SIO_BASE_HANDLE = &HC8000022 ' _WSAIOR(IOC_WS2,34) ' // Wrongly defined in the PB includes
%EQUATE `SIO_BASE_HANDLE = &H48000022 ' _WSAIOR(IOC_WS2,34)
'/*
' * Ioctl codes for Winsock extension functions.
' */
'%SIO_EXT_SELECT = &HC800001E ' _WSAIORW(IOC_WS2,30) ' // Wrongly defined in the PB includes
'%SIO_EXT_POLL = &HC800001F ' _WSAIORW(IOC_WS2,31) ' // Wrongly defined in the PB includes
'%SIO_EXT_SENDMSG = &HC8000020 ' _WSAIORW(IOC_WS2,32) ' // Wrongly defined in the PB includes
%EQUATE `SIO_EXT_SELECT = &H4800001E ' _WSAIORW(IOC_WS2,30)
%EQUATE `SIO_EXT_POLL = &H4800001F ' _WSAIORW(IOC_WS2,31)
%EQUATE `SIO_EXT_SENDMSG = &H48000020 ' _WSAIORW(IOC_WS2,32)
'/*
' * Data structure for passing WSAPoll arugments through WSAIoctl
' */
' // Size = 12 bytes
TYPE WSAPOLLDATA
 result AS LONG ' int
 fds AS DWORD ' ULONG
 timeout AS LONG ' INT
 ' fdArray() AS WSAPOLLFD ' variable-length array
END TYPE
'/*
' * Data structure for passing WSASendMsg arguments through WSAIoctl
' */
' // Size = 20 bytes
TYPE tagWSASENDMSG DWORD
 lpMsg AS WSAMSG PTR
 dwFlags AS DWORD
 lpNumberOfBytesSent AS DWORD PTR
 lpOverlapped AS WSAOVERLAPPED PTR
 lpCompletionRoutine AS DWORD ' LPWSAOVERLAPPED_COMPLETION_ROUTINE
END TYPE
MACRO WSASENDMSG_type = tagWSASENDMSG ' // For compatibility with PB includes
'/*
' * WSASendMsg -- send data to a specific destination, with options, using
' * overlapped I/O where applicable.
' *
' * Valid flags for dwFlags parameter:
' * MSG_DONTROUTE
' * MSG_PARTIAL (a.k.a. MSG_EOR) (only for non-stream sockets)
' * MSG_OOB (only for stream style sockets) (NYI)
' *
' * Caller must provide either lpOverlapped or lpCompletionRoutine
' * or neither (both NULL).
' */
'typedef
'INT
'(PASCAL FAR * LPFN_WSASENDMSG) (
' );
'FUNCTION FN_WSASENDMSG ( ' BYVAL s AS DWORD
' , BYREF lpMsg AS WSAMSG
' , BYVAL dwFlags AS DWORD
' , BYREF lpNumberOfBytesSent AS DWORD
' , BYREF lpOverlapped AS WSAOVERLAPPED
' , BYVAL lpCompletionRoutine AS DWORD
' ) AS LONG ' int
$WSAID_WSASENDMSG = GUID$("{A441E712-754F-43CA-84A7-0DEE44CF606D}")
'//
'// WSAPoll
'//
'FUNCTION FN_WSAPOLL ( ' BYREF fdarray AS WSAPOLLFD
' , BYVAL nfds AS DWORD
' , BYVAL ntimeout AS LONG
' ) AS LONG ' int
$WSAID_WSAPOLL = GUID$("{18C76F85-DC66-4964-972E-23C27238312B}")
'#endif //(_WIN32_WINNT >= 0x0600)
#ENDIF
