Reorganized structures into appropriately names files

pull/119/head
dahall 2020-04-17 18:03:22 -06:00
parent e9cf62fca3
commit 7ab58e2e74
3 changed files with 246 additions and 592 deletions

View File

@ -10157,261 +10157,6 @@ namespace Vanara.PInvoke
public SOCKET[] fd_array;
}
/// <summary>The SOCKET_ADDRESS_LIST structure defines a variable-sized list of transport addresses.</summary>
/// <remarks>
/// <para>
/// A WSK application passes a buffer to the WskControlSocket function when the WSK application queries the current list of local
/// transport addresses that match a socket's address family. If the call to the <c>WskControlSocket</c> function succeeds, the
/// buffer contains a SOCKET_ADDRESS_LIST structure followed by the SOCKADDR structures for each of the local transport addresses
/// that match the socket's address family. The WSK subsystem fills in the <c>Address</c> array and sets the <c>iAddressCount</c>
/// member to the number of entries in the array. The <c>lpSockaddr</c> pointers in each of the SOCKET_ADDRESS structures in the
/// array point to the specific SOCKADDR structure type that corresponds to the address family that the WSK application specified
/// when it created the socket.
/// </para>
/// <para>For more information about querying the current list of local transport addresses, see SIO_ADDRESS_LIST_QUERY.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/ws2def/ns-ws2def-socket_address_list typedef struct _SOCKET_ADDRESS_LIST { INT
// iAddressCount; SOCKET_ADDRESS Address[1]; } SOCKET_ADDRESS_LIST, *PSOCKET_ADDRESS_LIST, *LPSOCKET_ADDRESS_LIST;
[PInvokeData("ws2def.h", MSDNShortId = "b005200b-b0c2-4f19-8765-cd26fbfc0cff")]
[VanaraMarshaler(typeof(SafeAnysizeStructMarshaler<SOCKET_ADDRESS_LIST>), nameof(iAddressCount))]
[StructLayout(LayoutKind.Sequential)]
public struct SOCKET_ADDRESS_LIST
{
/// <summary>The number of transport addresses in the list.</summary>
public int iAddressCount;
/// <summary>A variable-sized array of SOCKET_ADDRESS structures. The SOCKET_ADDRESS structure is defined as follows:</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public SOCKET_ADDRESS[] Address;
}
/// <summary>
/// The <c>WSAMSG</c> structure is used with the WSARecvMsg and WSASendMsg functions to store address and optional control
/// information about connected and unconnected sockets as well as an array of buffers used to store message data.
/// </summary>
/// <remarks>
/// <para>
/// In the Microsoft Windows Software Development Kit (SDK), the version of this structure for use on Windows Vistais defined with
/// the data type for the <c>dwBufferCount</c> and <c>dwFlags</c> members as a <c>ULONG</c>. When compiling an application if the
/// target platform is Windows Vista and later ( <c>NTDDI_VERSION &gt;= NTDDI_LONGHORN, _WIN32_WINNT &gt;= 0x0600</c>, or <c>WINVER
/// &gt;= 0x0600</c>), the data type for the <c>dwBufferCount</c> and <c>dwFlags</c> members is a <c>ULONG</c>.
/// </para>
/// <para>
/// <c>Windows Server 2003 and Windows XP:</c> When compiling an application, the data type for the <c>dwBufferCount</c> and
/// <c>dwFlags</c> members is a <c>DWORD</c>.
/// </para>
/// <para>
/// On the Windows SDK released for Windows Vista and later, the <c>WSAMSG</c> structure is defined in the Ws2def.h header file.
/// Note that the Ws2def.h header file is automatically included in Winsock2.h, and should never be used directly
/// </para>
/// <para>
/// If the datagram or control data is truncated during the transmission, the function being used in association with the
/// <c>WSAMSG</c> structure returns SOCKET_ERROR and a call to the WSAGetLastError function returns WSAEMSGSIZE. It is up to the
/// application to determine what was truncated by checking for MSG_TRUNC and/or MSG_CTRUNC flags.
/// </para>
/// <para>Use of the Control Member</para>
/// <para>
/// The following table summarizes the various uses of control data available for use in the <c>Control</c> member for IPv4 and IPv6.
/// </para>
/// <list type="table">
/// <listheader>
/// <term>Protocol</term>
/// <term>cmsg_level</term>
/// <term>cmsg_type</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>IPv4</term>
/// <term>IPPROTO_IP</term>
/// <term>IP_ORIGINAL_ARRIVAL_IF</term>
/// <term>
/// Receives the original IPv4 arrival interface where the packet was received for datagram sockets. This control data is used by
/// firewalls when a Teredo, 6to4, or ISATAP tunnel is used for IPv4 NAT traversal. The cmsg_data[] member in the WSAMSG structure
/// is a ULONG that contains the IF_INDEX defined in the Ifdef.h header file. For more information, see the IPPROTO_IP Socket
/// Options for the IP_ORIGINAL_ARRIVAL_IF socket option. Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP:
/// The IP_ORIGINAL_ARRIVAL_IF cmsg_type is not supported.
/// </term>
/// </item>
/// <item>
/// <term>IPv4</term>
/// <term>IPPROTO_IP</term>
/// <term>IP_PKTINFO</term>
/// <term>Specifies/receives packet information for an IPv4 socket. For more information, see the IP_PKTINFO socket option.</term>
/// </item>
/// <item>
/// <term>IPv6</term>
/// <term>IPPROTO_IPV6</term>
/// <term>IPV6_DSTOPTS</term>
/// <term>Specifies/receives destination options.</term>
/// </item>
/// <item>
/// <term>IPv6</term>
/// <term>IPPROTO_IPV6</term>
/// <term>IPV6_HOPLIMIT</term>
/// <term>Specifies/receives hop limit. For more information, see the IPPROTO_IPV6 Socket Options for the IPV6_HOPLIMIT socket option.</term>
/// </item>
/// <item>
/// <term>IPv6</term>
/// <term>IPPROTO_IPV6</term>
/// <term>IPV6_HOPOPTS</term>
/// <term>Specifies/receives hop-by-hop options.</term>
/// </item>
/// <item>
/// <term>IPv6</term>
/// <term>IPPROTO_IPV6</term>
/// <term>IPV6_NEXTHOP</term>
/// <term>Specifies next-hop address.</term>
/// </item>
/// <item>
/// <term>IPv6</term>
/// <term>IPPROTO_IPV6</term>
/// <term>IPV6_PKTINFO</term>
/// <term>Specifies/receives packet information for an IPv6 socket. For more information, see the IPV6_PKTINFO socket option.</term>
/// </item>
/// <item>
/// <term>IPv6</term>
/// <term>IPPROTO_IPV6</term>
/// <term>IPV6_RTHDR</term>
/// <term>Specifies/receives routing header.</term>
/// </item>
/// </list>
/// <para>
/// Control data is made up of one or more control data objects, each beginning with a <c>WSACMSGHDR</c> structure, defined as the following.
/// </para>
/// <para>
/// <c>Note</c> The transport, not the application, fills out the header information in the <c>WSACMSGHDR</c> structure. The
/// application simply sets the needed socket options and provides the adequate buffer size.
/// </para>
/// <para>The members of the <c>WSACMSGHDR</c> structure are as follows:</para>
/// <list type="table">
/// <listheader>
/// <term>Term</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>cmsg_len</term>
/// <term>
/// The number of bytes of data starting from the beginning of the WSACMSGHDR to the end of data (excluding padding bytes that may
/// follow data).
/// </term>
/// </item>
/// <item>
/// <term>cmsg_level</term>
/// <term>The protocol that originated the control information.</term>
/// </item>
/// <item>
/// <term>cmsg_type</term>
/// <term>The protocol-specific type of control information.</term>
/// </item>
/// </list>
/// <para>The following macros are used to navigate the data objects:</para>
/// <para>
/// Returns a pointer to the first control data object. Returns a <c>NULL</c> pointer if there is no control data in the
/// <c>WSAMSG</c> structure, such as when the <c>Control</c> member is a <c>NULL</c> pointer.
/// </para>
/// <para>
/// Returns a pointer to the next control data object, or <c>NULL</c> if there are no more data objects. If the pcmsg parameter is
/// <c>NULL</c>, a pointer to the first control data object is returned.
/// </para>
/// <para>
/// Returns a pointer to the first byte of data (referred to as the <c>cmsg_data</c> member, though it is not defined in the structure).
/// </para>
/// <para>
/// Returns the total size of a control data object, given the amount of data. Used to allocate the correct amount of buffer space.
/// Includes alignment padding.
/// </para>
/// <para>Returns the value in <c>cmsg_len</c> given the amount of data. Includes alignment padding.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/ws2def/ns-ws2def-wsamsg typedef struct _WSAMSG { LPSOCKADDR name; INT namelen;
// LPWSABUF lpBuffers; #if ... ULONG dwBufferCount; #else DWORD dwBufferCount; #endif WSABUF Control; #if ... ULONG dwFlags; #else
// DWORD dwFlags; #endif } WSAMSG, *PWSAMSG, *LPWSAMSG;
[PInvokeData("ws2def.h", MSDNShortId = "105a6e2c-1edf-4ec0-a1c2-ac0bcafeda30")]
[StructLayout(LayoutKind.Sequential)]
public struct WSAMSG
{
/// <summary>
/// <para>Type: <c>LPSOCKADDR</c></para>
/// <para>
/// A pointer to a SOCKET_ADDRESS structure that stores information about the remote address. Used only with unconnected sockets.
/// </para>
/// </summary>
public IntPtr name;
/// <summary>
/// <para>Type: <c>INT</c></para>
/// <para>
/// The length, in bytes, of the SOCKET_ADDRESS structure pointed to in the <c>pAddr</c> member. Used only with unconnected sockets.
/// </para>
/// </summary>
public int namelen;
/// <summary>
/// <para>Type: <c>LPWSABUF</c></para>
/// <para>
/// An array of WSABUF structures used to receive the message data. The capability of the <c>lpBuffers</c> member to contain
/// multiple buffers enables the use of scatter/gather I/O.
/// </para>
/// </summary>
public IntPtr lpBuffers;
/// <summary>
/// <para>Type: <c>DWORD</c></para>
/// <para>The number of buffers pointed to in the <c>lpBuffers</c> member.</para>
/// </summary>
public uint dwBufferCount;
/// <summary>
/// <para>Type: <c>WSABUF</c></para>
/// <para>A structure of WSABUF type used to specify optional control data. See Remarks.</para>
/// </summary>
public WSABUF Control;
/// <summary>
/// <para>Type: <c>DWORD</c></para>
/// <para>
/// One or more control flags, specified as the logical <c>OR</c> of values. The possible values for <c>dwFlags</c> member on
/// input are defined in the Winsock2.h header file. The possible values for <c>dwFlags</c> member on output are defined in the
/// Ws2def.h header file which is automatically included by the Winsock2.h header file.
/// </para>
/// <list type="table">
/// <listheader>
/// <term>Flags on input</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>MSG_PEEK</term>
/// <term>
/// Peek 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 non-overlapped sockets.
/// </term>
/// </item>
/// </list>
/// <list type="table">
/// <listheader>
/// <term>Flag returned</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>MSG_BCAST</term>
/// <term>The datagram was received as a link-layer broadcast or with a destination IP address that is a broadcast address.</term>
/// </item>
/// <item>
/// <term>MSG_MCAST</term>
/// <term>The datagram was received with a destination IP address that is a multicast address.</term>
/// </item>
/// <item>
/// <term>MSG_TRUNC</term>
/// <term>The datagram was truncated. More data was present than the process allocated room for.</term>
/// </item>
/// <item>
/// <term>MSG_CTRUNC</term>
/// <term>The control (ancillary) data was truncated. More control data was present than the process allocated room for.</term>
/// </item>
/// </list>
/// </summary>
public MsgFlags dwFlags;
}
/// <summary>The <c>WSANETWORKEVENTS</c> structure is used to store a socket's internal information about network events.</summary>
// https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-wsanetworkevents typedef struct _WSANETWORKEVENTS { long
// lNetworkEvents; int iErrorCode[FD_MAX_EVENTS]; } WSANETWORKEVENTS, *LPWSANETWORKEVENTS;

View File

@ -1354,294 +1354,6 @@ namespace Vanara.PInvoke
public WSABUF ProviderSpecific;
}
/// <summary>The SOCKADDR_IN structure specifies a transport address and port for the AF_INET address family.</summary>
/// <remarks>
/// All of the data in the SOCKADDR_IN structure, except for the address family, must be specified in network-byte-order (big-endian).
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/ws2def/ns-ws2def-sockaddr_in typedef struct sockaddr_in { #if ... short
// sin_family; #else ADDRESS_FAMILY sin_family; #endif USHORT sin_port; IN_ADDR sin_addr; CHAR sin_zero[8]; } SOCKADDR_IN, *PSOCKADDR_IN;
[PInvokeData("ws2def.h", MSDNShortId = "96379562-403f-451c-ac7a-f0eec34bfe5e")]
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct SOCKADDR_IN
{
/// <summary>The address family for the transport address. This member should always be set to AF_INET.</summary>
public ADDRESS_FAMILY sin_family;
/// <summary>A transport protocol port number.</summary>
public ushort sin_port;
/// <summary>An IN_ADDR structure that contains an IPv4 transport address.</summary>
public IN_ADDR sin_addr;
/// <summary>Reserved for system use. A WSK application should set the contents of this array to zero.</summary>
public ulong sin_zero;
/// <summary>Initializes a new instance of the <see cref="SOCKADDR_IN"/> struct.</summary>
/// <param name="addr">An IN_ADDR structure that contains an IPv4 transport address.</param>
/// <param name="port">A transport protocol port number.</param>
public SOCKADDR_IN(IN_ADDR addr, ushort port = 0)
{
sin_family = ADDRESS_FAMILY.AF_INET;
sin_port = port;
sin_addr = addr;
sin_zero = 0;
}
/// <summary>Performs an implicit conversion from <see cref="IN_ADDR"/> to <see cref="SOCKADDR_IN"/>.</summary>
/// <param name="addr">The addr.</param>
/// <returns>The resulting <see cref="SOCKADDR_IN"/> instance from the conversion.</returns>
public static implicit operator SOCKADDR_IN(IN_ADDR addr) => new SOCKADDR_IN(addr);
/// <summary>Converts to string.</summary>
/// <returns>A <see cref="System.String"/> that represents this instance.</returns>
public override string ToString() => $"{sin_addr}:{sin_port}";
}
/// <summary>The SOCKADDR_IN6 structure specifies a transport address and port for the AF_INET6 address family.</summary>
/// <remarks>
/// <para>
/// All of the data in the SOCKADDR_IN6 structure, except for the address family, must be specified in network-byte-order (big-endian).
/// </para>
/// <para>
/// The size of the SOCKADDR_IN6 structure is too large to fit in the memory space that is provided by a SOCKADDR structure. For a
/// structure that is guaranteed to be large enough to contain a transport address for all possible address families, see SOCKADDR_STORAGEa&gt;.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/ws2ipdef/ns-ws2ipdef-sockaddr_in6_lh typedef struct sockaddr_in6 {
// ADDRESS_FAMILY sin6_family; USHORT sin6_port; ULONG sin6_flowinfo; IN6_ADDR sin6_addr; union { ULONG sin6_scope_id; SCOPE_ID
// sin6_scope_struct; }; } SOCKADDR_IN6_LH, *PSOCKADDR_IN6_LH, *LPSOCKADDR_IN6_LH;
[PInvokeData("ws2ipdef.h", MSDNShortId = "ef2955d2-5dc1-420b-a9e0-32a584059d5a")]
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct SOCKADDR_IN6
{
/// <summary>The address family for the transport address. This member should always be set to AF_INET6.</summary>
public ADDRESS_FAMILY sin6_family;
/// <summary>A transport protocol port number.</summary>
public ushort sin6_port;
/// <summary>The IPv6 flow information.</summary>
public uint sin6_flowinfo;
/// <summary>An IN6_ADDR structure that contains an IPv6 transport address.</summary>
public IN6_ADDR sin6_addr;
/// <summary>A ULONG representation of the IPv6 scope identifier that is defined in the <c>sin6_scope_struct</c> member.</summary>
public uint sin6_scope_id;
/// <summary>Initializes a new instance of the <see cref="SOCKADDR_IN6"/> struct.</summary>
/// <param name="addr">A byte array that contains an IPv6 transport address.</param>
/// <param name="scope_id">
/// A ULONG representation of the IPv6 scope identifier that is defined in the <c>sin6_scope_struct</c> member.
/// </param>
/// <param name="port">A transport protocol port number.</param>
public SOCKADDR_IN6(byte[] addr, uint scope_id, ushort port = 0) : this(new IN6_ADDR(addr), scope_id, port)
{
}
/// <summary>Initializes a new instance of the <see cref="SOCKADDR_IN6"/> struct.</summary>
/// <param name="addr">An IN6_ADDR structure that contains an IPv6 transport address.</param>
/// <param name="scope_id">
/// A ULONG representation of the IPv6 scope identifier that is defined in the <c>sin6_scope_struct</c> member.
/// </param>
/// <param name="port">A transport protocol port number.</param>
public SOCKADDR_IN6(IN6_ADDR addr, uint scope_id, ushort port = 0)
{
sin6_family = ADDRESS_FAMILY.AF_INET6;
sin6_port = port;
sin6_flowinfo = 0;
sin6_addr = addr;
sin6_scope_id = scope_id;
}
/// <summary>Performs an implicit conversion from <see cref="IN6_ADDR"/> to <see cref="SOCKADDR_IN6"/>.</summary>
/// <param name="addr">The address.</param>
/// <returns>The resulting <see cref="SOCKADDR_IN6"/> instance from the conversion.</returns>
public static implicit operator SOCKADDR_IN6(IN6_ADDR addr) => new SOCKADDR_IN6(addr, 0);
/// <inheritdoc/>
public override string ToString() => $"{sin6_addr}" + (sin6_scope_id == 0 ? "" : "%" + sin6_scope_id.ToString()) + $":{sin6_port}";
}
/// <summary>
/// The <c>SOCKADDR_IN6_PAIR</c> structure contains pointers to a pair of IP addresses that represent a source and destination
/// address pair.
/// </summary>
/// <remarks>
/// <para>The <c>SOCKADDR_IN6_PAIR</c> structure is defined on Windows Vista and later.</para>
/// <para>
/// Any IPv4 addresses in the <c>SOCKADDR_IN6_PAIR</c> structure must be represented in the IPv4-mapped IPv6 address format which
/// enables an IPv6 only application to communicate with an IPv4 node. For more information on the IPv4-mapped IPv6 address format,
/// see Dual-Stack Sockets.
/// </para>
/// <para>The <c>SOCKADDR_IN6_PAIR</c> structure is used by the CreateSortedAddressPairs function.</para>
/// <para>Note that the Ws2ipdef.h header file is automatically included in Ws2tcpip.h header file, and should never be used directly.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/ws2ipdef/ns-ws2ipdef-_sockaddr_in6_pair typedef struct _sockaddr_in6_pair {
// PSOCKADDR_IN6 SourceAddress; PSOCKADDR_IN6 DestinationAddress; } SOCKADDR_IN6_PAIR, *PSOCKADDR_IN6_PAIR;
[PInvokeData("ws2ipdef.h", MSDNShortId = "0265f8e0-8b35-4d9d-bf22-e98e9ff36a17")]
[StructLayout(LayoutKind.Sequential)]
public struct SOCKADDR_IN6_PAIR
{
/// <summary>The source address</summary>
private IntPtr _SourceAddress;
/// <summary>The destination address</summary>
private IntPtr _DestinationAddress;
/// <summary>
/// A pointer to an IP source address represented as a SOCKADDR_IN6 structure. The address family is in host byte order and the
/// IPv6 address, port, flow information, and zone ID are in network byte order.
/// </summary>
/// <value>The source address.</value>
public SOCKADDR_IN6 SourceAddress => _SourceAddress.ToStructure<SOCKADDR_IN6>();
/// <summary>
/// A pointer to an IP source address represented as a SOCKADDR_IN6 structure. The address family is in host byte order and the
/// IPv6 address, port, flow information, and zone ID are in network byte order.
/// </summary>
/// <value>The destination address.</value>
public SOCKADDR_IN6 DestinationAddress => _DestinationAddress.ToStructure<SOCKADDR_IN6>();
/// <summary>Performs an implicit conversion from <see cref="SOCKADDR_IN6_PAIR"/> to <see cref="SOCKADDR_IN6_PAIR_NATIVE"/>.</summary>
/// <param name="unmgd">The unmanaged value.</param>
/// <returns>The resulting <see cref="SOCKADDR_IN6_PAIR_NATIVE"/> instance from the conversion.</returns>
public static implicit operator SOCKADDR_IN6_PAIR_NATIVE(SOCKADDR_IN6_PAIR unmgd) =>
new SOCKADDR_IN6_PAIR_NATIVE { SourceAddress = unmgd.SourceAddress, DestinationAddress = unmgd.DestinationAddress };
/// <summary>Converts to string.</summary>
/// <returns>A <see cref="System.String"/> that represents this instance.</returns>
/// <inheritdoc/>
public override string ToString() => $"{SourceAddress} : {DestinationAddress}";
}
/// <summary>
/// The <c>SOCKADDR_IN6_PAIR</c> structure contains pointers to a pair of IP addresses that represent a source and destination
/// address pair.
/// </summary>
/// <remarks>
/// <para>The <c>SOCKADDR_IN6_PAIR</c> structure is defined on Windows Vista and later.</para>
/// <para>
/// Any IPv4 addresses in the <c>SOCKADDR_IN6_PAIR</c> structure must be represented in the IPv4-mapped IPv6 address format which
/// enables an IPv6 only application to communicate with an IPv4 node. For more information on the IPv4-mapped IPv6 address format,
/// see Dual-Stack Sockets.
/// </para>
/// <para>The <c>SOCKADDR_IN6_PAIR</c> structure is used by the CreateSortedAddressPairs function.</para>
/// <para>Note that the Ws2ipdef.h header file is automatically included in Ws2tcpip.h header file, and should never be used directly.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/ws2ipdef/ns-ws2ipdef-_sockaddr_in6_pair typedef struct _sockaddr_in6_pair {
// PSOCKADDR_IN6 SourceAddress; PSOCKADDR_IN6 DestinationAddress; } SOCKADDR_IN6_PAIR, *PSOCKADDR_IN6_PAIR;
[PInvokeData("ws2ipdef.h", MSDNShortId = "0265f8e0-8b35-4d9d-bf22-e98e9ff36a17")]
[StructLayout(LayoutKind.Sequential)]
public struct SOCKADDR_IN6_PAIR_NATIVE
{
/// <summary>
/// A pointer to an IP source address represented as a SOCKADDR_IN6 structure. The address family is in host byte order and the
/// IPv6 address, port, flow information, and zone ID are in network byte order.
/// </summary>
public SOCKADDR_IN6 SourceAddress;
/// <summary>
/// A pointer to an IP source address represented as a SOCKADDR_IN6 structure. The address family is in host byte order and the
/// IPv6 address, port, flow information, and zone ID are in network byte order.
/// </summary>
public SOCKADDR_IN6 DestinationAddress;
/// <summary>Converts to string.</summary>
/// <returns>A <see cref="System.String"/> that represents this instance.</returns>
/// <inheritdoc/>
public override string ToString() => $"{SourceAddress} : {DestinationAddress}";
}
/// <summary>The <c>SOCKADDR_INET</c> union contains an IPv4, an IPv6 address, or an address family.</summary>
/// <remarks>
/// <para>The <c>SOCKADDR_INET</c> union is defined on Windows Vista and later.</para>
/// <para>
/// The <c>SOCKADDR_INET</c> union is a convenience structure for accessing an IPv4 address, an IPv6 address, or the IP address
/// family without having to cast the sockaddr structure.
/// </para>
/// <para>The <c>SOCKADDR_INET</c> union is the data type of the <c>Prefix</c> member in the IP_ADDRESS_PREFIX structure</para>
/// <para>Note that the Ws2ipdef.h header file is automatically included in Ws2tcpip.h header file, and should never be used directly.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/ws2ipdef/ns-ws2ipdef-sockaddr_inet typedef union _SOCKADDR_INET { SOCKADDR_IN
// Ipv4; SOCKADDR_IN6 Ipv6; ADDRESS_FAMILY si_family; } SOCKADDR_INET, *PSOCKADDR_INET;
[PInvokeData("ws2ipdef.h", MSDNShortId = "7278dcb4-65c6-4aea-a474-cb7fae4d7672")]
[StructLayout(LayoutKind.Explicit)]
public struct SOCKADDR_INET : IEquatable<SOCKADDR_INET>, IEquatable<SOCKADDR_IN>, IEquatable<SOCKADDR_IN6>
{
/// <summary>
/// An IPv4 address represented as a SOCKADDR_IN structure containing the address family and the IPv4 address. The address
/// family is in host byte order and the IPv4 address is in network byte order.
/// <para>
/// On the Windows SDK released for Windows Vista and later, the organization of header files has changed and the SOCKADDR_IN
/// structure is defined in the Ws2def.h header file. Note that the Ws2def.h header file is automatically included in
/// Winsock2.h, and should never be used directly.
/// </para>
/// </summary>
[FieldOffset(0)]
public SOCKADDR_IN Ipv4;
/// <summary>
/// An IPv6 address represented as a SOCKADDR_IN6 structure containing the address family and the IPv6 address. The address
/// family is in host byte order and the IPv6 address is in network byte order.
/// <para>
/// On the Windows SDK released for Windows Vista and later, the organization of header files has changed and the SOCKADDR_IN6
/// structure is defined in the Ws2def.h header file. Note that the Ws2def.h header file is automatically included in
/// Winsock2.h, and should never be used directly.
/// </para>
/// </summary>
[FieldOffset(0)]
public SOCKADDR_IN6 Ipv6;
/// <summary>
/// The address family.
/// <para>
/// Possible values for the address family are listed in the Ws2def.h header file. Note that the values for the AF_ address
/// family and PF_ protocol family constants are identical (for example, AF_INET and PF_INET), so either constant can be
/// used.The Ws2def.h header file is automatically included in Winsock2.h, and should never be used directly.
/// </para>
/// </summary>
[FieldOffset(0)]
public ADDRESS_FAMILY si_family;
/// <summary>Specifies whether this instance is equal to the specified object.</summary>
/// <param name="other">The object to test for equality.</param>
/// <returns><see langword="true"/> if <paramref name="other"/> is equal to this instance.</returns>
public bool Equals(SOCKADDR_INET other) => (si_family == ADDRESS_FAMILY.AF_INET && Ipv4.Equals(other.Ipv4)) || (si_family == ADDRESS_FAMILY.AF_INET6 && Ipv6.Equals(other.Ipv6));
/// <summary>Specifies whether this instance is equal to the specified object.</summary>
/// <param name="other">The object to test for equality.</param>
/// <returns><see langword="true"/> if <paramref name="other"/> is equal to this instance.</returns>
public bool Equals(SOCKADDR_IN other) => si_family == ADDRESS_FAMILY.AF_INET && Ipv4.Equals(other);
/// <summary>Specifies whether this instance is equal to the specified object.</summary>
/// <param name="other">The object to test for equality.</param>
/// <returns><see langword="true"/> if <paramref name="other"/> is equal to this instance.</returns>
public bool Equals(SOCKADDR_IN6 other) => si_family == ADDRESS_FAMILY.AF_INET6 && Ipv6.Equals(other);
/// <summary>Performs an implicit conversion from <see cref="SOCKADDR_IN"/> to <see cref="SOCKADDR_INET"/>.</summary>
/// <param name="address">The address.</param>
/// <returns>The resulting <see cref="SOCKADDR_INET"/> instance from the conversion.</returns>
public static implicit operator SOCKADDR_INET(SOCKADDR_IN address) => new SOCKADDR_INET { Ipv4 = address };
/// <summary>Performs an implicit conversion from <see cref="SOCKADDR_IN6"/> to <see cref="SOCKADDR_INET"/>.</summary>
/// <param name="address">The address.</param>
/// <returns>The resulting <see cref="SOCKADDR_INET"/> instance from the conversion.</returns>
public static implicit operator SOCKADDR_INET(SOCKADDR_IN6 address) => new SOCKADDR_INET { Ipv6 = address };
/// <summary>Converts to string.</summary>
/// <returns>A <see cref="System.String"/> that represents this instance.</returns>
public override string ToString()
{
var sb = new System.Text.StringBuilder($"{si_family}");
if (si_family == ADDRESS_FAMILY.AF_INET)
sb.Append(":").Append(Ipv4);
else if (si_family == ADDRESS_FAMILY.AF_INET6)
sb.Append(":").Append(Ipv6);
return sb.ToString();
}
}
/// <summary>Provides a handle to a socket.</summary>
/// <seealso cref="Vanara.PInvoke.IHandle"/>
[PInvokeData("winsock2.h")]
@ -1711,41 +1423,6 @@ namespace Vanara.PInvoke
public override string ToString() => handle.ToString();
}
/// <summary>The <c>SOCKET_ADDRESS</c> structure stores protocol-specific address information.</summary>
/// <remarks>
/// <para>
/// The SOCKADDR structure pointed to by the <c>lpSockaddr</c> member varies depending on the protocol or address family selected.
/// For example, the <c>sockaddr_in6</c> structure is used for an IPv6 socket address while the <c>sockaddr_in4</c> structure is
/// used for an IPv4 socket address. The address family is the first member of all of the <c>SOCKADDR</c> structures. The address
/// family is used to determine which structure is used.
/// </para>
/// <para>
/// On the Microsoft Windows Software Development Kit (SDK) released for Windows Vista and later, the organization of header files
/// has changed and the <c>SOCKET_ADDRESS</c> structure is defined in the Ws2def.h header file. Note that the Ws2def.h header file
/// is automatically included in Winsock2.h, and should never be used directly.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/ws2def/ns-ws2def-socket_address typedef struct _SOCKET_ADDRESS { LPSOCKADDR
// lpSockaddr; INT iSockaddrLength; } SOCKET_ADDRESS, *PSOCKET_ADDRESS, *LPSOCKET_ADDRESS;
[PInvokeData("ws2def.h", MSDNShortId = "37fbcb96-a859-4eca-8928-8051f95407b9")]
[StructLayout(LayoutKind.Sequential)]
public struct SOCKET_ADDRESS
{
/// <summary>A pointer to a socket address represented as a SOCKADDR structure.</summary>
public IntPtr lpSockAddr;
/// <summary>The length, in bytes, of the socket address.</summary>
public int iSockaddrLength;
/// <summary>Gets the <see cref="SOCKADDR_INET"/> from this instance.</summary>
/// <returns>The <see cref="SOCKADDR_INET"/> value pointed to by this instance.</returns>
public SOCKADDR_INET GetSOCKADDR() => lpSockAddr.ToStructure<SOCKADDR_INET>();
/// <summary>Converts to string.</summary>
/// <returns>A <see cref="System.String"/> that represents this instance.</returns>
public override string ToString() => GetSOCKADDR().ToString();
}
/// <summary>
/// The <c>timeval</c> structure is used to specify a time interval. It is associated with the Berkeley Software Distribution (BSD)
/// Time.h header file.
@ -1785,20 +1462,6 @@ namespace Vanara.PInvoke
}
}
/// <summary>The <c>WSABUF</c> structure enables the creation or manipulation of a data buffer used by some Winsock functions.</summary>
// https://docs.microsoft.com/en-us/windows/desktop/api/ws2def/ns-ws2def-_wsabuf typedef struct _WSABUF { ULONG len; CHAR *buf; }
// WSABUF, *LPWSABUF;
[PInvokeData("ws2def.h", MSDNShortId = "a012c3ba-67fd-4fcf-84d1-85e9d495c29c")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct WSABUF
{
/// <summary>The length of the buffer, in bytes.</summary>
public uint len;
/// <summary>A pointer to the buffer.</summary>
public IntPtr buf;
}
/// <summary>The <c>WSADATA</c> structure contains information about the Windows Sockets implementation.</summary>
/// <remarks>
/// <para>

View File

@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
namespace Vanara.PInvoke
@ -284,5 +285,250 @@ namespace Vanara.PInvoke
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public IN_ADDR[] imsf_slist;
}
/// <summary>The SOCKADDR_IN6 structure specifies a transport address and port for the AF_INET6 address family.</summary>
/// <remarks>
/// <para>
/// All of the data in the SOCKADDR_IN6 structure, except for the address family, must be specified in network-byte-order (big-endian).
/// </para>
/// <para>
/// The size of the SOCKADDR_IN6 structure is too large to fit in the memory space that is provided by a SOCKADDR structure. For a
/// structure that is guaranteed to be large enough to contain a transport address for all possible address families, see SOCKADDR_STORAGEa&gt;.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/ws2ipdef/ns-ws2ipdef-sockaddr_in6_lh typedef struct sockaddr_in6 {
// ADDRESS_FAMILY sin6_family; USHORT sin6_port; ULONG sin6_flowinfo; IN6_ADDR sin6_addr; union { ULONG sin6_scope_id; SCOPE_ID
// sin6_scope_struct; }; } SOCKADDR_IN6_LH, *PSOCKADDR_IN6_LH, *LPSOCKADDR_IN6_LH;
[PInvokeData("ws2ipdef.h", MSDNShortId = "ef2955d2-5dc1-420b-a9e0-32a584059d5a")]
[StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct SOCKADDR_IN6
{
/// <summary>The address family for the transport address. This member should always be set to AF_INET6.</summary>
public ADDRESS_FAMILY sin6_family;
/// <summary>A transport protocol port number.</summary>
public ushort sin6_port;
/// <summary>The IPv6 flow information.</summary>
public uint sin6_flowinfo;
/// <summary>An IN6_ADDR structure that contains an IPv6 transport address.</summary>
public IN6_ADDR sin6_addr;
/// <summary>A ULONG representation of the IPv6 scope identifier that is defined in the <c>sin6_scope_struct</c> member.</summary>
public uint sin6_scope_id;
/// <summary>Initializes a new instance of the <see cref="SOCKADDR_IN6"/> struct.</summary>
/// <param name="addr">A byte array that contains an IPv6 transport address.</param>
/// <param name="scope_id">
/// A ULONG representation of the IPv6 scope identifier that is defined in the <c>sin6_scope_struct</c> member.
/// </param>
/// <param name="port">A transport protocol port number.</param>
public SOCKADDR_IN6(byte[] addr, uint scope_id, ushort port = 0) : this(new IN6_ADDR(addr), scope_id, port)
{
}
/// <summary>Initializes a new instance of the <see cref="SOCKADDR_IN6"/> struct.</summary>
/// <param name="addr">An IN6_ADDR structure that contains an IPv6 transport address.</param>
/// <param name="scope_id">
/// A ULONG representation of the IPv6 scope identifier that is defined in the <c>sin6_scope_struct</c> member.
/// </param>
/// <param name="port">A transport protocol port number.</param>
public SOCKADDR_IN6(IN6_ADDR addr, uint scope_id, ushort port = 0)
{
sin6_family = ADDRESS_FAMILY.AF_INET6;
sin6_port = port;
sin6_flowinfo = 0;
sin6_addr = addr;
sin6_scope_id = scope_id;
}
/// <summary>Performs an implicit conversion from <see cref="IN6_ADDR"/> to <see cref="SOCKADDR_IN6"/>.</summary>
/// <param name="addr">The address.</param>
/// <returns>The resulting <see cref="SOCKADDR_IN6"/> instance from the conversion.</returns>
public static implicit operator SOCKADDR_IN6(IN6_ADDR addr) => new SOCKADDR_IN6(addr, 0);
/// <inheritdoc/>
public override string ToString() => $"{sin6_addr}" + (sin6_scope_id == 0 ? "" : "%" + sin6_scope_id.ToString()) + $":{sin6_port}";
}
/// <summary>
/// The <c>SOCKADDR_IN6_PAIR</c> structure contains pointers to a pair of IP addresses that represent a source and destination
/// address pair.
/// </summary>
/// <remarks>
/// <para>The <c>SOCKADDR_IN6_PAIR</c> structure is defined on Windows Vista and later.</para>
/// <para>
/// Any IPv4 addresses in the <c>SOCKADDR_IN6_PAIR</c> structure must be represented in the IPv4-mapped IPv6 address format which
/// enables an IPv6 only application to communicate with an IPv4 node. For more information on the IPv4-mapped IPv6 address format,
/// see Dual-Stack Sockets.
/// </para>
/// <para>The <c>SOCKADDR_IN6_PAIR</c> structure is used by the CreateSortedAddressPairs function.</para>
/// <para>Note that the Ws2ipdef.h header file is automatically included in Ws2tcpip.h header file, and should never be used directly.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/ws2ipdef/ns-ws2ipdef-_sockaddr_in6_pair typedef struct _sockaddr_in6_pair {
// PSOCKADDR_IN6 SourceAddress; PSOCKADDR_IN6 DestinationAddress; } SOCKADDR_IN6_PAIR, *PSOCKADDR_IN6_PAIR;
[PInvokeData("ws2ipdef.h", MSDNShortId = "0265f8e0-8b35-4d9d-bf22-e98e9ff36a17")]
[StructLayout(LayoutKind.Sequential)]
public struct SOCKADDR_IN6_PAIR
{
/// <summary>The source address</summary>
private IntPtr _SourceAddress;
/// <summary>The destination address</summary>
private IntPtr _DestinationAddress;
/// <summary>
/// A pointer to an IP source address represented as a SOCKADDR_IN6 structure. The address family is in host byte order and the
/// IPv6 address, port, flow information, and zone ID are in network byte order.
/// </summary>
/// <value>The source address.</value>
public SOCKADDR_IN6 SourceAddress => _SourceAddress.ToStructure<SOCKADDR_IN6>();
/// <summary>
/// A pointer to an IP source address represented as a SOCKADDR_IN6 structure. The address family is in host byte order and the
/// IPv6 address, port, flow information, and zone ID are in network byte order.
/// </summary>
/// <value>The destination address.</value>
public SOCKADDR_IN6 DestinationAddress => _DestinationAddress.ToStructure<SOCKADDR_IN6>();
/// <summary>Performs an implicit conversion from <see cref="SOCKADDR_IN6_PAIR"/> to <see cref="SOCKADDR_IN6_PAIR_NATIVE"/>.</summary>
/// <param name="unmgd">The unmanaged value.</param>
/// <returns>The resulting <see cref="SOCKADDR_IN6_PAIR_NATIVE"/> instance from the conversion.</returns>
public static implicit operator SOCKADDR_IN6_PAIR_NATIVE(SOCKADDR_IN6_PAIR unmgd) =>
new SOCKADDR_IN6_PAIR_NATIVE { SourceAddress = unmgd.SourceAddress, DestinationAddress = unmgd.DestinationAddress };
/// <summary>Converts to string.</summary>
/// <returns>A <see cref="System.String"/> that represents this instance.</returns>
/// <inheritdoc/>
public override string ToString() => $"{SourceAddress} : {DestinationAddress}";
}
/// <summary>
/// The <c>SOCKADDR_IN6_PAIR</c> structure contains pointers to a pair of IP addresses that represent a source and destination
/// address pair.
/// </summary>
/// <remarks>
/// <para>The <c>SOCKADDR_IN6_PAIR</c> structure is defined on Windows Vista and later.</para>
/// <para>
/// Any IPv4 addresses in the <c>SOCKADDR_IN6_PAIR</c> structure must be represented in the IPv4-mapped IPv6 address format which
/// enables an IPv6 only application to communicate with an IPv4 node. For more information on the IPv4-mapped IPv6 address format,
/// see Dual-Stack Sockets.
/// </para>
/// <para>The <c>SOCKADDR_IN6_PAIR</c> structure is used by the CreateSortedAddressPairs function.</para>
/// <para>Note that the Ws2ipdef.h header file is automatically included in Ws2tcpip.h header file, and should never be used directly.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/desktop/api/ws2ipdef/ns-ws2ipdef-_sockaddr_in6_pair typedef struct _sockaddr_in6_pair {
// PSOCKADDR_IN6 SourceAddress; PSOCKADDR_IN6 DestinationAddress; } SOCKADDR_IN6_PAIR, *PSOCKADDR_IN6_PAIR;
[PInvokeData("ws2ipdef.h", MSDNShortId = "0265f8e0-8b35-4d9d-bf22-e98e9ff36a17")]
[StructLayout(LayoutKind.Sequential)]
public struct SOCKADDR_IN6_PAIR_NATIVE
{
/// <summary>
/// A pointer to an IP source address represented as a SOCKADDR_IN6 structure. The address family is in host byte order and the
/// IPv6 address, port, flow information, and zone ID are in network byte order.
/// </summary>
public SOCKADDR_IN6 SourceAddress;
/// <summary>
/// A pointer to an IP source address represented as a SOCKADDR_IN6 structure. The address family is in host byte order and the
/// IPv6 address, port, flow information, and zone ID are in network byte order.
/// </summary>
public SOCKADDR_IN6 DestinationAddress;
/// <summary>Converts to string.</summary>
/// <returns>A <see cref="System.String"/> that represents this instance.</returns>
/// <inheritdoc/>
public override string ToString() => $"{SourceAddress} : {DestinationAddress}";
}
/// <summary>The <c>SOCKADDR_INET</c> union contains an IPv4, an IPv6 address, or an address family.</summary>
/// <remarks>
/// <para>The <c>SOCKADDR_INET</c> union is defined on Windows Vista and later.</para>
/// <para>
/// The <c>SOCKADDR_INET</c> union is a convenience structure for accessing an IPv4 address, an IPv6 address, or the IP address
/// family without having to cast the sockaddr structure.
/// </para>
/// <para>The <c>SOCKADDR_INET</c> union is the data type of the <c>Prefix</c> member in the IP_ADDRESS_PREFIX structure</para>
/// <para>Note that the Ws2ipdef.h header file is automatically included in Ws2tcpip.h header file, and should never be used directly.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/ws2ipdef/ns-ws2ipdef-sockaddr_inet typedef union _SOCKADDR_INET { SOCKADDR_IN
// Ipv4; SOCKADDR_IN6 Ipv6; ADDRESS_FAMILY si_family; } SOCKADDR_INET, *PSOCKADDR_INET;
[PInvokeData("ws2ipdef.h", MSDNShortId = "7278dcb4-65c6-4aea-a474-cb7fae4d7672")]
[StructLayout(LayoutKind.Explicit)]
public struct SOCKADDR_INET : IEquatable<SOCKADDR_INET>, IEquatable<SOCKADDR_IN>, IEquatable<SOCKADDR_IN6>
{
/// <summary>
/// An IPv4 address represented as a SOCKADDR_IN structure containing the address family and the IPv4 address. The address
/// family is in host byte order and the IPv4 address is in network byte order.
/// <para>
/// On the Windows SDK released for Windows Vista and later, the organization of header files has changed and the SOCKADDR_IN
/// structure is defined in the Ws2def.h header file. Note that the Ws2def.h header file is automatically included in
/// Winsock2.h, and should never be used directly.
/// </para>
/// </summary>
[FieldOffset(0)]
public SOCKADDR_IN Ipv4;
/// <summary>
/// An IPv6 address represented as a SOCKADDR_IN6 structure containing the address family and the IPv6 address. The address
/// family is in host byte order and the IPv6 address is in network byte order.
/// <para>
/// On the Windows SDK released for Windows Vista and later, the organization of header files has changed and the SOCKADDR_IN6
/// structure is defined in the Ws2def.h header file. Note that the Ws2def.h header file is automatically included in
/// Winsock2.h, and should never be used directly.
/// </para>
/// </summary>
[FieldOffset(0)]
public SOCKADDR_IN6 Ipv6;
/// <summary>
/// The address family.
/// <para>
/// Possible values for the address family are listed in the Ws2def.h header file. Note that the values for the AF_ address
/// family and PF_ protocol family constants are identical (for example, AF_INET and PF_INET), so either constant can be
/// used.The Ws2def.h header file is automatically included in Winsock2.h, and should never be used directly.
/// </para>
/// </summary>
[FieldOffset(0)]
public ADDRESS_FAMILY si_family;
/// <summary>Specifies whether this instance is equal to the specified object.</summary>
/// <param name="other">The object to test for equality.</param>
/// <returns><see langword="true"/> if <paramref name="other"/> is equal to this instance.</returns>
public bool Equals(SOCKADDR_INET other) => (si_family == ADDRESS_FAMILY.AF_INET && Ipv4.Equals(other.Ipv4)) || (si_family == ADDRESS_FAMILY.AF_INET6 && Ipv6.Equals(other.Ipv6));
/// <summary>Specifies whether this instance is equal to the specified object.</summary>
/// <param name="other">The object to test for equality.</param>
/// <returns><see langword="true"/> if <paramref name="other"/> is equal to this instance.</returns>
public bool Equals(SOCKADDR_IN other) => si_family == ADDRESS_FAMILY.AF_INET && Ipv4.Equals(other);
/// <summary>Specifies whether this instance is equal to the specified object.</summary>
/// <param name="other">The object to test for equality.</param>
/// <returns><see langword="true"/> if <paramref name="other"/> is equal to this instance.</returns>
public bool Equals(SOCKADDR_IN6 other) => si_family == ADDRESS_FAMILY.AF_INET6 && Ipv6.Equals(other);
/// <summary>Performs an implicit conversion from <see cref="SOCKADDR_IN"/> to <see cref="SOCKADDR_INET"/>.</summary>
/// <param name="address">The address.</param>
/// <returns>The resulting <see cref="SOCKADDR_INET"/> instance from the conversion.</returns>
public static implicit operator SOCKADDR_INET(SOCKADDR_IN address) => new SOCKADDR_INET { Ipv4 = address };
/// <summary>Performs an implicit conversion from <see cref="SOCKADDR_IN6"/> to <see cref="SOCKADDR_INET"/>.</summary>
/// <param name="address">The address.</param>
/// <returns>The resulting <see cref="SOCKADDR_INET"/> instance from the conversion.</returns>
public static implicit operator SOCKADDR_INET(SOCKADDR_IN6 address) => new SOCKADDR_INET { Ipv6 = address };
/// <summary>Converts to string.</summary>
/// <returns>A <see cref="System.String"/> that represents this instance.</returns>
public override string ToString()
{
var sb = new System.Text.StringBuilder($"{si_family}");
if (si_family == ADDRESS_FAMILY.AF_INET)
sb.Append(":").Append(Ipv4);
else if (si_family == ADDRESS_FAMILY.AF_INET6)
sb.Append(":").Append(Ipv6);
return sb.ToString();
}
}
}
}