using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Vanara.InteropServices;
using static Vanara.PInvoke.Ws2_32;
namespace Vanara.PInvoke
{
public static partial class IpHlpApi
{
///
///
/// The IP_ADAPTER_INDEX_MAP structure stores the interface index associated with a network adapter with IPv4 enabled together
/// with the name of the network adapter.
///
///
///
/// The IP_ADAPTER_INDEX_MAP structure is specific to network adapters with IPv4 enabled.
///
/// An adapter index may change when the adapter is disabled and then enabled, or under other circumstances, and should not be
/// considered persistent.
///
///
/// On Windows Vista and later, the Name member of the IP_ADAPTER_INDEX_MAP structure may be a Unicode string of the
/// GUID for the network interface (the string begins with the '{' character).
///
///
/// This structure is defined in the Ipexport.h header file which is automatically included in the Iphlpapi.h header file. The
/// Ipexport.h header file should never be used directly.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/ipexport/ns-ipexport-_ip_adapter_index_map typedef struct
// _IP_ADAPTER_INDEX_MAP { ULONG Index; WCHAR Name[MAX_ADAPTER_NAME]; } IP_ADAPTER_INDEX_MAP, *PIP_ADAPTER_INDEX_MAP;
[PInvokeData("ipexport.h", MSDNShortId = "83d95ef3-13a4-4124-84cd-3016e9fb4446")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct IP_ADAPTER_INDEX_MAP
{
///
/// The interface index associated with the network adapter.
///
public uint Index;
///
/// A pointer to a Unicode string that contains the name of the adapter.
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_ADAPTER_NAME)]
public string Name;
///
public override string ToString() => Name;
}
/// The IP_OPTION_INFORMATION structure describes the options to be included in the header of an IP packet.
///
///
/// The IP_OPTION_INFORMATION structure is used to describe the options to be included in the header of an IP packet. On a
/// 64-bit platform, the IP_OPTION_INFORMATION32 structure should be used.
///
/// The values in the TTL, TOS and Flags members are carried in specific fields in the IP header.
/// The bytes in the OptionsData member are carried in the options area that follows the standard IP header.
///
/// With the exception of source route options for IPv4, the options data must be in the format to be transmitted on the wire as
/// specified in RFC 791. An IPv4 source route option should contain the full route, first hop through final destination, in the
/// route data. The first hop is pulled out of the data and the option is reformatted accordingly. Otherwise, the route option should
/// be formatted as specified in RFC 791.
///
/// For use with IPv6, the options data must be in the format to be transmitted on the wire as specified in RFC 2460.
///
/// The IP_OPTION_INFORMATION structure is a member of the ICMP_ECHO_REPLY structure used by the IcmpSendEcho, IcmpSendEcho2,
/// and Icmp6SendEcho2 functions.
///
///
/// This structure is defined in the Ipexport.h header file which is automatically included in the Iphlpapi.h header file. The
/// Ipexport.h header file should never be used directly.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/ipexport/ns-ipexport-ip_option_information typedef struct
// ip_option_information { UCHAR Ttl; UCHAR Tos; UCHAR Flags; UCHAR OptionsSize; PUCHAR OptionsData; } IP_OPTION_INFORMATION, *PIP_OPTION_INFORMATION;
[PInvokeData("ipexport.h", MSDNShortId = "4341d0a4-65d8-4677-b208-2cde5ff36f14")]
[StructLayout(LayoutKind.Sequential)]
public struct IP_OPTION_INFORMATION
{
///
/// Type: UCHAR
/// The Time to Live field in an IPv4 packet header. This is the Hop Limit field in an IPv6 header.
///
public byte Ttl;
///
/// Type: UCHAR
/// The type of service field in an IPv4 header. This member is currently silently ignored.
///
public byte Tos;
///
/// Type: UCHAR
///
/// The Flags field. In IPv4, this is the Flags field in the IPv4 header. In IPv6, this field is represented by options headers.
///
///
/// For IPv4, the possible values for the Flags member are a combination of the following values defined in the Ipexport.h
/// header file:
///
///
///
/// Value
/// Meaning
///
/// -
/// IP_FLAG_REVERSE 0x01
///
/// This value causes the IP packet to add in an IP routing header with the source. This value is only applicable on Windows
/// Vistaand later.
///
///
/// -
/// IP_FLAG_DF 0x02
/// This value indicates that the packet should not be fragmented.
///
///
///
public byte Flags;
///
/// Type: UCHAR
/// The size, in bytes, of IP options data.
///
public byte OptionsSize;
///
/// Type: PUCHAR
/// A pointer to options data.
///
public IntPtr OptionsData;
}
///
/// The IP_ADAPTER_ORDER_MAP structure stores an array of information about adapters and their relative priority on the local computer.
///
///
///
/// This structure is returned by the GetAdapterOrderMap function, and is used as a tie breaker for otherwise equal interfaces during
/// network operations. The GetAdapterOrderMap function should not be called directly; use the GetAdaptersInfo function instead.
///
///
/// The IP_ADAPTER_ORDER_MAP structure contains at least one AdapterOrder member even if the NumAdapters member
/// of the IP_ADAPTER_ORDER_MAP structure indicates no network adapters. When the NumAdapters member of the
/// IP_ADAPTER_ORDER_MAP structure is zero, the value of the single AdapterOrder member is undefined.
///
///
/// This structure is defined in the Ipexport.h header file which is automatically included in the Iphlpapi.h header file. The
/// Ipexport.h header file should never be used directly.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/ipexport/ns-ipexport-_ip_adapter_order_map typedef struct
// _IP_ADAPTER_ORDER_MAP { ULONG NumAdapters; ULONG AdapterOrder[1]; } IP_ADAPTER_ORDER_MAP, *PIP_ADAPTER_ORDER_MAP;
[PInvokeData("ipexport.h", MSDNShortId = "0bbd008e-67d4-4557-bff7-f0404a8878ff")]
[CorrespondingType(typeof(uint))]
[DefaultProperty(nameof(AdapterOrder))]
public class IP_ADAPTER_ORDER_MAP : SafeElementArray
{
private IP_ADAPTER_ORDER_MAP() : base() { }
/// Initializes a new instance of the class.
/// Size of the byte.
public IP_ADAPTER_ORDER_MAP(uint byteSize) : base((int)byteSize, 0)
{
}
///
/// An array of adapter indexes on the local computer, provided in the order specified in the Adapters and Bindings dialog
/// box for Network Connections.
///
/// The .
///
public uint[] AdapterOrder { get => Elements; set => Elements = value; }
/// The number of network adapters in the AdapterOrder member.
public uint NumAdapters => Count;
}
///
///
/// The IP_INTERFACE_INFO structure contains a list of the network interface adapters with IPv4 enabled on the local system.
///
///
///
///
/// The IP_INTERFACE_INFO structure is specific to network adapters with IPv4 enabled. The IP_INTERFACE_INFO structure
/// contains the number of network adapters with IPv4 enabled on the local system and an array of IP_ADAPTER_INDEX_MAP structures
/// with information on each network adapter with IPv4 enabled. The IP_INTERFACE_INFO structure contains at least one
/// IP_ADAPTER_INDEX_MAP structure even if the NumAdapters member of the IP_INTERFACE_INFO structure indicates
/// that no network adapters with IPv4 are enabled. When the NumAdapters member of the IP_INTERFACE_INFO structure is
/// zero, the value of the members of the single IP_ADAPTER_INDEX_MAP structure returned in the IP_INTERFACE_INFO
/// structure is undefined.
///
/// The IP_INTERFACE_INFO structure can't be used to return information about the loopback interface.
///
/// On Windows Vista and later, the Name member of the IP_ADAPTER_INDEX_MAP structure in the IP_INTERFACE_INFO
/// structure may be a Unicode string of the GUID for the network interface (the string begins with the '{' character).
///
///
/// This structure is defined in the Ipexport.h header file which is automatically included in the Iphlpapi.h header file. The
/// Ipexport.h header file should never be used directly.
///
/// Examples
///
/// The following example retrieves the list of network adapters with IPv4 enabled on the local system and prints various properties
/// of the first adapter.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/ipexport/ns-ipexport-_ip_interface_info typedef struct _IP_INTERFACE_INFO {
// LONG NumAdapters; IP_ADAPTER_INDEX_MAP Adapter[1]; } IP_INTERFACE_INFO, *PIP_INTERFACE_INFO;
[PInvokeData("ipexport.h", MSDNShortId = "287a4574-0a0f-4f20-932b-22bb6f40401d")]
[CorrespondingType(typeof(IP_ADAPTER_INDEX_MAP))]
[DefaultProperty(nameof(Adapter))]
public class IP_INTERFACE_INFO : SafeElementArray
{
/// Initializes a new instance of the class.
/// Amount of space, in bytes, to reserve.
public IP_INTERFACE_INFO(uint byteSize) : base((int)byteSize, 0)
{
}
///
///
/// An array of IP_ADAPTER_INDEX_MAP structures. Each structure maps an adapter index to that adapter's name. The adapter index
/// may change when an adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.
///
///
public IP_ADAPTER_INDEX_MAP[] Adapter { get => Elements; set => Elements = value; }
///
/// The number of adapters listed in the array pointed to by the Adapter member.
///
public int NumAdapters => Count;
/// Performs an implicit conversion from to .
/// The IP_INTERFACE_INFO instance.
/// The result of the conversion.
public static implicit operator IntPtr(IP_INTERFACE_INFO iii) => iii.DangerousGetHandle();
}
///
/// The IP_UNIDIRECTIONAL_ADAPTER_ADDRESS structure stores the IPv4 addresses associated with a unidirectional adapter.
///
///
///
/// The IP_UNIDIRECTIONAL_ADAPTER_ADDRESS structure is retrieved by the GetUnidirectionalAdapterInfofunction. A unidirectional
/// adapter is an adapter that can receive IPv4 datagrams, but can't transmit them.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/ipexport/ns-ipexport-_ip_unidirectional_adapter_address typedef struct
// _IP_UNIDIRECTIONAL_ADAPTER_ADDRESS { ULONG NumAdapters; IPAddr Address[1]; } IP_UNIDIRECTIONAL_ADAPTER_ADDRESS, *PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS;
[PInvokeData("ipexport.h", MSDNShortId = "225b93ae-e34f-4e5b-a699-1fdd342265c6")]
[CorrespondingType(typeof(IN_ADDR))]
[DefaultProperty(nameof(Address))]
public class IP_UNIDIRECTIONAL_ADAPTER_ADDRESS : SafeElementArray
{
/// Initializes a new instance of the class.
/// Amount of space, in bytes, to reserve.
public IP_UNIDIRECTIONAL_ADAPTER_ADDRESS(uint byteSize) : base((int)byteSize, 0)
{
}
///
///
/// An array of variables of type IPAddr. Each element of the array specifies an IPv4 address associated with this unidirectional adapter.
///
///
public IN_ADDR[] Address { get => Elements; set => Elements = value; }
///
/// The number of IPv4 addresses pointed to by the Address member.
///
public uint NumAdapters => Count;
/// Performs an implicit conversion from to .
/// The IP_UNIDIRECTIONAL_ADAPTER_ADDRESS instance.
/// The result of the conversion.
public static implicit operator IntPtr(IP_UNIDIRECTIONAL_ADAPTER_ADDRESS table) => table.DangerousGetHandle();
}
}
}