#pragma warning disable IDE1006 // Naming Styles using System; using System.Data; using System.Runtime.InteropServices; using System.Text; using Vanara.Extensions; using Vanara.InteropServices; namespace Vanara.PInvoke { /// Functions, structures and constants from ws2_32.h. public static partial class Ws2_32 { /// The CompletionRoutine is a placeholder for an application-defined or library-defined function name. /// Specifies the completion status for the overlapped operation as indicated by lpOverlapped. /// Specifies the number of bytes received. /// The overlapped operation. /// Contains information that would have appeared in lpFlags if the receive operation had completed immediately. // void (CALLBACK* LPWSAOVERLAPPED_COMPLETION_ROUTINE) ( IN DWORD dwError, IN DWORD cbTransferred, IN LPWSAOVERLAPPED lpOverlapped, // IN DWORD dwFlags ); [PInvokeData("winsock2.h", MSDNShortId = "abaf367a-8f99-478c-a58c-d57e9f9cd8a1")] public delegate void LPWSAOVERLAPPED_COMPLETION_ROUTINE([In] uint dwError, [In] uint cbTransferred, [In] in WSAOVERLAPPED lpOverlapped, [In] uint dwFlags); /// Network events. [PInvokeData("winsock2.h", MSDNShortId = "f98a71e4-47fb-47a4-b37e-e4cc801a8f98")] public enum FD { /// Wants to receive notification of readiness for reading. FD_READ = (1 << 0), /// Wants to receive notification of readiness for writing. FD_WRITE = (1 << 1), /// Wants to receive notification of the arrival of OOB data. FD_OOB = (1 << 2), /// Wants to receive notification of incoming connections. FD_ACCEPT = (1 << 3), /// Wants to receive notification of completed connection or multipoint join operation. FD_CONNECT = (1 << 4), /// Wants to receive notification of socket closure. FD_CLOSE = (1 << 5), /// Wants to receive notification of socket (QoS changes. FD_QOS = (1 << 6), /// Reserved for future use with socket groups. Want to receive notification of socket group QoS changes. FD_GROUP_QOS = (1 << 7), /// Wants to receive notification of routing interface changes for the specified destination. FD_ROUTING_INTERFACE_CHANGE = (1 << 8), /// Wants to receive notification of local address list changes for the address family of the socket. FD_ADDRESS_LIST_CHANGE = (1 << 9), /// All events. FD_ALL_EVENTS = ((1 << 10) - 1) } /// Flags to indicate that the socket is acting as a sender (JL_SENDER_ONLY), receiver (JL_RECEIVER_ONLY), or both (JL_BOTH). [PInvokeData("winsock2.h", MSDNShortId = "ef9efa03-feed-4f0d-b874-c646cce745c9")] [Flags] public enum JL { /// Acting as a sender. JL_SENDER_ONLY = 0x01, /// Acting as a receiver. JL_RECEIVER_ONLY = 0x02, /// Acting as both sender and receiver. JL_BOTH = 0x04, } /// Flags that control the depth of the search. [PInvokeData("winsock2.h", MSDNShortId = "448309ef-b9dd-4960-8016-d26691df59ec")] [Flags] public enum LUP : uint { /// Queries deep as opposed to just the first level. LUP_DEEP = 0x0001, /// Returns containers only. LUP_CONTAINERS = 0x0002, /// Do not return containers. LUP_NOCONTAINERS = 0x0004, /// If possible, returns results in the order of distance. The measure of distance is provider specific. LUP_NEAREST = 0x0008, /// Retrieves the name as lpszServiceInstanceName. LUP_RETURN_NAME = 0x0010, /// Retrieves the type as lpServiceClassId. LUP_RETURN_TYPE = 0x0020, /// Retrieves the version as lpVersion. LUP_RETURN_VERSION = 0x0040, /// Retrieves the comment as lpszComment. LUP_RETURN_COMMENT = 0x0080, /// Retrieves the addresses as lpcsaBuffer. LUP_RETURN_ADDR = 0x0100, /// Retrieves the private data as lpBlob. LUP_RETURN_BLOB = 0x0200, /// /// Any available alias information is to be returned in successive calls to WSALookupServiceNext, and each alias returned will /// have the RESULT_IS_ALIAS flag set. /// LUP_RETURN_ALIASES = 0x0400, /// Retrieves the query string used for the request. LUP_RETURN_QUERY_STRING = 0x0800, /// A set of flags that retrieves all of the LUP_RETURN_* values. LUP_RETURN_ALL = 0x0FF0, /// If the provider has cached information, ignore the cache and query the namespace itself. LUP_FLUSHCACHE = 0x1000, /// /// Used as a value for the dwControlFlags parameter in NSPLookupServiceNext. Setting this flag instructs the provider to /// discard the last result set, which was too large for the supplied buffer, and move on to the next result set. /// LUP_FLUSHPREVIOUS = 0x2000, /// Indicates that the namespace provider should included non-authoritative results for names. LUP_NON_AUTHORITATIVE = 0x4000, /// /// Indicates whether prime response is in the remote or local part of CSADDR_INFO structure. The other part must be usable in /// either case. This option applies only to service instance requests. /// LUP_RES_SERVICE = 0x8000, /// Indicates that the namespace provider should use a secure query. This option only applies to name query requests. LUP_SECURE = 0x8000, /// Indicates that the namespace provider should return only preferred names. LUP_RETURN_PREFERRED_NAMES = 0x10000, /// Indicates that the namespace provider should return the address configuration. LUP_ADDRCONFIG = 0x100000, /// /// Indicates that the namespace provider should return the dual addresses. This option only applies to dual-mode sockets (IPv6 /// and IPv4 mapped addresses). /// LUP_DUAL_ADDR = 0x200000, /// LUP_DNS_ONLY = 0x20000, /// LUP_FILESERVER = 0x00400000, /// /// Indicates that the namespace provider should disable automatic International Domain Names encoding. This value is supported /// on Windows 8 and Windows Server 2012 /// LUP_DISABLE_IDN_ENCODING = 0x00800000, /// LUP_API_ANSI = 0x01000000, /// LUP_RESOLUTION_HANDLE = 0x80000000, } /// /// The lpFlags parameter can be used to influence the behavior of the function invocation beyond the options specified for the /// associated socket. That is, the semantics of this function are determined by the socket options and the lpFlags parameter. /// [PInvokeData("winsock2.h", MSDNShortId = "bfe66e11-e9a7-4321-ad55-3141113e9a03")] [Flags] public enum MsgFlags { /// Processes OOB data. MSG_OOB = 0x1, /// /// Peeks at the incoming data. The data is copied into the buffer, but is not removed from the input queue. This flag is valid /// only for nonoverlapped sockets. /// MSG_PEEK = 0x2, /// MSG_DONTROUTE = 0x4, /// /// The receive request will complete only when one of the following events occurs: Be aware that if the underlying transport /// provider does not support MSG_WAITALL, or if the socket is in a non-blocking mode, then this call will fail with /// WSAEOPNOTSUPP. Also, if MSG_WAITALL is specified along with MSG_OOB, MSG_PEEK, or MSG_PARTIAL, then this call will fail with /// WSAEOPNOTSUPP. This flag is not supported on datagram sockets or message-oriented sockets. /// MSG_WAITALL = 0x8, /// /// This flag is for stream-oriented sockets only. This flag allows an application that uses stream sockets to tell the /// transport provider not to delay completion of partially filled pending receive requests. This is a hint to the transport /// provider that the application is willing to receive any incoming data as soon as possible without necessarily waiting for /// the remainder of the data that might still be in transit. What constitutes a partially filled pending receive request is a /// transport-specific matter. In the case of TCP, this refers to the case of incoming TCP segments being placed into the /// receive request data buffer where none of the TCP segments indicated a PUSH bit value of 1. In this case, TCP may hold the /// partially filled receive request a little longer to allow the remainder of the data to arrive with a TCP segment that has /// the PUSH bit set to 1. This flag tells TCP not to hold the receive request but to complete it immediately. Using this flag /// for large block transfers is not recommended since processing partial blocks is often not optimal. This flag is useful only /// for cases where receiving and processing the partial data immediately helps decrease processing latency. This flag is a hint /// rather than an actual guarantee. This flag is supported on Windows 8.1, Windows Server 2012 R2, and later. /// MSG_PUSH_IMMEDIATE = 0x20, /// /// This flag is for message-oriented sockets only. On output, this flag indicates that the data specified is a portion of the /// message transmitted by the sender. Remaining portions of the message will be specified in subsequent receive operations. A /// subsequent receive operation with the MSG_PARTIAL flag cleared indicates end of sender's message. As an input parameter, /// this flag indicates that the receive operation should complete even if only part of a message has been received by the /// transport provider. /// MSG_PARTIAL = 0x8000, /// MSG_INTERRUPT = 0x10, /// The datagram was truncated. More data was present than the process allocated room for. MSG_TRUNC = 0x0100, /// The control (ancillary) data was truncated. More control data was present than the process allocated room for. MSG_CTRUNC = 0x0200, /// The datagram was received as a link-layer broadcast or with a destination IP address that is a broadcast address. MSG_BCAST = 0x0400, /// The datagram was received with a destination IP address that is a multicast address. MSG_MCAST = 0x0800, /// /// This flag specifies that queued errors should be received from the socket error queue. The error is passed in an ancillary /// message with a type dependent on the protocol (for IPv4 IP_RECVERR). The user should supply a buffer of sufficient size.See /// cmsg(3) and ip(7) for more information.The payload of the original packet that caused the error is passed as normal data via /// msg_iovec. The original destination address of the datagram that caused the error is supplied via msg_name. /// MSG_ERRQUEUE = 0x1000, } /// /// A set of flags that indicate the type of status being requested or, upon return from the WSAPoll function call, the results of /// the status query. /// [PInvokeData("winsock2.h", MSDNShortId = "88f122ce-e2ca-44ce-bd53-d73d0962e7ef")] [Flags] public enum PollFlags : short { /// Normal data may be read without blocking. POLLRDNORM = 0x0100, /// Priority band (out-of-band) data may be read without blocking. POLLRDBAND = 0x0200, /// POLLRDNORM | POLLRDBAND POLLIN = (POLLRDNORM | POLLRDBAND), /// Priority data may be read without blocking. This flag is not returned by the Microsoft Winsock provider. POLLPRI = 0x0400, /// Normal data may be written without blocking. POLLWRNORM = 0x0010, /// Normal data may be written without blocking. POLLOUT = (POLLWRNORM), /// POLLWRBAND = 0x0020, /// An error has occurred. POLLERR = 0x0001, /// A stream-oriented connection was either disconnected or aborted. POLLHUP = 0x0002, /// An invalid socket was used. POLLNVAL = 0x0004, } /// Service install flags value that further controls the operation performed of the WSASetServicefunction. [PInvokeData("winsock2.h", MSDNShortId = "21a8ff26-4c9e-4846-a75a-1a27c746edab")] [Flags] public enum ServiceInstallFlags { /// /// Controls scope of operation. When this flag is not set, service addresses are managed as a group. A register or removal from /// the registry invalidates all existing addresses before adding the given address set. When set, the action is only performed /// on the given address set. A register does not invalidate existing addresses and a removal from the registry only invalidates /// the given set of addresses. /// SERVICE_MULTIPLE = 0x00000001, } /// A set of flags used to specify additional socket attributes. [PInvokeData("winsock2.h", MSDNShortId = "dcf2e543-de54-43d9-9e45-4cb935da3548")] [Flags] public enum WSA_FLAG { /// /// Create a socket that supports overlapped I/O operations. Most sockets should be created with this flag set. Overlapped /// sockets can utilize WSASend, WSASendTo, WSARecv, WSARecvFrom, and WSAIoctl for overlapped I/O operations, which allow /// multiple operations to be initiated and in progress simultaneously. All functions that allow overlapped operation (WSASend, /// WSARecv, WSASendTo, WSARecvFrom, WSAIoctl) also support nonoverlapped usage on an overlapped socket if the values for /// parameters related to overlapped operations are NULL. /// WSA_FLAG_OVERLAPPED = 0x01, /// /// Create a socket that will be a c_root in a multipoint session. This attribute is only allowed if the WSAPROTOCOL_INFO /// structure for the transport provider that creates the socket supports a multipoint or multicast mechanism and the control /// plane for a multipoint session is rooted. This would be indicated by the dwServiceFlags1 member of the WSAPROTOCOL_INFO /// structure with the XP1_SUPPORT_MULTIPOINT and XP1_MULTIPOINT_CONTROL_PLANE flags set. When the lpProtocolInfo parameter is /// not NULL, the WSAPROTOCOL_INFO structure for the transport provider is pointed to by the lpProtocolInfo parameter. When the /// lpProtocolInfo parameter is NULL, the WSAPROTOCOL_INFO structure is based on the transport provider selected by the values /// specified for the af, type, and protocol parameters. Refer to Multipoint and Multicast Semantics for additional information /// on a multipoint session. /// WSA_FLAG_MULTIPOINT_C_ROOT = 0x02, /// /// Create a socket that will be a c_leaf in a multipoint session. This attribute is only allowed if the WSAPROTOCOL_INFO /// structure for the transport provider that creates the socket supports a multipoint or multicast mechanism and the control /// plane for a multipoint session is non-rooted. This would be indicated by the dwServiceFlags1 member of the WSAPROTOCOL_INFO /// structure with the XP1_SUPPORT_MULTIPOINT flag set and the XP1_MULTIPOINT_CONTROL_PLANE flag not set. When the /// lpProtocolInfo parameter is not NULL, the WSAPROTOCOL_INFO structure for the transport provider is pointed to by the /// lpProtocolInfo parameter. When the lpProtocolInfo parameter is NULL, the WSAPROTOCOL_INFO structure is based on the /// transport provider selected by the values specified for the af, type, and protocol parameters. Refer to Multipoint and /// Multicast Semantics for additional information on a multipoint session. /// WSA_FLAG_MULTIPOINT_C_LEAF = 0x04, /// /// Create a socket that will be a d_root in a multipoint session. This attribute is only allowed if the WSAPROTOCOL_INFO /// structure for the transport provider that creates the socket supports a multipoint or multicast mechanism and the data plane /// for a multipoint session is rooted. This would be indicated by the dwServiceFlags1 member of the WSAPROTOCOL_INFO structure /// with the XP1_SUPPORT_MULTIPOINT and XP1_MULTIPOINT_DATA_PLANE flags set. When the lpProtocolInfo parameter is not NULL, the /// WSAPROTOCOL_INFO structure for the transport provider is pointed to by the lpProtocolInfo parameter. When the lpProtocolInfo /// parameter is NULL, the WSAPROTOCOL_INFO structure is based on the transport provider selected by the values specified for /// the af, type, and protocol parameters. Refer to Multipoint and Multicast Semantics for additional information on a /// multipoint session. /// WSA_FLAG_MULTIPOINT_D_ROOT = 0x08, /// /// Create a socket that will be a d_leaf in a multipoint session. This attribute is only allowed if the WSAPROTOCOL_INFO /// structure for the transport provider that creates the socket supports a multipoint or multicast mechanism and the data plane /// for a multipoint session is non-rooted. This would be indicated by the dwServiceFlags1 member of the WSAPROTOCOL_INFO /// structure with the XP1_SUPPORT_MULTIPOINT flag set and the XP1_MULTIPOINT_DATA_PLANE flag not set. When the lpProtocolInfo /// parameter is not NULL, the WSAPROTOCOL_INFO structure for the transport provider is pointed to by the lpProtocolInfo /// parameter. When the lpProtocolInfo parameter is NULL, the WSAPROTOCOL_INFO structure is based on the transport provider /// selected by the values specified for the af, type, and protocol parameters. Refer to Multipoint and Multicast Semantics for /// additional information on a multipoint session. /// WSA_FLAG_MULTIPOINT_D_LEAF = 0x10, /// /// Create a socket that allows the the ability to set a security descriptor on the socket that contains a security access /// control list (SACL) as opposed to just a discretionary access control list (DACL). SACLs are used for generating audits and /// alarms when an access check occurs on the object. For a socket, an access check occurs to determine whether the socket /// should be allowed to bind to a specific address specified to the bind function. The ACCESS_SYSTEM_SECURITY access right /// controls the ability to get or set the SACL in an object's security descriptor. The system grants this access right only if /// the SE_SECURITY_NAME privilege is enabled in the access token of the requesting thread. /// WSA_FLAG_ACCESS_SYSTEM_SECURITY = 0x40, /// /// Create a socket that is non-inheritable. A socket handle created by the WSASocket or the socket function is inheritable by /// default. When this flag is set, the socket handle is non-inheritable. The GetHandleInformation function can be used to /// determine if a socket handle was created with the WSA_FLAG_NO_HANDLE_INHERIT flag set. The GetHandleInformation function /// will return that the HANDLE_FLAG_INHERIT value is set. This flag is supported on Windows 7 with SP1, Windows Server 2008 R2 /// with SP1, and later /// WSA_FLAG_NO_HANDLE_INHERIT = 0x80, /// WSA_FLAG_REGISTERED_IO = 0x100, } #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member [PInvokeData("winsock2.h")] public enum WSACOMPLETIONTYPE { NSP_NOTIFY_IMMEDIATELY, NSP_NOTIFY_HWND, NSP_NOTIFY_EVENT, NSP_NOTIFY_PORT, NSP_NOTIFY_APC, } #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } }