using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
namespace Vanara.PInvoke
{
public static partial class Ws2_32
{
///
public const uint IOC_IN = 0x80000000;
///
public const uint IOC_INOUT = IOC_IN | IOC_OUT;
///
public const uint IOC_OUT = 0x40000000;
///
public const uint IOC_VOID = 0x20000000;
///
public const uint IOCPARM_MASK = 0x7f;
///
/// It is used to return information about each interface on the local machine. Nothing is required on input, but on output, an array of INTERFACE_INFO structures is returned.
///
public static readonly uint SIO_GET_INTERFACE_LIST = _IOR('t', 127, typeof(uint));
///
/// This ioctl is the same as SIO_GET_INTERFACE_LIST except the structure returned contains embedded SOCKET_ADDRESS structure to describe each local interface, as opposed to SOCKADDR_GEN structure. This removes the dependency the size of the socket address structure.
///
public static readonly uint SIO_GET_INTERFACE_LIST_EX = _IOR('t', 126, typeof(uint));
///
/// This ioctl retrieves the multicast filter set on a given socket. The multicast state is set with the SIO_SET_MULTICAST_FILTER ioctl. This ioctl requires an IGMPv3-enabled network and is supported in only Windows XP.
///
public static readonly uint SIO_GET_MULTICAST_FILTER = _IOW('t', 124 | IOC_IN, typeof(uint));
///
/// This ioctl sets the multicast state. The input parameter is a struct ip_msfilter.
///
public static readonly uint SIO_SET_MULTICAST_FILTER = _IOW('t', 125, typeof(uint));
///
/// This ioctl retrieves the multicast filter set on a given socket. The multicast state is set with the SIO_SET_MULTICAST_FILTER ioctl. This ioctl requires an IGMPv3-enabled network and is supported in only Windows XP.
///
public static readonly uint SIOCGIPMSFILTER = SIO_GET_MULTICAST_FILTER;
///
/// Enables an application to retrieve a list of the IPv4 or IPv6 source addresses that comprise the source filter along with the current mode on a given interface index and a multicast group for a socket. The source filter may either include or exclude the set of source address, depending on the filter mode (MCAST_INCLUDE or MCAST_EXCLUDE), which is defined in the GROUP_FILTER structure.
///
public static readonly uint SIOCGMSFILTER = _IOW('t', 127 | IOC_IN, typeof(uint));
///
/// This ioctl sets the multicast state. The input parameter is a struct ip_msfilter.
///
public static readonly uint SIOCSIPMSFILTER = SIO_SET_MULTICAST_FILTER;
///
/// Enables an application to specify or modify a list of IPv4 or IPv6 source addresses on a given interface index and to specify or modify a multicast group for a socket. The source filter can include or exclude the set of source address, depending on the filter mode (MCAST_INCLUDE or MCAST_EXCLUDE), which is defined in the GROUP_FILTER structure of the BPXYIOCC macro. The application can join multiple source multicast groups on a single socket; it also can join the same group on multiple interfaces on the same socket. However, there is a maximum limit of 20 groups per single UDP socket and there is a maximum limit of 256 groups per single RAW socket.
///
public static readonly uint SIOCSMSFILTER = _IOW('t', 126, typeof(uint));
/// The MULTICAST_MODE_TYPE enumeration specifies the filter mode for multicast group addresses.
///
/// This enumeration is supported on Windows Vistaand later.
///
/// The MULTICAST_MODE_TYPE enumeration is used in the gf_fmode member of the GROUP_SOURCE_REQ structure to determine
/// if a list of IP addresses should included or excluded. The values from this enumeration can also be used in the
/// imsf_fmode member of the ip_msfilter structure.
///
///
/// The MULTICAST_MODE_TYPE enumeration is defined in the Ws2ipdef.h header file which is automatically included in the
/// Ws2tcpip.h header file. The Ws2ipdef.h header files should never be used directly.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2ipdef/ne-ws2ipdef-multicast_mode_type typedef enum { MCAST_INCLUDE,
// MCAST_EXCLUDE } MULTICAST_MODE_TYPE;
[PInvokeData("ws2ipdef.h", MSDNShortId = "7ca9cb9b-618a-4e73-9e2a-18e55e5c00c0")]
public enum MULTICAST_MODE_TYPE
{
/// The filter contains a list of IP addresses to include.
MCAST_INCLUDE,
/// The filter contains a list of IP addresses to exclude.
MCAST_EXCLUDE,
}
///
/// Used for an ioctl that reads data from the device driver. The driver will be allowed to return sizeof(data_type) bytes to the user.
///
/// The type.
/// The value.
/// The type from which a size is extracted.
/// IOCtrl value.
public static uint _IOR(char x, uint y, Type t) => IOC_OUT | (((uint)Marshal.SizeOf(t) & IOCPARM_MASK) << 16) | ((uint)x) << 8 | (y);
/// Used for an ioctl that writes data to the device driver.
/// The type.
/// The value.
/// The type from which a size is extracted.
/// IOCtrl value.
public static uint _IOW(char x, uint y, Type t) => IOC_IN | (((uint)Marshal.SizeOf(t) & IOCPARM_MASK) << 16) | ((uint)x) << 8 | (y);
/// Gets the size, in bytes, of an GROUP_FILTER with a number of SOCKADDR_STORAGE items.
/// The number of SOCKADDR_STORAGE sources.
/// Size, in bytes.
[PInvokeData("ws2ipdef.h")]
public static int GROUP_FILTER_SIZE(int numsrc) => Marshal.SizeOf(typeof(GROUP_FILTER)) - Marshal.SizeOf(typeof(SOCKADDR_STORAGE)) + numsrc * Marshal.SizeOf(typeof(SOCKADDR_STORAGE));
/// Gets the size, in bytes, of an IP_MSFILTER with a number of IN_ADDR items.
/// The number of IN_ADDR sources.
/// Size, in bytes.
[PInvokeData("ws2ipdef.h")]
public static int IP_MSFILTER_SIZE(int NumSources) => Marshal.SizeOf(typeof(IP_MSFILTER)) - Marshal.SizeOf(typeof(IN_ADDR)) + NumSources * Marshal.SizeOf(typeof(IN_ADDR));
/// The GROUP_FILTER structure provides multicast filtering parameters for multicast IPv6 or IPv4 addresses.
///
///
/// The GROUP_FILTER structure is used with either IPv6 or IPv4 multicast addresses. The GROUP_FILTER structure is
/// passed as an argument for the SIOCGMSFILTER and SIOCSMSFILTER IOCTLs.
///
///
/// The GROUP_FILTER structure and related structures used for multicast programming are based on IETF recommendations in
/// sections 5 and 8.2 of RFC 3768. For more information, see http://www.ietf.org/rfc/rfc3678.txt.
///
///
/// On Windows Vista and later, a set of socket options are available for multicast programming that support IPv6 and IPv4
/// addresses. These socket options are IP agnostic and can be used on both IPv6 and IPv4. These IP agnostic options use the
/// GROUP_REQ and the GROUP_SOURCE_REQ structures and are the preferred socket options for multicast programming on Windows Vista
/// and later.
///
/// The GetAdaptersAddresses function can be used to obtain interface index information required for the gf_interface member.
///
/// The GROUP_FILTER structure and the Ioctls that use this structure are only valid on datagram and raw sockets (the socket
/// type must be SOCK_DGRAM or SOCK_RAW).
///
///
/// The GROUP_FILTER structure is defined in the Ws2ipdef.h header file which is automatically included in the Ws2tcpip.h
/// header file. The Ws2ipdef.h header files should never be used directly.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2ipdef/ns-ws2ipdef-group_filter typedef struct group_filter { ULONG
// gf_interface; SOCKADDR_STORAGE gf_group; MULTICAST_MODE_TYPE gf_fmode; ULONG gf_numsrc; SOCKADDR_STORAGE gf_slist[1]; }
// GROUP_FILTER, *PGROUP_FILTER;
[PInvokeData("ws2ipdef.h", MSDNShortId = "09aa1f67-c858-4bef-9a98-ce25ebcc1d4e")]
[VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), "gf_numsrc")]
[StructLayout(LayoutKind.Sequential)]
public struct GROUP_FILTER
{
/// The interface index of the local interface for the multicast group to filter.
public uint gf_interface;
/// The multicast address group that should be filtered. This may be either an IPv6 or IPv4 multicast address.
public SOCKADDR_STORAGE gf_group;
///
/// The multicast filter mode.
///
/// This member can be one of the values from the MULTICAST_MODE_TYPE enumeration type defined in the Ws2ipdef.h header file.
/// This member determines if the list of IP addresses in the gf_numsrc member should be included or excluded.
///
///
///
/// Value
/// Meaning
///
/// -
/// MCAST_INCLUDE
/// The filter contains a list of IP addresses to include.
///
/// -
/// MCAST_EXCLUDE
/// The filter contains a list of IP addresses to exclude.
///
///
///
public MULTICAST_MODE_TYPE gf_fmode;
/// The number of multicast filter source address entries in the gf_slist member.
public uint gf_numsrc;
///
/// An array of SOCKADDR_STORAGE structures specifying the multicast source addresses to include or exclude. These IP addresses
/// may be either IPv6 or IPv4 addresses, but they must be the same address family (IPv6 or IPv4) as the address specified in
/// the gf_group member..
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public SOCKADDR_STORAGE[] gf_slist;
}
/// The ip_msfilter structure provides multicast filtering parameters for IPv4 addresses.
///
///
/// The ip_msfilter structure is used with IPv4 addresses. The ip_msfilter structure is passed as an argument for the
/// SIO_GET_MULTICAST_FILTER and SIO_SET_MULTICAST_FILTER IOCTLs.
///
///
/// The ip_msfilter structure and related structures used for IPv4 multicast programming are based on IETF recommendations in
/// sections 4 and 8.1 of RFC 3768. For more information, see http://www.ietf.org/rfc/rfc3678.txt.
///
///
/// On Windows Vista and later, a set of socket options are available for multicast programming that support IPv6 and IPv4
/// addresses. These socket options are IP agnostic and can be used on both IPv6 and IPv4. These IP agnostic options use the
/// GROUP_REQ and the GROUP_SOURCE_REQ structures and the SIOCSMSFILTER and SIOCGMSFILTER IOCTLs. These are the
/// preferred socket options and IOCTLs for multicast programming on Windows Vista and later.
///
///
/// The imsf_interface member can be an interface index. Any IPv4 address in the 0.x.x.x block (first octet of 0) except for
/// the IPv4 address of 0.0.0.0 is treated as an interface index. An interface index is a 24-bit number. The 0.0.0.0/8 IPv4 address
/// block is not used (this range is reserved). The GetAdaptersAddresses function can be used to obtain interface index information
/// to use for the imsf_interface member.
///
///
/// It is recommended that a local IPv4 address or interface index always be specified in the imsf_interface member of the
/// ip_msfilter structure, rather than use the default interface. This is particularly important on computers with multiple
/// network interfaces and multiple public IPv4 addresses.
///
///
/// The default interface used for IPv4 multicast is determined by the networking stack in Windows. An application can determine the
/// default interface used for IPv4 multicast using the GetIpForwardTable function to retrieve the IPv4 routing table. The network
/// interface with the lowest value for the routing metric for a destination IP address of 224.0.0.0 is the default interface for
/// IPv4 multicast. The routing table can also be displayed from the command prompt with the following command:
///
/// route print
///
/// The IP_MULTICAST_IF socket option can be used to set the default interface to send IPv4 multicast packets. This socket option
/// does not change the default interface used to receive IPv4 multicast packets.
///
///
/// A typical IPv4 multicast application would use the IP_ADD_MEMBERSHIP socket option with the ip_mreq structure or the
/// IP_ADD_SOURCE_MEMBERSHIP socket option with the ip_mreq_source structure to join a multicast group and listen for
/// multicast packets on a specific interface. The IP_MULTICAST_IF socket option would be used to set the interface to send
/// IPv4 multicast packets to the multicast group. The most common scenario would be a multicast application that listens and sends
/// on the same interface for a multicast group. Multiple sockets might be used by a multicast application with one socket for
/// listening and one or more sockets for sending.
///
///
/// On the Microsoft Windows Software Development Kit (SDK) released for Windows Vista and later, the organization of header files
/// has changed and the ip_msfilter structure is defined in the Ws2ipdef.h header file which is automatically included in the
/// Ws2tcpip.h header file. The Ws2ipdef.h header files should never be used directly.
///
///
/// Note The IP_MSFILTER and PIP_MSFILTER derived structures are only defined on the Windows SDK released with
/// Windows Vista and later. The ip_msfilter structure should be used on earlier versions of the Windows SDK.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2ipdef/ns-ws2ipdef-ip_msfilter typedef struct ip_msfilter { IN_ADDR
// imsf_multiaddr; IN_ADDR imsf_interface; MULTICAST_MODE_TYPE imsf_fmode; ULONG imsf_numsrc; IN_ADDR imsf_slist[1]; } IP_MSFILTER, *PIP_MSFILTER;
[PInvokeData("ws2ipdef.h", MSDNShortId = "8d9d515e-9369-4d71-9614-6cbeb5557a5d")]
[VanaraMarshaler(typeof(SafeAnysizeStructMarshaler), "imsf_numsrc")]
[StructLayout(LayoutKind.Sequential)]
public struct IP_MSFILTER
{
/// The IPv4 address of the multicast group.
public IN_ADDR imsf_multiaddr;
///
///
/// The local IPv4 address of the interface or the interface index on which the multicast group should be filtered. This value
/// is in network byte order. If this member specifies an IPv4 address of 0.0.0.0, the default IPv4 multicast interface is used.
///
/// To use an interface index of 1 would be the same as an IP address of 0.0.0.1.
///
public IN_ADDR imsf_interface;
///
///
/// The multicast filter mode to be used. This parameter can be either MCAST_INCLUDE (value of 0) to include particular
/// multicast sources, or MCAST_EXCLUDE (value of 1) to exclude traffic from specified sources.
///
/// On Windows Server 2003 and Windows XP, these values are defined in the Ws2tcpip.h header file.
///
/// On Windows Vistaand later, these values are defined as enumeration values in the MULTICAST_MODE_TYPE enumeration defined in
/// the Ws2ipdef.h header file.
///
///
public MULTICAST_MODE_TYPE imsf_fmode;
/// The number of sources in the imsf_slist member.
public uint imsf_numsrc;
/// An array of in_addr structures that specify the IPv4 multicast source addresses to include or exclude.
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
public IN_ADDR[] imsf_slist;
}
/// The SOCKADDR_IN6 structure specifies a transport address and port for the AF_INET6 address family.
///
///
/// All of the data in the SOCKADDR_IN6 structure, except for the address family, must be specified in network-byte-order (big-endian).
///
///
/// 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>.
///
///
// 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
{
/// The address family for the transport address. This member should always be set to AF_INET6.
public ADDRESS_FAMILY sin6_family;
/// A transport protocol port number.
public ushort sin6_port;
/// The IPv6 flow information.
public uint sin6_flowinfo;
/// An IN6_ADDR structure that contains an IPv6 transport address.
public IN6_ADDR sin6_addr;
/// A ULONG representation of the IPv6 scope identifier that is defined in the sin6_scope_struct member.
public uint sin6_scope_id;
/// Initializes a new instance of the struct.
/// A byte array that contains an IPv6 transport address.
///
/// A ULONG representation of the IPv6 scope identifier that is defined in the sin6_scope_struct member.
///
/// A transport protocol port number.
public SOCKADDR_IN6(byte[] addr, uint scope_id, ushort port = 0) : this(new IN6_ADDR(addr), scope_id, port)
{
}
/// Initializes a new instance of the struct.
/// An IN6_ADDR structure that contains an IPv6 transport address.
///
/// A ULONG representation of the IPv6 scope identifier that is defined in the sin6_scope_struct member.
///
/// A transport protocol port number.
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;
}
/// Performs an implicit conversion from to .
/// The address.
/// The resulting instance from the conversion.
public static implicit operator SOCKADDR_IN6(IN6_ADDR addr) => new SOCKADDR_IN6(addr, 0);
///
public override string ToString() => $"{sin6_addr}" + (sin6_scope_id == 0 ? "" : "%" + sin6_scope_id.ToString()) + $":{sin6_port}";
}
///
/// The SOCKADDR_IN6_PAIR structure contains pointers to a pair of IP addresses that represent a source and destination
/// address pair.
///
///
/// The SOCKADDR_IN6_PAIR structure is defined on Windows Vista and later.
///
/// Any IPv4 addresses in the SOCKADDR_IN6_PAIR 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.
///
/// The SOCKADDR_IN6_PAIR structure is used by the CreateSortedAddressPairs function.
/// Note that the Ws2ipdef.h header file is automatically included in Ws2tcpip.h header file, and should never be used directly.
///
// 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
{
/// The source address
private IntPtr _SourceAddress;
/// The destination address
private IntPtr _DestinationAddress;
///
/// 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.
///
/// The source address.
public SOCKADDR_IN6 SourceAddress => _SourceAddress.ToStructure();
///
/// 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.
///
/// The destination address.
public SOCKADDR_IN6 DestinationAddress => _DestinationAddress.ToStructure();
/// Performs an implicit conversion from to .
/// The unmanaged value.
/// The resulting instance from the conversion.
public static implicit operator SOCKADDR_IN6_PAIR_NATIVE(SOCKADDR_IN6_PAIR unmgd) =>
new SOCKADDR_IN6_PAIR_NATIVE { SourceAddress = unmgd.SourceAddress, DestinationAddress = unmgd.DestinationAddress };
/// Converts to string.
/// A that represents this instance.
///
public override string ToString() => $"{SourceAddress} : {DestinationAddress}";
}
///
/// The SOCKADDR_IN6_PAIR structure contains pointers to a pair of IP addresses that represent a source and destination
/// address pair.
///
///
/// The SOCKADDR_IN6_PAIR structure is defined on Windows Vista and later.
///
/// Any IPv4 addresses in the SOCKADDR_IN6_PAIR 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.
///
/// The SOCKADDR_IN6_PAIR structure is used by the CreateSortedAddressPairs function.
/// Note that the Ws2ipdef.h header file is automatically included in Ws2tcpip.h header file, and should never be used directly.
///
// 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
{
///
/// 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.
///
public SOCKADDR_IN6 SourceAddress;
///
/// 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.
///
public SOCKADDR_IN6 DestinationAddress;
/// Converts to string.
/// A that represents this instance.
///
public override string ToString() => $"{SourceAddress} : {DestinationAddress}";
}
/// The SOCKADDR_INET union contains an IPv4, an IPv6 address, or an address family.
///
/// The SOCKADDR_INET union is defined on Windows Vista and later.
///
/// The SOCKADDR_INET 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.
///
/// The SOCKADDR_INET union is the data type of the Prefix member in the IP_ADDRESS_PREFIX structure
/// Note that the Ws2ipdef.h header file is automatically included in Ws2tcpip.h header file, and should never be used directly.
///
// 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, IEquatable, IEquatable
{
///
/// 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.
///
/// 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.
///
///
[FieldOffset(0)]
public SOCKADDR_IN Ipv4;
///
/// 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.
///
/// 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.
///
///
[FieldOffset(0)]
public SOCKADDR_IN6 Ipv6;
///
/// The address family.
///
/// 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.
///
///
[FieldOffset(0)]
public ADDRESS_FAMILY si_family;
/// Specifies whether this instance is equal to the specified object.
/// The object to test for equality.
/// if is equal to this instance.
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));
/// Specifies whether this instance is equal to the specified object.
/// The object to test for equality.
/// if is equal to this instance.
public bool Equals(SOCKADDR_IN other) => si_family == ADDRESS_FAMILY.AF_INET && Ipv4.Equals(other);
/// Specifies whether this instance is equal to the specified object.
/// The object to test for equality.
/// if is equal to this instance.
public bool Equals(SOCKADDR_IN6 other) => si_family == ADDRESS_FAMILY.AF_INET6 && Ipv6.Equals(other);
/// Performs an implicit conversion from to .
/// The address.
/// The resulting instance from the conversion.
public static implicit operator SOCKADDR_INET(SOCKADDR_IN address) => new SOCKADDR_INET { Ipv4 = address };
/// Performs an implicit conversion from to .
/// The address.
/// The resulting instance from the conversion.
public static implicit operator SOCKADDR_INET(SOCKADDR_IN6 address) => new SOCKADDR_INET { Ipv6 = address };
/// Converts to string.
/// A that represents this instance.
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();
}
}
}
}