diff --git a/PInvoke/IpHlpApi/IpHlpApi.cs b/PInvoke/IpHlpApi/IpHlpApi.cs
index 3dc2c4d1..6c141957 100644
--- a/PInvoke/IpHlpApi/IpHlpApi.cs
+++ b/PInvoke/IpHlpApi/IpHlpApi.cs
@@ -674,21 +674,6 @@ namespace Vanara.PInvoke
IpSuffixOriginRandom,
}
- [PInvokeData("netioapi.h")]
- public enum MIB_IF_ENTRY_LEVEL
- {
- MibIfEntryNormal = 0,
- MibIfEntryNormalWithoutStatistics = 2
- }
-
- [PInvokeData("netioapi.h")]
- public enum MIB_IF_TABLE_LEVEL
- {
- MibIfTableNormal,
- MibIfTableRaw,
- MibIfTableNormalWithoutStatistics
- }
-
[PInvokeData("IpHlpApi.h")]
[Flags]
public enum MIB_IPADDRTYPE : ushort
@@ -710,13 +695,6 @@ namespace Vanara.PInvoke
MIB_IPROUTE_TYPE_INDIRECT = 4,
}
- [Flags]
- public enum MIB_IPNET_ROW2_FLAGS : uint
- {
- IsRouther = 1,
- IsUnreachable = 2
- }
-
[PInvokeData("IpHlpApi.h")]
public enum MIB_IPNET_TYPE
{
@@ -1360,97 +1338,6 @@ namespace Vanara.PInvoke
[PInvokeData("iphlpapi.h", MSDNShortId = "607f9aad-2046-4ab2-9a62-4092f87ffa66")]
public static extern Win32Error CreateIpNetEntry(ref MIB_IPNETROW pArpEntry);
- ///
- /// The CreateIpNetEntry2 function creates a new neighbor IP address entry on the local computer.
- ///
- ///
- /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry.
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_ACCESS_DENIED
- ///
- /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required
- /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in
- /// Administrator (RunAs administrator).
- ///
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- ///
- /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
- /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid unicast, anycast, or multicast IPv4
- /// or IPv6 address, the PhysicalAddress and PhysicalAddressLength members of the MIB_IPNET_ROW2 pointed to by the Row parameter were
- /// not set to a valid physical address, or both the InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the
- /// Row parameter were unspecified. This error is also returned if a loopback address was passed in the Address member.
- ///
- ///
- /// -
- /// ERROR_NOT_FOUND
- ///
- /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
- /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found.
- ///
- ///
- /// -
- /// ERROR_NOT_SUPPORTED
- ///
- /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
- /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter. This error is also returned if no IPv6 stack is on
- /// the local computer and an IPv6 address was specified in the Address member.
- ///
- ///
- /// -
- /// ERROR_OBJECT_ALREADY_EXISTS
- ///
- /// The object already exists. This error is returned if the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter is
- /// a duplicate of an existing neighbor IP address on the interface specified by the InterfaceLuid or InterfaceIndex member of the MIB_IPNET_ROW2.
- ///
- ///
- /// -
- /// Other
- /// Use FormatMessage to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- /// The CreateIpNetEntry2 function is defined on Windows Vista and later.
- /// The CreateIpNetEntry2 function is used to add a new neighbor IP address entry on a local computer.
- ///
- /// The Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid unicast,
- /// anycast, or multicast IPv4 or IPv6 address and family. The PhysicalAddress and PhysicalAddressLength members in the
- /// MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid physical address. In addition, at
- /// least one of the following members in the MIB_IPNET_ROW2 structure pointed to the Row parameter must be initialized to the
- /// interface: the InterfaceLuid or InterfaceIndex.
- ///
- ///
- /// The CreateIpNetEntry2 function will fail if the IP address passed in the Address member of the MIB_IPNET_ROW2
- /// pointed to by the Row parameter is a duplicate of an existing neighbor IP address on the interface.
- ///
- ///
- /// The CreateIpNetEntry2 function can only be called by a user logged on as a member of the Administrators group. If
- /// CreateIpNetEntry2 is called by a user that is not a member of the Administrators group, the function call will fail and
- /// ERROR_ACCESS_DENIED is returned. This function can also fail because of user account control (UAC) on Windows Vista and
- /// later. If an application that contains this function is executed by a user logged on as a member of the Administrators group
- /// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
- /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a
- /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced
- /// shell as the built-in Administrator (RunAs administrator) for this function to succeed.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-createipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
- // CreateIpNetEntry2( CONST MIB_IPNET_ROW2 *Row );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "ca92b9f8-ec3c-4889-b649-f606c3920f92")]
- public static extern Win32Error CreateIpNetEntry2(ref MIB_IPNET_ROW2 Row);
-
///
/// The DeleteIPAddress function deletes an IP address previously added using AddIPAddress.
///
@@ -1581,86 +1468,6 @@ namespace Vanara.PInvoke
[PInvokeData("iphlpapi.h", MSDNShortId = "0d338676-b66f-410c-8022-5576096954b4")]
public static extern Win32Error DeleteIpNetEntry(ref MIB_IPNETROW pArpEntry);
- ///
- /// The DeleteIpNetEntry2 function deletes a neighbor IP address entry on the local computer.
- ///
- ///
- ///
- /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this entry will be deleted.
- ///
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_ACCESS_DENIED
- ///
- /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required
- /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in
- /// Administrator (RunAs administrator).
- ///
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- ///
- /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
- /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid neighbor IPv4 or IPv6 address, or
- /// both the InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the Row parameter were unspecified.
- ///
- ///
- /// -
- /// ERROR_NOT_FOUND
- ///
- /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
- /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found.
- ///
- ///
- /// -
- /// ERROR_NOT_SUPPORTED
- ///
- /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
- /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter. This error is also returned if no IPv6 stack is on
- /// the local computer and an IPv6 address was specified in the Address member.
- ///
- ///
- /// -
- /// Other
- /// Use FormatMessage to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- /// The DeleteIpNetEntry2 function is defined on Windows Vista and later.
- /// The DeleteIpNetEntry2 function is used to delete a MIB_IPNET_ROW2 structure entry.
- ///
- /// On input, the Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a
- /// valid neighbor IPv4 or IPv6 address and family. In addition, at least one of the following members in the MIB_IPNET_ROW2
- /// structure pointed to the Row parameter must be initialized: the InterfaceLuid or InterfaceIndex.
- ///
- /// On output when the call is successful, DeleteIpNetEntry2 deletes the neighbor IP address.
- /// The GetIpNetTable2 function can be called to enumerate the neighbor IP address entries on a local computer.
- ///
- /// The DeleteIpNetEntry2 function can only be called by a user logged on as a member of the Administrators group. If
- /// DeleteIpNetEntry2 is called by a user that is not a member of the Administrators group, the function call will fail and
- /// ERROR_ACCESS_DENIED is returned. This function can also fail because of user account control (UAC) on Windows Vista and
- /// later. If an application that contains this function is executed by a user logged on as a member of the Administrators group
- /// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
- /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a
- /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced
- /// shell as the built-in Administrator (RunAs administrator) for this function to succeed.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-deleteipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
- // DeleteIpNetEntry2( CONST MIB_IPNET_ROW2 *Row );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "85bace04-6c95-4cf2-a212-764de292aed6")]
- public static extern Win32Error DeleteIpNetEntry2(ref MIB_IPNET_ROW2 Row);
-
///
///
/// The EnableRouter function turns on IPv4 forwarding on the local computer. EnableRouter also increments a reference
@@ -1707,145 +1514,6 @@ namespace Vanara.PInvoke
[PInvokeData("iphlpapi.h", MSDNShortId = "779f5840-d58d-4194-baa7-2c6a7aeb7d79")]
public static extern unsafe Win32Error EnableRouter(ref IntPtr pHandle, System.Threading.NativeOverlapped* pOverlapped);
- ///
- /// The FlushIpNetTable2 function flushes the IP neighbor table on the local computer.
- ///
- ///
- /// The address family to flush.
- ///
- /// Possible values for the address family are listed in the Winsock2.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.
- ///
- ///
- /// On the Windows SDK released for Windows Vista and later, the organization of header files has changed and possible values for
- /// this member are 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.
- ///
- /// The values currently supported are AF_INET, AF_INET6, and AF_UNSPEC.
- ///
- ///
- /// Value
- /// Meaning
- ///
- /// -
- /// AF_UNSPEC 0
- ///
- /// The address family is unspecified. When this parameter is specified, this function flushes the neighbor IP address table
- /// containing both IPv4 and IPv6 entries.
- ///
- ///
- /// -
- /// AF_INET 2
- ///
- /// The Internet Protocol version 4 (IPv4) address family. When this parameter is specified, this function flushes the neighbor IP
- /// address table containing only IPv4 entries.
- ///
- ///
- /// -
- /// AF_INET6 23
- ///
- /// The Internet Protocol version 6 (IPv6) address family. When this parameter is specified, this function flushes the neighbor IP
- /// address table containing only IPv6 entries.
- ///
- ///
- ///
- ///
- ///
- ///
- /// The interface index. If the index is specified, flush the neighbor IP address entries on a specific interface, otherwise flush
- /// the neighbor IP address entries on all the interfaces. To ignore the interface, set this parameter to zero.
- ///
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_ACCESS_DENIED
- ///
- /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required
- /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in
- /// Administrator (RunAs administrator).
- ///
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- ///
- /// An invalid parameter was passed to the function. This error is returned if the Family parameter was not specified as AF_INET,
- /// AF_INET6, or AF_UNSPEC.
- ///
- ///
- /// -
- /// ERROR_NOT_SUPPORTED
- ///
- /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and AF_INET was specified in the
- /// Family parameter. This error is also returned if no IPv6 stack is on the local computer and AF_INET6 was specified in the Family
- /// parameter. This error is also returned on versions of Windows where this function is not supported.
- ///
- ///
- /// -
- /// Other
- /// Use FormatMessage to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- /// The FlushIpNetTable2 function is defined on Windows Vista and later.
- ///
- /// The FlushIpNetTable2 function flushes or deletes the neighbor IP addresses on a local system. The Family parameter can be
- /// used to limit neighbor IP addresses to delete to a particular IP address family. If neighbor IP addresses for both IPv4 and IPv6
- /// should be deleted, set the Family parameter to AF_UNSPEC. The InterfaceIndex parameter can be used to limit neighbor IP
- /// addresses to delete to a particular interface. If neighbor IP addresses for all interfaces should be deleted, set the
- /// InterfaceIndex parameter to zero.
- ///
- /// The Family parameter must be initialized to either AF_INET, AF_INET6, or AF_UNSPEC.
- ///
- /// The FlushIpNetTable2 function can only be called by a user logged on as a member of the Administrators group. If
- /// FlushIpNetTable2 is called by a user that is not a member of the Administrators group, the function call will fail and
- /// ERROR_ACCESS_DENIED is returned. This function can also fail because of user account control (UAC) on Windows Vista and
- /// later. If an application that contains this function is executed by a user logged on as a member of the Administrators group
- /// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
- /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a
- /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced
- /// shell as the built-in Administrator (RunAs administrator) for this function to succeed.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-flushipnettable2 _NETIOAPI_SUCCESS_ NETIOAPI_API
- // FlushIpNetTable2( ADDRESS_FAMILY Family, NET_IFINDEX InterfaceIndex );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "6ebfca41-acc3-450c-a3c5-881b8c3fca5e")]
- public static extern Win32Error FlushIpNetTable2(ADDRESS_FAMILY Family, uint InterfaceIndex);
-
- ///
- ///
- /// The FreeMibTable function frees the buffer allocated by the functions that return tables of network interfaces, addresses,
- /// and routes (GetIfTable2 and GetAnycastIpAddressTable, for example).
- ///
- ///
- ///
- /// A pointer to the buffer to free.
- ///
- ///
- /// This function does not return a value.
- ///
- ///
- /// The FreeMibTable function is defined on Windows Vista and later.
- ///
- /// The FreeMibTable function is used to free the internal buffers used by various functions to retrieve tables of interfaces,
- /// addresses, and routes. When these tables are no longer needed, then FreeMibTable should be called to release the memory
- /// used by these tables.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-freemibtable VOID NETIOAPI_API_ FreeMibTable( PVOID
- // Memory );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "31c8cdc4-73c7-4e82-8226-c90320046199")]
- public static extern void FreeMibTable(IntPtr Memory);
-
/// The GetAdapterIndex function obtains the index of an adapter, given its name.
/// A pointer to a Unicode string that specifies the name of the adapter.
/// A pointer to a ULONG variable that points to the index of the adapter.
@@ -2330,276 +1998,6 @@ namespace Vanara.PInvoke
[PInvokeData("iphlpapi.h", MSDNShortId = "5e507d14-f603-467d-9c37-bb048658d0b1")]
public static extern Win32Error GetBestRoute(IN_ADDR dwDestAddr, [Optional] IN_ADDR dwSourceAddr, out MIB_IPFORWARDROW pBestRoute);
- ///
- ///
- /// The GetBestRoute2 function retrieves the IP route entry on the local computer for the best route to the specified
- /// destination IP address.
- ///
- ///
- ///
- /// The locally unique identifier (LUID) to specify the network interface associated with an IP route entry.
- ///
- ///
- ///
- /// The local index value to specify the network interface associated with an IP route entry. This index value may change when a
- /// network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.
- ///
- ///
- ///
- /// The source IP address. This parameter may be omitted and passed as a NULL pointer.
- ///
- ///
- /// The destination IP address.
- ///
- ///
- /// A set of options that affect how IP addresses are sorted. This parameter is not currently used.
- ///
- ///
- /// A pointer to the MIB_IPFORWARD_ROW2 for the best route from the source IP address to the destination IP address.
- ///
- ///
- /// A pointer to the best source IP address.
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- ///
- /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the DestinationAddress,
- /// BestSourceAddress, or the BestRoute parameter. This error is also returned if the DestinationAddress parameter does not specify
- /// an IPv4 or IPv6 address and family.
- ///
- ///
- /// -
- /// ERROR_FILE_NOT_FOUND
- ///
- /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
- /// InterfaceIndex parameter could not be found.
- ///
- ///
- /// -
- /// ERROR_NOT_SUPPORTED
- ///
- /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address and family was
- /// specified in the DestinationAddress parameter. This error is also returned if no IPv6 stack is on the local computer and an IPv6
- /// address and family was specified in the DestinationAddress parameter.
- ///
- ///
- /// -
- /// Other
- /// Use FormatMessage to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- /// The GetBestRoute2 function is defined on Windows Vista and later.
- ///
- /// The GetBestRoute2 function is used to retrieve a MIB_IPFORWARD_ROW2 structure entry for the best route from a source IP
- /// address to a destination IP address.
- ///
- ///
- /// On input, the DestinationAddress parameter must be initialized to a valid IPv4 or IPv6 address and family. On input, the
- /// SourceAddress parameter may be initialized to the preferred IPv4 or IPv6 address and family. In addition, at least one of the
- /// following parameters must be initialized: the InterfaceLuid or InterfaceIndex.
- ///
- ///
- /// On output when the call is successful, GetBestRoute2 retrieves and MIB_IPFORWARD_ROW2 structure for the best route from
- /// the source IP address the destination IP address.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getbestroute2 _NETIOAPI_SUCCESS_ NETIOAPI_API
- // GetBestRoute2( NET_LUID *InterfaceLuid, NET_IFINDEX InterfaceIndex, CONST SOCKADDR_INET *SourceAddress, CONST SOCKADDR_INET
- // *DestinationAddress, ULONG AddressSortOptions, PMIB_IPFORWARD_ROW2 BestRoute, SOCKADDR_INET *BestSourceAddress );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "7bc16824-c98f-4cd5-a589-e198b48b637c")]
- public static extern Win32Error GetBestRoute2(ref NET_LUID InterfaceLuid, uint InterfaceIndex, ref SOCKADDR_INET SourceAddress, ref SOCKADDR_INET DestinationAddress, uint AddressSortOptions, out MIB_IPFORWARD_ROW2 BestRoute, out SOCKADDR_INET BestSourceAddress);
-
- ///
- ///
- /// The GetBestRoute2 function retrieves the IP route entry on the local computer for the best route to the specified
- /// destination IP address.
- ///
- ///
- ///
- /// The locally unique identifier (LUID) to specify the network interface associated with an IP route entry.
- ///
- ///
- ///
- /// The local index value to specify the network interface associated with an IP route entry. This index value may change when a
- /// network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.
- ///
- ///
- ///
- /// The source IP address. This parameter may be omitted and passed as a NULL pointer.
- ///
- ///
- /// The destination IP address.
- ///
- ///
- /// A set of options that affect how IP addresses are sorted. This parameter is not currently used.
- ///
- ///
- /// A pointer to the MIB_IPFORWARD_ROW2 for the best route from the source IP address to the destination IP address.
- ///
- ///
- /// A pointer to the best source IP address.
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- ///
- /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the DestinationAddress,
- /// BestSourceAddress, or the BestRoute parameter. This error is also returned if the DestinationAddress parameter does not specify
- /// an IPv4 or IPv6 address and family.
- ///
- ///
- /// -
- /// ERROR_FILE_NOT_FOUND
- ///
- /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
- /// InterfaceIndex parameter could not be found.
- ///
- ///
- /// -
- /// ERROR_NOT_SUPPORTED
- ///
- /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address and family was
- /// specified in the DestinationAddress parameter. This error is also returned if no IPv6 stack is on the local computer and an IPv6
- /// address and family was specified in the DestinationAddress parameter.
- ///
- ///
- /// -
- /// Other
- /// Use FormatMessage to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- /// The GetBestRoute2 function is defined on Windows Vista and later.
- ///
- /// The GetBestRoute2 function is used to retrieve a MIB_IPFORWARD_ROW2 structure entry for the best route from a source IP
- /// address to a destination IP address.
- ///
- ///
- /// On input, the DestinationAddress parameter must be initialized to a valid IPv4 or IPv6 address and family. On input, the
- /// SourceAddress parameter may be initialized to the preferred IPv4 or IPv6 address and family. In addition, at least one of the
- /// following parameters must be initialized: the InterfaceLuid or InterfaceIndex.
- ///
- ///
- /// On output when the call is successful, GetBestRoute2 retrieves and MIB_IPFORWARD_ROW2 structure for the best route from
- /// the source IP address the destination IP address.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getbestroute2 _NETIOAPI_SUCCESS_ NETIOAPI_API
- // GetBestRoute2( NET_LUID *InterfaceLuid, NET_IFINDEX InterfaceIndex, CONST SOCKADDR_INET *SourceAddress, CONST SOCKADDR_INET
- // *DestinationAddress, ULONG AddressSortOptions, PMIB_IPFORWARD_ROW2 BestRoute, SOCKADDR_INET *BestSourceAddress );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "7bc16824-c98f-4cd5-a589-e198b48b637c")]
- public static extern Win32Error GetBestRoute2(IntPtr InterfaceLuid, uint InterfaceIndex, ref SOCKADDR_INET SourceAddress, ref SOCKADDR_INET DestinationAddress, uint AddressSortOptions, out MIB_IPFORWARD_ROW2 BestRoute, out SOCKADDR_INET BestSourceAddress);
-
- ///
- ///
- /// The GetBestRoute2 function retrieves the IP route entry on the local computer for the best route to the specified
- /// destination IP address.
- ///
- ///
- ///
- /// The locally unique identifier (LUID) to specify the network interface associated with an IP route entry.
- ///
- ///
- ///
- /// The local index value to specify the network interface associated with an IP route entry. This index value may change when a
- /// network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.
- ///
- ///
- ///
- /// The source IP address. This parameter may be omitted and passed as a NULL pointer.
- ///
- ///
- /// The destination IP address.
- ///
- ///
- /// A set of options that affect how IP addresses are sorted. This parameter is not currently used.
- ///
- ///
- /// A pointer to the MIB_IPFORWARD_ROW2 for the best route from the source IP address to the destination IP address.
- ///
- ///
- /// A pointer to the best source IP address.
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- ///
- /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the DestinationAddress,
- /// BestSourceAddress, or the BestRoute parameter. This error is also returned if the DestinationAddress parameter does not specify
- /// an IPv4 or IPv6 address and family.
- ///
- ///
- /// -
- /// ERROR_FILE_NOT_FOUND
- ///
- /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
- /// InterfaceIndex parameter could not be found.
- ///
- ///
- /// -
- /// ERROR_NOT_SUPPORTED
- ///
- /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address and family was
- /// specified in the DestinationAddress parameter. This error is also returned if no IPv6 stack is on the local computer and an IPv6
- /// address and family was specified in the DestinationAddress parameter.
- ///
- ///
- /// -
- /// Other
- /// Use FormatMessage to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- /// The GetBestRoute2 function is defined on Windows Vista and later.
- ///
- /// The GetBestRoute2 function is used to retrieve a MIB_IPFORWARD_ROW2 structure entry for the best route from a source IP
- /// address to a destination IP address.
- ///
- ///
- /// On input, the DestinationAddress parameter must be initialized to a valid IPv4 or IPv6 address and family. On input, the
- /// SourceAddress parameter may be initialized to the preferred IPv4 or IPv6 address and family. In addition, at least one of the
- /// following parameters must be initialized: the InterfaceLuid or InterfaceIndex.
- ///
- ///
- /// On output when the call is successful, GetBestRoute2 retrieves and MIB_IPFORWARD_ROW2 structure for the best route from
- /// the source IP address the destination IP address.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getbestroute2 _NETIOAPI_SUCCESS_ NETIOAPI_API
- // GetBestRoute2( NET_LUID *InterfaceLuid, NET_IFINDEX InterfaceIndex, CONST SOCKADDR_INET *SourceAddress, CONST SOCKADDR_INET
- // *DestinationAddress, ULONG AddressSortOptions, PMIB_IPFORWARD_ROW2 BestRoute, SOCKADDR_INET *BestSourceAddress );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "7bc16824-c98f-4cd5-a589-e198b48b637c")]
- public static extern Win32Error GetBestRoute2(IntPtr InterfaceLuid, uint InterfaceIndex, IntPtr SourceAddress, ref SOCKADDR_INET DestinationAddress, uint AddressSortOptions, out MIB_IPFORWARD_ROW2 BestRoute, out SOCKADDR_INET BestSourceAddress);
-
///
/// The GetExtendedTcpTable function retrieves a table that contains a list of TCP endpoints available to the application.
///
@@ -3049,151 +2447,6 @@ namespace Vanara.PInvoke
return mem;
}
- ///
- /// The GetIfEntry2 function retrieves information for the specified interface on the local computer.
- ///
- ///
- ///
- /// A pointer to a MIB_IF_ROW2 structure that, on successful return, receives information for an interface on the local computer. On
- /// input, the InterfaceLuid or the InterfaceIndex member of the MIB_IF_ROW2 must be set to the interface for
- /// which to retrieve information.
- ///
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_FILE_NOT_FOUND
- ///
- /// The system cannot find the file specified. This error is returned if the network interface LUID or interface index specified by
- /// the InterfaceLuid or InterfaceIndex member of the MIB_IF_ROW2 pointed to by the Row parameter was not a value on the local machine.
- ///
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- ///
- /// An invalid parameter was passed to the function. This error is returned if a NULL parameter is passed in the Row parameter. This
- /// error is also returned if the both the InterfaceLuid and InterfaceIndex member of the MIB_IF_ROW2 pointed to by the Row parameter
- /// are unspecified.
- ///
- ///
- /// -
- /// Other
- /// Use the FormatMessage function to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- /// The GetIfEntry2 function is defined on Windows Vista and later.
- ///
- /// On input, at least one of the following members in the MIB_IF_ROW2 structure passed in the Row parameter must be initialized:
- /// InterfaceLuid or InterfaceIndex.
- ///
- /// On output, the remaining fields of the MIB_IF_ROW2 structure pointed to by the Row parameter are filled in.
- /// Note that the Netioapi.h header file is automatically included in IpHlpApi.h header file, and should never be used directly.
- /// Examples
- ///
- /// The following example retrieves a interface entry specified on the command line and prints some values from the retrieved
- /// MIB_IF_ROW2 structure.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getifentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API GetIfEntry2(
- // PMIB_IF_ROW2 Row );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "da787dae-5e89-4bf2-a9b6-90e727995414")]
- public static extern Win32Error GetIfEntry2(ref MIB_IF_ROW2 Row);
-
- ///
- ///
- /// The GetIfEntry2Ex function retrieves the specified level of information for the specified interface on the local computer.
- ///
- ///
- ///
- ///
- /// The level of interface information to retrieve. This parameter can be one of the values from the MIB_IF_ENTRY_LEVEL
- /// enumeration type defined in the Netioapi.h header file.
- ///
- ///
- ///
- /// Value
- /// Meaning
- ///
- /// -
- /// MibIfEntryNormal 0
- ///
- /// The values of statistics and state returned in members of the MIB_IF_ROW2 structure pointed to by the Row parameter are returned
- /// from the top of the filter stack.
- ///
- ///
- /// -
- /// MibIfEntryNormalWithoutStatistics 2
- ///
- /// The values of state (without statistics) returned in members of the MIB_IF_ROW2 structure pointed to by the Row parameter are
- /// returned from the top of the filter stack.
- ///
- ///
- ///
- ///
- ///
- ///
- /// A pointer to a MIB_IF_ROW2 structure that, on successful return, receives information for an interface on the local computer. On
- /// input, the InterfaceLuid or the InterfaceIndex member of the MIB_IF_ROW2 must be set to the interface for
- /// which to retrieve information.
- ///
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_FILE_NOT_FOUND
- ///
- /// The system cannot find the file specified. This error is returned if the network interface LUID or interface index specified by
- /// the InterfaceLuid or InterfaceIndex member of the MIB_IF_ROW2 pointed to by the Row parameter was not a value on the local machine.
- ///
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- ///
- /// An invalid parameter was passed to the function. This error is returned if a NULL parameter is passed in the Row parameter. This
- /// error is also returned if the both the InterfaceLuid and InterfaceIndex member of the MIB_IF_ROW2 pointed to by the Row parameter
- /// are unspecified.
- ///
- ///
- /// -
- /// Other
- /// Use the FormatMessage function to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- ///
- /// The GetIfEntry2Ex function retrieves information for a specified interface on a local system and returns this information
- /// in a pointer to a MIB_IF_ROW2 structure. GetIfEntry2Ex is an enhanced version of the GetIfEntry2 function that allows
- /// selecting the level of interface information to retrieve.
- ///
- ///
- /// On input, at least one of the following members in the MIB_IF_ROW2 structure passed in the Row parameter must be initialized:
- /// InterfaceLuid or InterfaceIndex.
- ///
- /// On output, the remaining fields of the MIB_IF_ROW2 structure pointed to by the Row parameter are filled in.
- /// Note that the Netioapi.h header file is automatically included in IpHlpApi.h header file, and should never be used directly.
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getifentry2ex _NETIOAPI_SUCCESS_ NETIOAPI_API
- // GetIfEntry2Ex( MIB_IF_ENTRY_LEVEL Level, PMIB_IF_ROW2 Row );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "98C25986-1B38-4878-B578-3D30394F49E4")]
- public static extern Win32Error GetIfEntry2Ex(MIB_IF_ENTRY_LEVEL Level, ref MIB_IF_ROW2 Row);
-
///
/// The GetIfTable function retrieves the MIB-II interface table.
///
@@ -3293,155 +2546,6 @@ namespace Vanara.PInvoke
return mem;
}
- ///
- /// The GetIfTable2 function retrieves the MIB-II interface table.
- ///
- ///
- /// A pointer to a buffer that receives the table of interfaces in a MIB_IF_TABLE2 structure.
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_NOT_ENOUGH_MEMORY
- /// Insufficient memory resources are available to complete the operation.
- ///
- /// -
- /// Other
- /// Use FormatMessage to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- ///
- /// The GetIfTable2 function enumerates the logical and physical interfaces on a local system and returns this information in
- /// a MIB_IF_TABLE2 structure. GetIfTable2 is an enhanced version of the GetIfTable function.
- ///
- ///
- /// A similar GetIfTable2Ex function can be used to specify the level of interfaces to return. Calling the GetIfTable2Ex
- /// function with the Level parameter set to MibIfTableNormal retrieves the same results as calling the GetIfTable2 function.
- ///
- ///
- /// Interfaces are returned in a MIB_IF_TABLE2 structure in the buffer pointed to by the Table parameter. The MIB_IF_TABLE2
- /// structure contains an interface count and an array of MIB_IF_ROW2 structures for each interface. Memory is allocated by the
- /// GetIfTable2 function for the MIB_IF_TABLE2 structure and the MIB_IF_ROW2 entries in this structure. When
- /// these returned structures are no longer required, free the memory by calling the FreeMibTable.
- ///
- ///
- /// Note that the returned MIB_IF_TABLE2 structure pointed to by the Table parameter may contain padding for alignment between the
- /// NumEntries member and the first MIB_IF_ROW2 array entry in the Table member of the MIB_IF_TABLE2 structure.
- /// Padding for alignment may also be present between the MIB_IF_ROW2 array entries. Any access to a MIB_IF_ROW2 array
- /// entry should assume padding may exist.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getiftable2 _NETIOAPI_SUCCESS_ NETIOAPI_API GetIfTable2(
- // PMIB_IF_TABLE2 *Table );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "0153c41c-b02b-4832-87b3-88dc3a9f4ff1")]
- public static extern Win32Error GetIfTable2(out MIB_IF_TABLE2 pIfTable);
-
- ///
- /// The GetIfTable2Ex function retrieves the MIB-II interface table.
- ///
- ///
- ///
- /// The level of interface information to retrieve. This parameter can be one of the values from the MIB_IF_TABLE_LEVEL
- /// enumeration type defined in the Netioapi.h header file.
- ///
- ///
- ///
- /// Value
- /// Meaning
- ///
- /// -
- /// MibIfTableNormal
- ///
- /// The values of statistics and state returned in members of the MIB_IF_ROW2 structure in the MIB_IF_TABLE2 structure pointed to by
- /// the Table parameter are returned from the top of the filter stack when this parameter is specified.
- ///
- ///
- /// -
- /// MibIfTableRaw
- ///
- /// The values of statistics and state returned in members of the MIB_IF_ROW2 structure in the MIB_IF_TABLE2 structure pointed to by
- /// the Table parameter are returned directly for the interface being queried.
- ///
- ///
- ///
- ///
- ///
- /// A pointer to a buffer that receives the table of interfaces in a MIB_IF_TABLE2 structure.
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- /// An invalid parameter was passed to the function. This error is returned if an illegal value was passed in the Level parameter.
- ///
- /// -
- /// ERROR_NOT_ENOUGH_MEMORY
- /// Insufficient memory resources are available to complete the operation.
- ///
- /// -
- /// Other
- /// Use FormatMessage to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- ///
- /// The GetIfTable2Ex function enumerates the logical and physical interfaces on a local system and returns this information
- /// in a MIB_IF_TABLE2 structure. GetIfTable2Ex is an enhanced version of the GetIfTable function that allows selecting
- /// the level of interface information to retrieve.
- ///
- ///
- /// A similar GetIfTable2 function can also be used to retrieve interfaces. but does not allow specifying the level of interfaces to
- /// return. Calling the GetIfTable2Ex function with the Level parameter set to MibIfTableNormal retrieves the same
- /// results as calling the GetIfTable2 function.
- ///
- ///
- /// Interfaces are returned in a MIB_IF_TABLE2 structure in the buffer pointed to by the Table parameter. The MIB_IF_TABLE2
- /// structure contains an interface count and an array of MIB_IF_ROW2 structures for each interface. Memory is allocated by the
- /// GetIfTable2 function for the MIB_IF_TABLE2 structure and the MIB_IF_ROW2 entries in this structure. When these
- /// returned structures are no longer required, free the memory by calling the FreeMibTable.
- ///
- ///
- /// All interfaces including NDIS intermediate driver interfaces and NDIS filter driver interfaces are returned for either of the
- /// possible values for the Level parameter. The setting for the Level parameter affects how statistics and state members of the
- /// MIB_IF_ROW2 structure in the MIB_IF_TABLE2 structure pointed to by the Table parameter for the interface are returned. For
- /// example, a network interface card (NIC) will have a NDIS miniport driver. An NDIS intermediate driver can be installed to
- /// interface between upper-level protocol drivers and NDIS miniport drivers. An NDIS filter driver (LWF) can be attached on top of
- /// the NDIS intermediate driver. Assume that the NIC reports the MediaConnectState member of the MIB_IF_ROW2 structure as
- /// MediaConnectStateConnected but NDIS filter driver modifies the state and reports the state as
- /// MediaConnectStateDisconnected. When the interface information is queried with Level parameter set to
- /// MibIfTableNormal, the state at the top of the filter stack, that is MediaConnectStateDisconnected is reported. When
- /// the interface is queried with the Level parameter set to MibIfTableRaw, the state at the interface level directly, that is
- /// MediaConnectStateConnected is returned.
- ///
- ///
- /// Note that the returned MIB_IF_TABLE2 structure pointed to by the Table parameter may contain padding for alignment between the
- /// NumEntries member and the first MIB_IF_ROW2 array entry in the Table member of the MIB_IF_TABLE2 structure.
- /// Padding for alignment may also be present between the MIB_IF_ROW2 array entries. Any access to a MIB_IF_ROW2 array
- /// entry should assume padding may exist.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getiftable2ex _NETIOAPI_SUCCESS_ NETIOAPI_API
- // GetIfTable2Ex( MIB_IF_TABLE_LEVEL Level, PMIB_IF_TABLE2 *Table );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "d8663894-50b1-4ca2-a1f4-6ca0970795a7")]
- public static extern Win32Error GetIfTable2Ex(MIB_IF_TABLE_LEVEL Level, out MIB_IF_TABLE2 pIfTable);
-
///
///
/// The GetInterfaceInfo function obtains the list of the network interface adapters with IPv4 enabled on the local system.
@@ -3673,80 +2777,6 @@ namespace Vanara.PInvoke
return mem;
}
- ///
- /// The GetIpNetEntry2 function retrieves information for a neighbor IP address entry on the local computer.
- ///
- ///
- ///
- /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this structure will be
- /// updated with the properties for neighbor IP address.
- ///
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_FILE_NOT_FOUND
- ///
- /// The system cannot find the file specified. This error is returned if the network interface LUID or interface index specified by
- /// the InterfaceLuid or InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not a value on the local machine.
- ///
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- ///
- /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
- /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid neighbor IPv4 or IPv6 address, or
- /// both the InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the Row parameter were unspecified.
- ///
- ///
- /// -
- /// ERROR_NOT_FOUND
- ///
- /// Element not found. This error is returned if the network interface specified by the InterfaceLuid or InterfaceIndex member of the
- /// MIB_IPNET_ROW2 structure pointed to by the Row parameter does not match the neighbor IP address and address family specified in
- /// the Address member in the MIB_IPNET_ROW2 structure.
- ///
- ///
- /// -
- /// ERROR_NOT_SUPPORTED
- ///
- /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
- /// in the Address member of the MIB_IPNET_ROW2 structure pointed to by the Row parameter. This error is also returned if no IPv6
- /// stack is on the local computer and an IPv6 address was specified in the Address member of the MIB_IPNET_ROW2 structure.
- ///
- ///
- /// -
- /// Other
- /// Use FormatMessage to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- /// The GetIpNetEntry2 function is defined on Windows Vista and later.
- /// The GetIpNetEntry2 function is used to retrieve a MIB_IPNET_ROW2 structure entry.
- ///
- /// On input, the Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a
- /// valid neighbor IPv4 or IPv6 address and family. In addition, at least one of the following members in the MIB_IPNET_ROW2
- /// structure pointed to the Row parameter must be initialized: the InterfaceLuid or InterfaceIndex.
- ///
- ///
- /// On output when the call is successful, GetIpNetEntry2 retrieves the other properties for the neighbor IP address and fills
- /// out the MIB_IPNET_ROW2 structure pointed to by the Row parameter.
- ///
- /// The GetIpNetTable2 function can be called to enumerate the neighbor IP address entries on a local computer.
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
- // GetIpNetEntry2( PMIB_IPNET_ROW2 Row );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "c77e01da-2d5a-4c74-b581-62fa6ee52c9e")]
- public static extern Win32Error GetIpNetEntry2(ref MIB_IPNET_ROW2 Row);
-
///
/// The GetIpNetTable function retrieves the IPv4 to physical address mapping table.
///
@@ -3850,120 +2880,6 @@ namespace Vanara.PInvoke
return mem;
}
- ///
- /// The GetIpNetTable2 function retrieves the IP neighbor table on the local computer.
- ///
- ///
- /// The address family to retrieve.
- ///
- /// Possible values for the address family are listed in the Winsock2.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.
- ///
- ///
- /// On the Windows SDK released for Windows Vista and later, the organization of header files has changed and possible values for
- /// this member are 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.
- ///
- /// The values currently supported are AF_INET, AF_INET6, and AF_UNSPEC.
- ///
- ///
- /// Value
- /// Meaning
- ///
- /// -
- /// AF_UNSPEC 0
- ///
- /// The address family is unspecified. When this parameter is specified, this function returns the neighbor IP address table
- /// containing both IPv4 and IPv6 entries.
- ///
- ///
- /// -
- /// AF_INET 2
- ///
- /// The Internet Protocol version 4 (IPv4) address family. When this parameter is specified, this function returns the neighbor IP
- /// address table containing only IPv4 entries.
- ///
- ///
- /// -
- /// AF_INET6 23
- ///
- /// The Internet Protocol version 6 (IPv6) address family. When this parameter is specified, this function returns the neighbor IP
- /// address table containing only IPv6 entries.
- ///
- ///
- ///
- ///
- ///
- /// A pointer to a MIB_IPNET_TABLE2 structure that contains a table of neighbor IP address entries on the local computer.
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR or ERROR_NOT_FOUND.
- /// If the function fails or returns no data, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- ///
- /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Table parameter or the
- /// Family parameter was not specified as AF_INET, AF_INET6, or AF_UNSPEC.
- ///
- ///
- /// -
- /// ERROR_NOT_ENOUGH_MEMORY
- /// Insufficient memory resources are available to complete the operation.
- ///
- /// -
- /// ERROR_NOT_FOUND
- ///
- /// No neighbor IP address entries as specified in the Family parameter were found. This return value indicates that the call to the
- /// GetIpNetTable2 function succeeded, but there was no data to return. This can occur when AF_INET is specified in the Family
- /// parameter and there are no ARP entries to return.
- ///
- ///
- /// -
- /// ERROR_NOT_SUPPORTED
- ///
- /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and AF_INET was specified in the
- /// Family parameter. This error is also returned if no IPv6 stack is on the local computer and AF_INET6 was specified in the Family
- /// parameter. This error is also returned on versions of Windows where this function is not supported.
- ///
- ///
- /// -
- /// Other
- /// Use FormatMessage to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- /// The GetIpNetTable2 function is defined on Windows Vista and later.
- ///
- /// The GetIpNetTable2 function enumerates the neighbor IP addresses on a local system and returns this information in a
- /// MIB_IPNET_TABLE2 structure.
- ///
- ///
- /// The neighbor IP address entries are returned in a MIB_IPNET_TABLE2 structure in the buffer pointed to by the Table parameter. The
- /// MIB_IPNET_TABLE2 structure contains a neighbor IP address entry count and an array of MIB_IPNET_ROW2 structures for each
- /// neighbor IP address entry. When these returned structures are no longer required, free the memory by calling the FreeMibTable.
- ///
- /// The Family parameter must be initialized to either AF_INET, AF_INET6, or AF_UNSPEC.
- ///
- /// Note that the returned MIB_IPNET_TABLE2 structure pointed to by the Table parameter may contain padding for alignment between the
- /// NumEntries member and the first MIB_IPNET_ROW2 array entry in the Table member of the MIB_IPNET_TABLE2
- /// structure. Padding for alignment may also be present between the MIB_IPNET_ROW2 array entries. Any access to a
- /// MIB_IPNET_ROW2 array entry should assume padding may exist.
- ///
- /// Examples
- /// The following example retrieves the IP neighbor table, then prints the values for IP neighbor row entries in the table.
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getipnettable2 _NETIOAPI_SUCCESS_ NETIOAPI_API
- // GetIpNetTable2( ADDRESS_FAMILY Family, PMIB_IPNET_TABLE2 *Table );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "6c45d735-9a07-41ca-8d8a-919f32c98a3c")]
- public static extern Win32Error GetIpNetTable2(ADDRESS_FAMILY Family, out MIB_IPNET_TABLE2 Table);
-
///
/// The GetNetworkParams function retrieves network parameters for the local computer.
///
@@ -4564,184 +3480,6 @@ namespace Vanara.PInvoke
return $"{physAddr[0]:X}-{physAddr[1]:X}-{physAddr[2]:X}-{physAddr[3]:X}-{physAddr[4]:X}-{physAddr[5]:X}";
}
- ///
- /// The ResolveIpNetEntry2 function resolves the physical address for a neighbor IP address entry on the local computer.
- ///
- ///
- ///
- /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this structure will be
- /// updated with the properties for neighbor IP address.
- ///
- ///
- ///
- ///
- /// A pointer to a an optional source IP address used to select the interface to send the requests on for the neighbor IP address entry.
- ///
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_BAD_NET_NAME
- /// The network name cannot be found. This error is returned if the network with the neighbor IP address is unreachable.
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- ///
- /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
- /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid IPv4 or IPv6 address, or both the
- /// InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the Row parameter were unspecified. This error is
- /// also returned if a loopback address was passed in the Address member.
- ///
- ///
- /// -
- /// ERROR_NOT_FOUND
- ///
- /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
- /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found.
- ///
- ///
- /// -
- /// ERROR_NOT_SUPPORTED
- ///
- /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
- /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter or no IPv6 stack is on the local computer and an IPv6
- /// address was specified in the Address member.
- ///
- ///
- /// -
- /// Other
- /// Use FormatMessage to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- /// The ResolveIpNetEntry2 function is defined on Windows Vista and later.
- ///
- /// The ResolveIpNetEntry2 function is used to resolve the physical address for a neighbor IP address entry on a local
- /// computer. This function flushes any existing neighbor entry that matches the IP address on the interface and then resolves the
- /// physical address (MAC) address by sending ARP requests for an IPv4 address or neighbor solicitation requests for an IPv6 address.
- /// If the SourceAddress parameter is specified, the ResolveIpNetEntry2 function will select the interface with this source IP
- /// address to send the requests on. If the SourceAddress parameter is not specified (NULL was passed in this parameter), the
- /// ResolveIpNetEntry2 function will automatically select the best interface to send the requests on.
- ///
- ///
- /// The Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid IPv4 or
- /// IPv6 address and family. In addition, at least one of the following members in the MIB_IPNET_ROW2 structure pointed to the
- /// Row parameter must be initialized to the interface: the InterfaceLuid or InterfaceIndex.
- ///
- ///
- /// If the IP address passed in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter is a duplicate of an
- /// existing neighbor IP address on the interface, the ResolveIpNetEntry2 function will flush the existing entry before
- /// resolving the IP address.
- ///
- ///
- /// On output when the call is successful, ResolveIpNetEntry2 retrieves the other properties for the neighbor IP address and
- /// fills out the MIB_IPNET_ROW2 structure pointed to by the Row parameter. The PhysicalAddress and
- /// PhysicalAddressLength members in the MIB_IPNET_ROW2 structure pointed to by the Row parameter will be initialized
- /// to a valid physical address.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-resolveipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
- // ResolveIpNetEntry2( PMIB_IPNET_ROW2 Row, CONST SOCKADDR_INET *SourceAddress );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "37f9dc58-362d-413e-a593-4dda52fb7d8b")]
- public static extern Win32Error ResolveIpNetEntry2(ref MIB_IPNET_ROW2 Row, IntPtr SourceAddress = default(IntPtr));
-
- ///
- /// The ResolveIpNetEntry2 function resolves the physical address for a neighbor IP address entry on the local computer.
- ///
- ///
- ///
- /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this structure will be
- /// updated with the properties for neighbor IP address.
- ///
- ///
- ///
- ///
- /// A pointer to a an optional source IP address used to select the interface to send the requests on for the neighbor IP address entry.
- ///
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_BAD_NET_NAME
- /// The network name cannot be found. This error is returned if the network with the neighbor IP address is unreachable.
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- ///
- /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
- /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid IPv4 or IPv6 address, or both the
- /// InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the Row parameter were unspecified. This error is
- /// also returned if a loopback address was passed in the Address member.
- ///
- ///
- /// -
- /// ERROR_NOT_FOUND
- ///
- /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
- /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found.
- ///
- ///
- /// -
- /// ERROR_NOT_SUPPORTED
- ///
- /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
- /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter or no IPv6 stack is on the local computer and an IPv6
- /// address was specified in the Address member.
- ///
- ///
- /// -
- /// Other
- /// Use FormatMessage to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- /// The ResolveIpNetEntry2 function is defined on Windows Vista and later.
- ///
- /// The ResolveIpNetEntry2 function is used to resolve the physical address for a neighbor IP address entry on a local
- /// computer. This function flushes any existing neighbor entry that matches the IP address on the interface and then resolves the
- /// physical address (MAC) address by sending ARP requests for an IPv4 address or neighbor solicitation requests for an IPv6 address.
- /// If the SourceAddress parameter is specified, the ResolveIpNetEntry2 function will select the interface with this source IP
- /// address to send the requests on. If the SourceAddress parameter is not specified (NULL was passed in this parameter), the
- /// ResolveIpNetEntry2 function will automatically select the best interface to send the requests on.
- ///
- ///
- /// The Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid IPv4 or
- /// IPv6 address and family. In addition, at least one of the following members in the MIB_IPNET_ROW2 structure pointed to the
- /// Row parameter must be initialized to the interface: the InterfaceLuid or InterfaceIndex.
- ///
- ///
- /// If the IP address passed in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter is a duplicate of an
- /// existing neighbor IP address on the interface, the ResolveIpNetEntry2 function will flush the existing entry before
- /// resolving the IP address.
- ///
- ///
- /// On output when the call is successful, ResolveIpNetEntry2 retrieves the other properties for the neighbor IP address and
- /// fills out the MIB_IPNET_ROW2 structure pointed to by the Row parameter. The PhysicalAddress and
- /// PhysicalAddressLength members in the MIB_IPNET_ROW2 structure pointed to by the Row parameter will be initialized
- /// to a valid physical address.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-resolveipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
- // ResolveIpNetEntry2( PMIB_IPNET_ROW2 Row, CONST SOCKADDR_INET *SourceAddress );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "37f9dc58-362d-413e-a593-4dda52fb7d8b")]
- public static extern Win32Error ResolveIpNetEntry2(ref MIB_IPNET_ROW2 Row, ref SOCKADDR_INET SourceAddress);
-
///
///
/// The SendARP function sends an Address Resolution Protocol (ARP) request to obtain the physical address that corresponds to
@@ -5000,95 +3738,6 @@ namespace Vanara.PInvoke
[PInvokeData("iphlpapi.h", MSDNShortId = "d985b749-5aa3-4b4a-ba8f-bc8edcf1b1f3")]
public static extern Win32Error SetIpNetEntry(ref MIB_IPNETROW pArpEntry);
- ///
- /// The SetIpNetEntry2 function sets the physical address of an existing neighbor IP address entry on the local computer.
- ///
- ///
- /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry.
- ///
- ///
- /// If the function succeeds, the return value is NO_ERROR.
- /// If the function fails, the return value is one of the following error codes.
- ///
- ///
- /// Return code
- /// Description
- ///
- /// -
- /// ERROR_ACCESS_DENIED
- ///
- /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required
- /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in
- /// Administrator (RunAs administrator).
- ///
- ///
- /// -
- /// ERROR_INVALID_PARAMETER
- ///
- /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
- /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid unicast, anycast, or multicast IPv4
- /// or IPv6 address, the PhysicalAddress and PhysicalAddressLength members of the MIB_IPNET_ROW2 pointed to by the Row parameter were
- /// not set to a valid physical address, or both the InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the
- /// Row parameter were unspecified. This error is also returned if a loopback address was passed in the Address member.
- ///
- ///
- /// -
- /// ERROR_NOT_FOUND
- ///
- /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
- /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found.
- ///
- ///
- /// -
- /// ERROR_NOT_SUPPORTED
- ///
- /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
- /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter or no IPv6 stack is on the local computer and an IPv6
- /// address was specified in the Address member.
- ///
- ///
- /// -
- /// Other
- /// Use FormatMessage to obtain the message string for the returned error.
- ///
- ///
- ///
- ///
- /// The SetIpNetEntry2 function is defined on Windows Vista and later.
- ///
- /// The SetIpNetEntry2 function is used to set the physical address for an existing neighbor IP address entry on a local computer.
- ///
- ///
- /// The Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid unicast,
- /// anycast, or multicast IPv4 or IPv6 address and family. The PhysicalAddress and PhysicalAddressLength members in the
- /// MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid physical address. In addition, at
- /// least one of the following members in the MIB_IPNET_ROW2 structure pointed to the Row parameter must be initialized to the
- /// interface: the InterfaceLuid or InterfaceIndex.
- ///
- ///
- /// The SetIpNetEntry2 function will fail if the IP address passed in the Address member of the MIB_IPNET_ROW2 pointed
- /// to by the Row parameter is not an existing neighbor IP address on the interface specified.
- ///
- ///
- /// The SetIpNetEntry2 function can only be called by a user logged on as a member of the Administrators group. If
- /// SetIpNetEntry2 is called by a user that is not a member of the Administrators group, the function call will fail and
- /// ERROR_ACCESS_DENIED is returned.
- ///
- ///
- /// The SetIpNetEntry2 function can also fail because of user account control (UAC) on Windows Vista and later. If an
- /// application that contains this function is executed by a user logged on as a member of the Administrators group other than the
- /// built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
- /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a
- /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced
- /// shell as the built-in Administrator (RunAs administrator) for this function to succeed.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-setipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
- // SetIpNetEntry2( PMIB_IPNET_ROW2 Row );
- [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
- [PInvokeData("netioapi.h", MSDNShortId = "4f423700-f721-44a9-ade3-ea5b5b86e394")]
- public static extern Win32Error SetIpNetEntry2(ref MIB_IPNET_ROW2 Row);
-
///
///
/// The UnenableRouter function decrements the reference count that tracks the number of requests to enable IPv4 forwarding.
@@ -5134,705 +3783,6 @@ namespace Vanara.PInvoke
[PInvokeData("iphlpapi.h", MSDNShortId = "95f0387f-24e8-4382-b78e-e59bcec0f2ed")]
public static extern unsafe Win32Error UnenableRouter(System.Threading.NativeOverlapped* pOverlapped, out uint lpdwEnableCount);
- ///
- /// The FIXED_INFO structure contains information that is the same across all the interfaces on a computer.
- ///
- ///
- /// The FIXED_INFO structure is retrieved by the GetNetworkParams function.
- ///
- /// In the Microsoft Windows Software Development Kit (SDK), the FIXED_INFO_WIN2KSP1 structure is defined. When compiling an
- /// application if the target platform is Windows 2000 with Service Pack 1 (SP1) and later (, , or ), the FIXED_INFO_WIN2KSP1
- /// struct is typedefed to the FIXED_INFO structure. When compiling an application if the target platform is not Windows 2000
- /// with SP1 and later, the FIXED_INFO structure is undefined.
- ///
- ///
- /// The GetNetworkParams function and the FIXED_INFO structure are supported on Windows 98and later. But to build an
- /// application for a target platform earlier than Windows 2000 with Service Pack 1 (SP1), an earlier version of the Platform
- /// Software Development Kit (SDK) must be used.
- ///
- /// Examples
- ///
- /// The following code retrieves a FIXED_INFO structure that contains network configuration information for the local
- /// computer. The code prints selected members from the structure.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-fixed_info_w2ksp1
- // typedef struct FIXED_INFO_W2KSP1 { char HostName[MAX_HOSTNAME_LEN + 4]; char DomainName[MAX_DOMAIN_NAME_LEN + 4]; PIP_ADDR_STRING CurrentDnsServer; IP_ADDR_STRING DnsServerList; UINT NodeType; char ScopeId[MAX_SCOPE_ID_LEN + 4]; UINT EnableRouting; UINT EnableProxy; UINT EnableDns; } *PFIXED_INFO_W2KSP1;
- [PInvokeData("iptypes.h", MSDNShortId = "6dcf33c6-33dc-4583-9b04-5231948d3d9a")]
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
- public struct FIXED_INFO
- {
- ///
- /// Type: char[MAX_HOSTNAME_LEN + 4]
- ///
- /// The hostname for the local computer. This may be the fully qualified hostname (including the domain) for a computer that is
- /// joined to a domain.
- ///
- ///
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_HOSTNAME_LEN + 4)]
- public string HostName;
-
- ///
- /// Type: char[MAX_DOMAIN_NAME_LEN + 4]
- /// The domain in which the local computer is registered.
- ///
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_HOSTNAME_LEN + 4)]
- public string DomainName;
-
- ///
- /// Type: PIP_ADDR_STRING
- /// Reserved. Use the DnsServerList member to obtain the DNS servers for the local computer.
- ///
- public IntPtr CurrentDnsServer;
-
- ///
- /// Type: IP_ADDR_STRING
- /// A linked list of IP_ADDR_STRING structures that specify the set of DNS servers used by the local computer.
- ///
- public IP_ADDR_STRING DnsServerList;
-
- ///
- /// Type: UINT
- /// The node type of the local computer. These values are defined in the Iptypes.h header file.
- ///
- ///
- /// NodeType
- /// Meaning
- ///
- /// -
- /// BROADCAST_NODETYPE 0x0001
- /// A broadcast nodetype.
- ///
- /// -
- /// PEER_TO_PEER_NODETYPE 0x0002
- /// A peer to peer nodetype.
- ///
- /// -
- /// MIXED_NODETYPE 0x0004
- /// A mixed nodetype.
- ///
- /// -
- /// HYBRID_NODETYPE 0x0008
- /// A hybrid nodetype.
- ///
- ///
- ///
- public NetBiosNodeType NodeType;
-
- ///
- /// Type: char[MAX_SCOPE_ID_LEN + 4]
- /// The DHCP scope name.
- ///
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_SCOPE_ID_LEN + 4)]
- public string ScopeId;
-
- ///
- /// Type: UINT
- /// A Boolean value that specifies whether routing is enabled on the local computer.
- ///
- [MarshalAs(UnmanagedType.Bool)]
- public bool EnableRouting;
-
- ///
- /// Type: UINT
- /// A Boolean value that specifies whether the local computer is acting as an ARP proxy.
- ///
- [MarshalAs(UnmanagedType.Bool)]
- public bool EnableProxy;
-
- ///
- /// Type: UINT
- /// A Boolean value that specifies whether DNS is enabled on the local computer.
- ///
- [MarshalAs(UnmanagedType.Bool)]
- public bool EnableDns;
- }
-
- ///
- ///
- /// The IP_ADAPTER_ADDRESSES structure is the header node for a linked list of addresses for a particular adapter. This
- /// structure can simultaneously be used as part of a linked list of IP_ADAPTER_ADDRESSES structures.
- ///
- ///
- ///
- ///
- /// The GetAdaptersAddresses function retrieves information for IPv4 and IPv6 addresses and returns this information as a linked list
- /// of IP_ADAPTER_ADDRESSES structures
- ///
- ///
- /// The adapter index values specified in the IfIndex and Ipv6IfIndex members may change when an adapter is disabled
- /// and then enabled, or under other circumstances, and should not be considered persistent.
- ///
- ///
- /// The values for the IfType member are defined in the Ipifcons.h header file. Only the possible values listed in the
- /// description of the IfType member are currently supported.
- ///
- ///
- /// The size of the IP_ADAPTER_ADDRESSES structure changed on Windows XP with SP1 and later. The size of the
- /// IP_ADAPTER_ADDRESSES structure also changed on Windows Vista and later. The size of the IP_ADAPTER_ADDRESSES
- /// structure also changed on Windows Vista with SP1and later and onWindows Server 2008 and later. The Length member should be
- /// used to determine which version of the IP_ADAPTER_ADDRESSES structure is being used.
- ///
- ///
- /// The version of the IP_ADAPTER_ADDRESSES structure on Windows XP with SP1 and later has the following new members added:
- /// Ipv6IfIndex, ZoneIndices, and FirstPrefix.
- ///
- ///
- /// The version of the IP_ADAPTER_ADDRESSES structure on Windows Vista and later has the following new members added:
- /// TransmitLinkSpeed, ReceiveLinkSpeed, FirstWinsServerAddress, FirstGatewayAddress, Ipv4Metric,
- /// Ipv6Metric, Luid, Dhcpv4Server, CompartmentId, NetworkGuid, ConnectionType,
- /// TunnelType, Dhcpv6Server, Dhcpv6ClientDuid, Dhcpv6ClientDuidLength, and Dhcpv6Iaid.
- ///
- ///
- /// The version of the IP_ADAPTER_ADDRESSES structure on Windows Vista with SP1and later and on Windows Server 2008 and later
- /// has the following new member added: FirstDnsSuffix.
- ///
- ///
- /// The Ipv4Metric and Ipv6Metric members are used to prioritize route metrics for routes connected to multiple
- /// interfaces on the local computer.
- ///
- ///
- /// The order of linked IP_ADAPTER_UNICAST_ADDRESS structures pointed to by the FirstUnicastAddress member that are returned
- /// by the GetAdaptersAddresses function does not reflect the order that IP addresses were added to an adapter and may vary between
- /// versions of Windows. Similarly, the order of linked IP_ADAPTER_ANYCAST_ADDRESS structures pointed to by the
- /// FirstAnycastAddress member and the order of linked IP_ADAPTER_MULTICAST_ADDRESS structures pointed to by the
- /// FirstMulticastAddress member do not reflect the order that IP addresses were added to an adapter and may vary between
- /// versions of Windows.
- ///
- ///
- /// In addition, the linked IP_ADAPTER_UNICAST_ADDRESS structures pointed to by the FirstUnicastAddress member and the linked
- /// IP_ADAPTER_PREFIXstructures pointed to by the FirstPrefix member are maintained as separate internal linked lists by the
- /// operating system. As a result, the order of linked IP_ADAPTER_UNICAST_ADDRESS structures pointed to by the
- /// FirstUnicastAddress member does not have any relationship with the order of linked IP_ADAPTER_PREFIX structures
- /// pointed to by the FirstPrefix member.
- ///
- ///
- /// On Windows Vista and later, the linked IP_ADAPTER_PREFIXstructures pointed to by the FirstPrefix member include three IP
- /// adapter prefixes for each IP address assigned to the adapter. These include the host IP address prefix, the subnet IP address
- /// prefix, and the subnet broadcast IP address prefix. In addition, for each adapter there is a multicast address prefix and a
- /// broadcast address prefix.
- ///
- ///
- /// On Windows XP with SP1 and later prior to Windows Vista, the linked IP_ADAPTER_PREFIXstructures pointed to by the
- /// FirstPrefix member include only a single IP adapter prefix for each IP address assigned to the adapter.
- ///
- ///
- /// In the Windows SDK, the version of the structure for use on Windows Vista and later is defined as IP_ADAPTER_ADDRESSES_LH.
- /// In the Microsoft Windows Software Development Kit (SDK), the version of this structure to be used on earlier systems including
- /// Windows XP with SP1 and later is defined as IP_ADAPTER_ADDRESSES_XP. When compiling an application if the target platform
- /// is Windows Vista and later (, , or ), the IP_ADAPTER_ADDRESSES_LH structure is typedefed to the
- /// IP_ADAPTER_ADDRESSES structure. When compiling an application if the target platform is not Windows Vista and later, the
- /// IP_ADAPTER_ADDRESSES_XP structure is typedefed to the IP_ADAPTER_ADDRESSES structure.
- ///
- ///
- /// The SOCKET_ADDRESS structure is used in the IP_ADAPTER_ADDRESSES structure. On the Windows SDK released for Windows Vista
- /// and later, the organization of header files has changed and the SOCKET_ADDRESS structure is defined in the Ws2def.h header
- /// file which is automatically included by the Winsock2.h header file. On the Platform Software Development Kit (SDK) released for
- /// Windows Server 2003 and Windows XP, the SOCKET_ADDRESS structure is declared in the Winsock2.h header file. In order to
- /// use the IP_ADAPTER_ADDRESSES structure, the Winsock2.h header file must be included before the Iphlpapi.h header file.
- ///
- /// Examples
- ///
- /// This example retrieves the IP_ADAPTER_ADDRESSES structure for the adapters associated with the system and prints some
- /// members for each adapter interface.
- ///
- ///
- // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_adapter_addresses_lh typedef struct
- // _IP_ADAPTER_ADDRESSES_LH { union { ULONGLONG Alignment; struct { ULONG Length; IF_INDEX IfIndex; }; }; struct
- // _IP_ADAPTER_ADDRESSES_LH *Next; PCHAR AdapterName; PIP_ADAPTER_UNICAST_ADDRESS_LH FirstUnicastAddress;
- // PIP_ADAPTER_ANYCAST_ADDRESS_XP FirstAnycastAddress; PIP_ADAPTER_MULTICAST_ADDRESS_XP FirstMulticastAddress;
- // PIP_ADAPTER_DNS_SERVER_ADDRESS_XP FirstDnsServerAddress; PWCHAR DnsSuffix; PWCHAR Description; PWCHAR FriendlyName; BYTE
- // PhysicalAddress[MAX_ADAPTER_ADDRESS_LENGTH]; ULONG PhysicalAddressLength; union { ULONG Flags; struct { ULONG DdnsEnabled : 1;
- // ULONG RegisterAdapterSuffix : 1; ULONG Dhcpv4Enabled : 1; ULONG ReceiveOnly : 1; ULONG NoMulticast : 1; ULONG
- // Ipv6OtherStatefulConfig : 1; ULONG NetbiosOverTcpipEnabled : 1; ULONG Ipv4Enabled : 1; ULONG Ipv6Enabled : 1; ULONG
- // Ipv6ManagedAddressConfigurationSupported : 1; }; }; ULONG Mtu; IFTYPE IfType; IF_OPER_STATUS OperStatus; IF_INDEX Ipv6IfIndex;
- // ULONG ZoneIndices[16]; PIP_ADAPTER_PREFIX_XP FirstPrefix; ULONG64 TransmitLinkSpeed; ULONG64 ReceiveLinkSpeed;
- // PIP_ADAPTER_WINS_SERVER_ADDRESS_LH FirstWinsServerAddress; PIP_ADAPTER_GATEWAY_ADDRESS_LH FirstGatewayAddress; ULONG Ipv4Metric;
- // ULONG Ipv6Metric; IF_LUID Luid; SOCKET_ADDRESS Dhcpv4Server; NET_IF_COMPARTMENT_ID CompartmentId; NET_IF_NETWORK_GUID NetworkGuid;
- // NET_IF_CONNECTION_TYPE ConnectionType; TUNNEL_TYPE TunnelType; SOCKET_ADDRESS Dhcpv6Server; BYTE
- // Dhcpv6ClientDuid[MAX_DHCPV6_DUID_LENGTH]; ULONG Dhcpv6ClientDuidLength; ULONG Dhcpv6Iaid; PIP_ADAPTER_DNS_SUFFIX FirstDnsSuffix; }
- // IP_ADAPTER_ADDRESSES_LH, *PIP_ADAPTER_ADDRESSES_LH;
- [PInvokeData("iptypes.h", MSDNShortId = "a2df3749-6c75-40c0-8952-1656bbe639a6")]
- [StructLayout(LayoutKind.Sequential)]
- public struct IP_ADAPTER_ADDRESSES
- {
- public uint Length;
- public uint IfIndex;
- ///
- /// Type: struct _IP_ADAPTER_ADDRESSES*
- /// A pointer to the next adapter addresses structure in the list.
- ///
- public IntPtr Next;
-
- ///
- /// Type: PCHAR
- ///
- /// An array of characters that contains the name of the adapter with which these addresses are associated. Unlike an adapter's
- /// friendly name, the adapter name specified in AdapterName is permanent and cannot be modified by the user.
- ///
- ///
- [MarshalAs(UnmanagedType.LPStr)]
- public string AdapterName;
-
- ///
- /// Type: PIP_ADAPTER_UNICAST_ADDRESS
- /// A pointer to the first IP_ADAPTER_UNICAST_ADDRESS structure in a linked list of IP unicast addresses for the adapter.
- ///
- public IntPtr FirstUnicastAddress;
- ///
- /// Type: PIP_ADAPTER_ANYCAST_ADDRESS
- /// A pointer to the first IP_ADAPTER_ANYCAST_ADDRESS structure in a linked list of IP anycast addresses for the adapter.
- ///
- public IntPtr FirstAnycastAddress;
- ///
- /// Type: PIP_ADAPTER_MULTICAST_ADDRESS
- /// A pointer to the first IP_ADAPTER_MULTICAST_ADDRESS structure in a list of IP multicast addresses for the adapter.
- ///
- public IntPtr FirstMulticastAddress;
- ///
- /// Type: PIP_ADAPTER_DNS_SERVER_ADDRESS
- /// A pointer to the first IP_ADAPTER_DNS_SERVER_ADDRESS structure in a linked list of DNS server addresses for the adapter.
- ///
- public IntPtr FirstDnsServerAddress;
-
- ///
- /// Type: PWCHAR
- /// The Domain Name System (DNS) suffix associated with this adapter.
- ///
- [MarshalAs(UnmanagedType.LPWStr)]
- public string DnsSuffix;
-
- ///
- /// Type: PWCHAR
- /// A description for the adapter. This member is read-only.
- ///
- [MarshalAs(UnmanagedType.LPWStr)]
- public string Description;
-
- ///
- /// Type: PWCHAR
- ///
- /// A user-friendly name for the adapter. For example: "Local Area Connection 1." This name appears in contexts such as the
- /// ipconfig command line program and the Connection folder. This member is read only and can't be modified using any IP
- /// Helper functions.
- ///
- ///
- /// This member is the ifAlias field used by NDIS as described in RFC 2863. The ifAlias field can be set by an NDIS interface
- /// provider when the NDIS driver is installed. For NDIS miniport drivers, this field is set by NDIS.
- ///
- ///
- [MarshalAs(UnmanagedType.LPWStr)]
- public string FriendlyName;
-
- ///
- /// Type: BYTE[MAX_ADAPTER_ADDRESS_LENGTH]
- ///
- /// The Media Access Control (MAC) address for the adapter. For example, on an Ethernet network this member would specify the
- /// Ethernet hardware address.
- ///
- ///
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_ADAPTER_ADDRESS_LENGTH)]
- public byte[] PhysicalAddress;
-
- ///
- /// Type: DWORD
- ///
- /// The length, in bytes, of the address specified in the PhysicalAddress member. For interfaces that do not have a
- /// data-link layer, this value is zero.
- ///
- ///
- public uint PhysicalAddressLength;
- public IP_ADAPTER_FLAGS Flags;
- ///
- /// Type: DWORD
- /// The maximum transmission unit (MTU) size, in bytes.
- ///
- public uint Mtu;
- ///
- /// Type: DWORD
- ///
- /// The interface type as defined by the Internet Assigned Names Authority (IANA). Possible values for the interface type are
- /// listed in the Ipifcons.h header file.
- ///
- /// The table below lists common values for the interface type although many other values are possible.
- ///
- ///
- /// Value
- /// Meaning
- ///
- /// -
- /// IF_TYPE_OTHER 1
- /// Some other type of network interface.
- ///
- /// -
- /// IF_TYPE_ETHERNET_CSMACD 6
- /// An Ethernet network interface.
- ///
- /// -
- /// IF_TYPE_ISO88025_TOKENRING 9
- /// A token ring network interface.
- ///
- /// -
- /// IF_TYPE_PPP 23
- /// A PPP network interface.
- ///
- /// -
- /// IF_TYPE_SOFTWARE_LOOPBACK 24
- /// A software loopback network interface.
- ///
- /// -
- /// IF_TYPE_ATM 37
- /// An ATM network interface.
- ///
- /// -
- /// IF_TYPE_IEEE80211 71
- ///
- /// An IEEE 802.11 wireless network interface. On Windows Vista and later, wireless network cards are reported as
- /// IF_TYPE_IEEE80211. On earlier versions of Windows, wireless network cards are reported as IF_TYPE_ETHERNET_CSMACD. On Windows
- /// XP with SP3 and on Windows XP with SP2 x86 with the Wireless LAN API for Windows XP with SP2 installed, the
- /// WlanEnumInterfaces function can be used to enumerate wireless interfaces on the local computer.
- ///
- ///
- /// -
- /// IF_TYPE_TUNNEL 131
- /// A tunnel type encapsulation network interface.
- ///
- /// -
- /// IF_TYPE_IEEE1394 144
- /// An IEEE 1394 (Firewire) high performance serial bus network interface.
- ///
- ///
- ///
- public IFTYPE IfType;
- ///
- /// Type: IF_OPER_STATUS
- ///
- /// The operational status for the interface as defined in RFC 2863. For more information, see
- /// http://www.ietf.org/rfc/rfc2863.txt. This member can be one of the values from the IF_OPER_STATUS enumeration type
- /// defined in the Iftypes.h header file. On Windows Vista and later, the header files were reorganized and this enumeration is
- /// defined in the Ifdef.h header file.
- ///
- ///
- ///
- /// Value
- /// Meaning
- ///
- /// -
- /// IfOperStatusUp 1
- /// The interface is up and able to pass packets.
- ///
- /// -
- /// IfOperStatusDown 2
- ///
- /// The interface is down and not in a condition to pass packets. The IfOperStatusDown state has two meanings, depending on the
- /// value of AdminStatus member. If AdminStatus is not set to NET_IF_ADMIN_STATUS_DOWN and ifOperStatus is set to
- /// IfOperStatusDown then a fault condition is presumed to exist on the interface. If AdminStatus is set to IfOperStatusDown,
- /// then ifOperStatus will normally also be set to IfOperStatusDown or IfOperStatusNotPresent and there is not necessarily a
- /// fault condition on the interface.
- ///
- ///
- /// -
- /// IfOperStatusTesting 3
- /// The interface is in testing mode.
- ///
- /// -
- /// IfOperStatusUnknown 4
- /// The operational status of the interface is unknown.
- ///
- /// -
- /// IfOperStatusDormant 5
- ///
- /// The interface is not actually in a condition to pass packets (it is not up), but is in a pending state, waiting for some
- /// external event. For on-demand interfaces, this new state identifies the situation where the interface is waiting for events
- /// to place it in the IfOperStatusUp state.
- ///
- ///
- /// -
- /// IfOperStatusNotPresent 6
- ///
- /// A refinement on the IfOperStatusDown state which indicates that the relevant interface is down specifically because some
- /// component (typically, a hardware component) is not present in the managed system.
- ///
- ///
- /// -
- /// IfOperStatusLowerLayerDown 7
- ///
- /// A refinement on the IfOperStatusDown state. This new state indicates that this interface runs on top of one or more other
- /// interfaces and that this interface is down specifically because one or more of these lower-layer interfaces are down.
- ///
- ///
- ///
- ///
- public IF_OPER_STATUS OperStatus;
- ///
- /// Type: DWORD
- /// The interface index for the IPv6 IP address. This member is zero if IPv6 is not available on the interface.
- /// Note This structure member is only available on Windows XP with SP1 and later.
- ///
- private readonly uint Ipv6IfIndex;
-
- ///
- /// Type: DWORD[16]
- ///
- /// An array of scope IDs for each scope level used for composing sockaddr structures. The SCOPE_LEVEL enumeration is used to
- /// index the array. On IPv6, a single interface may be assigned multiple IPv6 multicast addresses based on a scope ID.
- ///
- /// Note This structure member is only available on Windows XP with SP1 and later.
- ///
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
- public SCOPE_LEVEL[] ZoneIndices;
-
- ///
- /// Type: PIP_ADAPTER_PREFIX
- /// A pointer to the first IP_ADAPTER_PREFIX structure in a linked list of IP adapter prefixes for the adapter.
- /// Note This structure member is only available on Windows XP with SP1 and later.
- ///
- public IntPtr FirstPrefix;
- ///
- /// Type: ULONG64
- /// The current speed in bits per second of the transmit link for the adapter.
- /// Note This structure member is only available on Windows Vista and later.
- ///
- public ulong TrasmitLinkSpeed;
- ///
- /// Type: ULONG64
- /// The current speed in bits per second of the receive link for the adapter.
- /// Note This structure member is only available on Windows Vista and later.
- ///
- public ulong ReceiveLinkSpeed;
- ///
- /// Type: PIP_ADAPTER_WINS_SERVER_ADDRESS_LH
- ///
- /// A pointer to the first IP_ADAPTER_WINS_SERVER_ADDRESS structure in a linked list of Windows Internet Name Service (WINS)
- /// server addresses for the adapter.
- ///
- /// Note This structure member is only available on Windows Vista and later.
- ///
- public IntPtr FirstWinsServerAddress;
- ///
- /// Type: PIP_ADAPTER_GATEWAY_ADDRESS_LH
- /// A pointer to the first IP_ADAPTER_GATEWAY_ADDRESS structure in a linked list of gateways for the adapter.
- /// Note This structure member is only available on Windows Vista and later.
- ///
- public IntPtr FirstGatewayAddress;
- ///
- /// Type: ULONG
- /// The IPv4 interface metric for the adapter address. This member is only applicable to an IPv4 adapter address.
- ///
- /// The actual route metric used to compute the route preferences for IPv4 is the summation of the route metric offset specified
- /// in the Metric member of the MIB_IPFORWARD_ROW2 structure and the interface metric specified in this member for IPv4.
- ///
- /// Note This structure member is only available on Windows Vista and later.
- ///
- public uint Ipv4Metric;
- ///
- /// Type: ULONG
- /// The IPv6 interface metric for the adapter address. This member is only applicable to an IPv6 adapter address.
- ///
- /// The actual route metric used to compute the route preferences for IPv6 is the summation of the route metric offset specified
- /// in the Metric member of the MIB_IPFORWARD_ROW2 structure and the interface metric specified in this member for IPv4.
- ///
- /// Note This structure member is only available on Windows Vista and later.
- ///
- public uint Ipv6Metric;
- ///
- /// Type: IF_LUID
- /// The interface LUID for the adapter address.
- /// Note This structure member is only available on Windows Vista and later.
- ///
- public NET_LUID Luid;
- ///
- /// Type: SOCKET_ADDRESS
- ///
- /// The IPv4 address of the DHCP server for the adapter address. This member is only applicable to an IPv4 adapter address
- /// configured using DHCP.
- ///
- /// Note This structure member is only available on Windows Vista and later.
- ///
- public SOCKET_ADDRESS Dhcpv4Server;
- ///
- /// Type: NET_IF_COMPARTMENT_ID
- /// The routing compartment ID for the adapter address.
- ///
- /// Note This structure member is only available on Windows Vista and later. This member is not currently supported and is
- /// reserved for future use.
- ///
- ///
- public uint CompartmentId;
- ///
- /// Type: NET_IF_NETWORK_GUID
- /// The GUID that is associated with the network that the interface belongs to.
- ///
- /// If the interface provider cannot provide the network GUID, this member can be a zero GUID. In this case, the interface
- /// was registered by NDIS in the default network.
- ///
- /// Note This structure member is only available on Windows Vista and later.
- ///
- public Guid NetworkGuid;
- ///
- /// Type: NET_IF_CONNECTION_TYPE
- /// The interface connection type for the adapter address.
- ///
- /// This member can be one of the values from the NET_IF_CONNECTION_TYPE enumeration type defined in the Ifdef.h header file.
- ///
- ///
- ///
- /// Value
- /// Meaning
- ///
- /// -
- /// NET_IF_CONNECTION_DEDICATED 1
- ///
- /// The connection type is dedicated. The connection comes up automatically when media sense is TRUE. For example, an Ethernet
- /// connection is dedicated.
- ///
- ///
- /// -
- /// NET_IF_CONNECTION_PASSIVE 2
- ///
- /// The connection type is passive. The remote end must bring up the connection to the local station. For example, a RAS
- /// interface is passive.
- ///
- ///
- /// -
- /// NET_IF_CONNECTION_DEMAND 3
- ///
- /// The connection type is demand-dial. A connection of this type comes up in response to a local action (sending a packet, for example).
- ///
- ///
- /// -
- /// NET_IF_CONNECTION_MAXIMUM 4
- ///
- /// The maximum possible value for the NET_IF_CONNECTION_TYPE enumeration type. This is not a legal value for ConnectionType member.
- ///
- ///
- ///
- /// Note This structure member is only available on Windows Vista and later.
- ///
- public NET_IF_CONNECTION_TYPE ConnectionType;
- ///
- /// Type: TUNNEL_TYPE
- /// The encapsulation method used by a tunnel if the adapter address is a tunnel.
- /// Note This structure member is only available on Windows Vista and later.
- /// The tunnel type is defined by the Internet Assigned Names Authority (IANA). For more information, see
- /// http://www.iana.org/assignments/ianaiftype-mib
- /// . This member can be one of the values from the
- /// TUNNEL_TYPE
- /// enumeration type defined in the
- /// Ifdef.h
- /// header file.
- ///
- ///
- /// Value
- /// Meaning
- ///
- /// -
- /// TUNNEL_TYPE_NONE 0
- /// Not a tunnel.
- ///
- /// -
- /// TUNNEL_TYPE_OTHER 1
- /// None of the following tunnel types.
- ///
- /// -
- /// TUNNEL_TYPE_DIRECT 2
- ///
- /// A packet is encapsulated directly within a normal IP header, with no intermediate header, and unicast to the remote tunnel endpoint.
- ///
- ///
- /// -
- /// TUNNEL_TYPE_6TO4 11
- ///
- /// An IPv6 packet is encapsulated directly within an IPv4 header, with no intermediate header, and unicast to the destination
- /// determined by the 6to4 protocol.
- ///
- ///
- /// -
- /// TUNNEL_TYPE_ISATAP 13
- ///
- /// An IPv6 packet is encapsulated directly within an IPv4 header, with no intermediate header, and unicast to the destination
- /// determined by the ISATAP protocol.
- ///
- ///
- /// -
- /// TUNNEL_TYPE_TEREDO 14
- /// Teredo encapsulation for IPv6 packets.
- ///
- /// -
- /// TUNNEL_TYPE_IPHTTPS 15
- /// IP over HTTPS encapsulation for IPv6 packets.
- ///
- ///
- ///
- public TUNNEL_TYPE TunnelType;
- ///
- /// Type: SOCKET_ADDRESS
- ///
- /// The IPv6 address of the DHCPv6 server for the adapter address. This member is only applicable to an IPv6 adapter address
- /// configured using DHCPv6. This structure member is not currently supported and is reserved for future use.
- ///
- /// Note This structure member is only available on Windows Vista and later.
- ///
- public SOCKET_ADDRESS Dhcpv6Server;
-
- ///
- /// Type: BYTE[MAX_DHCPV6_DUID_LENGTH]
- ///
- /// The DHCP unique identifier (DUID) for the DHCPv6 client. This member is only applicable to an IPv6 adapter address configured
- /// using DHCPv6.
- ///
- /// Note This structure member is only available on Windows Vista and later.
- ///
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_DHCPV6_DUID_LENGTH)]
- public byte[] Dhcpv6ClientDuid;
-
- ///
- /// Type: ULONG
- ///
- /// The length, in bytes, of the DHCP unique identifier (DUID) for the DHCPv6 client. This member is only applicable to an IPv6
- /// adapter address configured using DHCPv6.
- ///
- /// Note This structure member is only available on Windows Vista and later.
- ///
- public uint Dhcpv6ClientDuidLength;
- ///
- /// Type: ULONG
- ///
- /// The identifier for an identity association chosen by the DHCPv6 client. This member is only applicable to an IPv6 adapter
- /// address configured using DHCPv6.
- ///
- /// Note This structure member is only available on Windows Vista and later.
- ///
- public uint Dhcpv6Iaid;
- ///
- /// Type: PIP_ADAPTER_DNS_SUFFIX
- /// A pointer to the first IP_ADAPTER_DNS_SUFFIX structure in a linked list of DNS suffixes for the adapter.
- ///
- /// Note This structure member is only available on Windows Vista with SP1and later and on Windows Server 2008 and later.
- ///
- ///
- public IntPtr FirstDnsSuffix;
-
- public IEnumerable UnicastAddresses => FirstUnicastAddress.LinkedListToIEnum(t => t.Next);
- public IEnumerable AnycastAddresses => FirstAnycastAddress.LinkedListToIEnum(t => t.Next);
- public IEnumerable MulticastAddresses => FirstMulticastAddress.LinkedListToIEnum(t => t.Next);
- public IEnumerable DnsServerAddresses => FirstDnsServerAddress.LinkedListToIEnum(t => t.Next);
- public IEnumerable Prefixes => FirstPrefix.LinkedListToIEnum(t => t.Next);
- public IEnumerable WinsServerAddresses => FirstWinsServerAddress.LinkedListToIEnum(t => t.Next);
- public IEnumerable GatewayAddresses => FirstGatewayAddress.LinkedListToIEnum(t => t.Next);
- public IEnumerable DnsSuffixes => FirstDnsSuffix.LinkedListToIEnum(t => t.Next);
-
- public IP_ADAPTER_ADDRESSES? GetNext()
- {
- return Next.ToNullableStructure();
- }
-
- public static IEnumerable ListFromPtr(IntPtr ptr)
- {
- return ptr.LinkedListToIEnum(t => t.Next);
- }
- }
-
[PInvokeData("IpHlpApi.h")]
[StructLayout(LayoutKind.Sequential)]
public struct IP_ADAPTER_ANYCAST_ADDRESS
@@ -6021,205 +3971,6 @@ namespace Vanara.PInvoke
}
}
- /// The MIB_IF_ROW2 structure stores information about a particular interface.
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- public struct MIB_IF_ROW2
- {
- /// The locally unique identifier (LUID) for the network interface.
- public NET_LUID InterfaceLuid;
-
- ///
- /// The index that identifies the network interface. This index value may change when a network adapter is disabled and then
- /// enabled, and should not be considered persistent.
- ///
- public uint InterfaceIndex;
-
- /// The GUID for the network interface.
- public Guid InterfaceGuid;
-
- /// A NULL-terminated Unicode string that contains the alias name of the network interface.
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = IF_MAX_STRING_SIZE + 1)]
- public string Alias;
-
- /// A NULL-terminated Unicode string that contains a description of the network interface.
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = IF_MAX_STRING_SIZE + 1)]
- public string Description;
-
- /// The length, in bytes, of the physical hardware address specified by the PhysicalAddress member.
- public uint physicalAddressLength;
-
- /// The physical hardware address of the adapter for this network interface.
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = IF_MAX_PHYS_ADDRESS_LENGTH)]
- public byte[] PhysicalAddress;
-
- /// The permanent physical hardware address of the adapter for this network interface.
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = IF_MAX_PHYS_ADDRESS_LENGTH)]
- public byte[] PermanentPhysicalAddress;
-
- /// The maximum transmission unit (MTU) size, in bytes, for this network interface.
- public uint Mtu;
-
- ///
- /// The interface type as defined by the Internet Assigned Names Authority (IANA). For more information, see
- /// http://www.iana.org/assignments/ianaiftype-mib. Possible values for the interface type are listed in the Ipifcons.h header file.
- ///
- public IFTYPE Type;
-
- ///
- /// The encapsulation method used by a tunnel if the Type member is IF_TYPE_TUNNEL. The tunnel type is defined by the Internet
- /// Assigned Names Authority (IANA). For more information, see http://www.iana.org/assignments/ianaiftype-mib. This member can be
- /// one of the values from the TUNNEL_TYPE enumeration type defined in the Ifdef.h header file.
- ///
- public TUNNEL_TYPE TunnelType;
-
- ///
- /// The NDIS media type for the interface. This member can be one of the values from the NDIS_MEDIUM enumeration type defined in
- /// the Ntddndis.h header file.
- ///
- public NDIS_MEDIUM MediaType;
-
- ///
- /// The NDIS physical medium type. This member can be one of the values from the NDIS_PHYSICAL_MEDIUM enumeration type defined in
- /// the Ntddndis.h header file.
- ///
- public NDIS_PHYSICAL_MEDIUM PhysicalMediumType;
-
- ///
- /// The interface access type. This member can be one of the values from the NET_IF_ACCESS_TYPE enumeration type defined in the
- /// Ifdef.h header file.
- ///
- public NET_IF_ACCESS_TYPE AccessType;
-
- ///
- /// The interface direction type. This member can be one of the values from the NET_IF_DIRECTION_TYPE enumeration type defined in
- /// the Ifdef.h header file.
- ///
- public NET_IF_DIRECTION_TYPE DirectionType;
-
- ///
- /// A set of flags that provide information about the interface. These flags are combined with a bitwise OR operation. If none of
- /// the flags applies, then this member is set to zero.
- ///
- public InterfaceAndOperStatusFlags InterfaceAndOperStatusFlags;
-
- ///
- /// The operational status for the interface as defined in RFC 2863 as IfOperStatus. For more information, see
- /// http://www.ietf.org/rfc/rfc2863.txt. This member can be one of the values from the IF_OPER_STATUS enumeration type defined in
- /// the Ifdef.h header file.
- ///
- public IF_OPER_STATUS OperStatus;
-
- ///
- /// The administrative status for the interface as defined in RFC 2863. For more information, see
- /// http://www.ietf.org/rfc/rfc2863.txt. This member can be one of the values from the NET_IF_ADMIN_STATUS enumeration type
- /// defined in the Ifdef.h header file.
- ///
- public NET_IF_ADMIN_STATUS AdminStatus;
-
- ///
- /// The connection state of the interface. This member can be one of the values from the NET_IF_MEDIA_CONNECT_STATE enumeration
- /// type defined in the Ifdef.h header file.
- ///
- public NET_IF_MEDIA_CONNECT_STATE MediaConnectState;
-
- /// The GUID that is associated with the network that the interface belongs to.
- public Guid NetworkGuid;
-
- ///
- /// The NDIS network interface connection type. This member can be one of the values from the NET_IF_CONNECTION_TYPE enumeration
- /// type defined in the Ifdef.h header file.
- ///
- public NET_IF_CONNECTION_TYPE ConnectionType;
-
- /// The speed in bits per second of the transmit link.
- public ulong TransmitLinkSpeed;
-
- /// The speed in bits per second of the receive link.
- public ulong ReceiveLinkSpeed;
-
- ///
- /// The number of octets of data received without errors through this interface. This value includes octets in unicast,
- /// broadcast, and multicast packets.
- ///
- public ulong InOctets;
-
- /// The number of unicast packets received without errors through this interface.
- public ulong InUcastPkts;
-
- ///
- /// The number of non-unicast packets received without errors through this interface. This value includes broadcast and multicast packets.
- ///
- public ulong InNUcastPkts;
-
- ///
- /// The number of inbound packets which were chosen to be discarded even though no errors were detected to prevent the packets
- /// from being deliverable to a higher-layer protocol.
- ///
- public ulong InDiscards;
-
- /// The number of incoming packets that were discarded because of errors.
- public ulong InErrors;
-
- /// The number of incoming packets that were discarded because the protocol was unknown.
- public ulong InUnknownProtos;
-
- /// The number of octets of data received without errors in unicast packets through this interface.
- public ulong InUcastOctets;
-
- /// The number of octets of data received without errors in multicast packets through this interface.
- public ulong InMulticastOctets;
-
- /// The number of octets of data received without errors in broadcast packets through this interface.
- public ulong InBroadcastOctets;
-
- ///
- /// The number of octets of data transmitted without errors through this interface. This value includes octets in unicast,
- /// broadcast, and multicast packets.
- ///
- public ulong OutOctets;
-
- /// The number of unicast packets transmitted without errors through this interface.
- public ulong OutUcastPkts;
-
- ///
- /// The number of non-unicast packets transmitted without errors through this interface. This value includes broadcast and
- /// multicast packets.
- ///
- public ulong OutNUcastPkts;
-
- /// The number of outgoing packets that were discarded even though they did not have errors.
- public ulong OutDiscards;
-
- /// The number of outgoing packets that were discarded because of errors.
- public ulong OutErrors;
-
- /// The number of octets of data transmitted without errors in unicast packets through this interface.
- public ulong OutUcastOctets;
-
- /// The number of octets of data transmitted without errors in multicast packets through this interface.
- public ulong OutMulticastOctets;
-
- /// The number of octets of data transmitted without errors in broadcast packets through this interface.
- public ulong OutBroadcastOctets;
-
- /// The transmit queue length. This field is not currently used.
- public ulong OutQLen;
-
- /// Initializes a new instance of the struct.
- /// Index of the interface.
- public MIB_IF_ROW2(uint interfaceIndex) : this()
- {
- InterfaceIndex = interfaceIndex;
- }
-
- /// Initializes a new instance of the struct.
- /// The interface luid.
- public MIB_IF_ROW2(NET_LUID interfaceLuid) : this()
- {
- InterfaceLuid = interfaceLuid;
- }
- }
-
[PInvokeData("IpHlpApi.h")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MIB_IFROW
@@ -6270,27 +4021,6 @@ namespace Vanara.PInvoke
public MIB_IPADDRTYPE wType;
}
- [PInvokeData("IpHlpApi.h")]
- [StructLayout(LayoutKind.Sequential, Pack = 1)]
- public struct MIB_IPFORWARD_ROW2
- {
- public NET_LUID InterfaceLuid;
- public uint InterfaceIndex;
- public IP_ADDRESS_PREFIX DestinationPrefix;
- public SOCKADDR_INET NextHop;
- public byte SitePrefixLength;
- public uint ValidLifetime;
- public uint PreferredLifetime;
- public uint Metric;
- public MIB_IPPROTOCOL Protocol;
- public byte Loopback;
- public byte AutoconfigureAddress;
- public byte Publish;
- public byte Immortal;
- public uint Age;
- public NL_ROUTE_ORIGIN Origin;
- }
-
[PInvokeData("IpHlpApi.h")]
[StructLayout(LayoutKind.Sequential)]
public struct MIB_IPFORWARDROW
@@ -6311,74 +4041,6 @@ namespace Vanara.PInvoke
public uint dwForwardMetric5;
}
- ///
- /// The MIB_IPNETROW structure contains information for an Address Resolution Protocol (ARP) table entry for an IPv4 address.
- ///
- [PInvokeData("IpHlpApi.h")]
- [StructLayout(LayoutKind.Sequential, Pack = 2)]
- public struct MIB_IPNET_ROW2
- {
- public SOCKADDR_INET Address;
- public uint InterfaceIndex;
- public NET_LUID InterfaceLuid;
-
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = IF_MAX_PHYS_ADDRESS_LENGTH)]
- public byte[] PhysicalAddress;
-
- public uint PhysicalAddressLength;
- public NL_NEIGHBOR_STATE State;
- public MIB_IPNET_ROW2_FLAGS Flags;
- public uint ReachabilityTime;
-
- private MIB_IPNET_ROW2(SOCKADDR_IN ipV4, byte[] macAddr) : this()
- {
- Address.Ipv4 = ipV4;
- SetMac(macAddr);
- }
-
- public MIB_IPNET_ROW2(SOCKADDR_IN ipV4, NET_LUID ifLuid, byte[] macAddr = null) : this(ipV4, macAddr)
- {
- InterfaceLuid = ifLuid;
- }
-
- public MIB_IPNET_ROW2(SOCKADDR_IN ipV4, uint ifIdx, byte[] macAddr = null) : this(ipV4, macAddr)
- {
- InterfaceIndex = ifIdx;
- }
-
- private MIB_IPNET_ROW2(SOCKADDR_IN6 ipV6, byte[] macAddr) : this()
- {
- Address.Ipv6 = ipV6;
- SetMac(macAddr);
- }
-
- public MIB_IPNET_ROW2(SOCKADDR_IN6 ipV6, NET_LUID ifLuid, byte[] macAddr = null) : this(ipV6, macAddr)
- {
- InterfaceLuid = ifLuid;
- }
-
- public MIB_IPNET_ROW2(SOCKADDR_IN6 ipV6, uint ifIdx, byte[] macAddr = null) : this(ipV6, macAddr)
- {
- InterfaceIndex = ifIdx;
- }
-
- private void SetMac(byte[] macAddr)
- {
- if (macAddr == null)
- {
- return;
- }
-
- PhysicalAddressLength = IF_MAX_PHYS_ADDRESS_LENGTH;
- PhysicalAddress = new byte[IF_MAX_PHYS_ADDRESS_LENGTH];
- Array.Copy(macAddr, PhysicalAddress, 6);
- }
-
- public override string ToString()
- {
- return $"{Address}; MAC:{PhysicalAddressToString(PhysicalAddress)}; If:{(InterfaceIndex != 0 ? InterfaceIndex.ToString() : InterfaceLuid.ToString())}";
- }
- }
///
/// The MIB_IPNETROW structure contains information for an Address Resolution Protocol (ARP) table entry for an IPv4 address.
@@ -6688,39 +4350,6 @@ namespace Vanara.PInvoke
}
}
- /// The MIB_IF_TABLE2 structure contains a table of logical and physical interface entries.
- [PInvokeData("IpHlpApi.h")]
- [CorrespondingType(typeof(MIB_IF_ROW2))]
- [DefaultProperty(nameof(Elements))]
- public class MIB_IF_TABLE2 : GenericSafeHandle, IEnumerable
- {
- /// Initializes a new instance of the class.
- public MIB_IF_TABLE2() : base(Free) { }
-
- /// Gets the array of MIB_IF_ROW2 structures containing interface entries.
- /// An array of MIB_IF_ROW2 structures containing interface entries.
- public MIB_IF_ROW2[] Elements => handle.ToArray((int)NumEntries, Marshal.SizeOf(typeof(ulong)));
-
- /// Gets the number of interface entries in the array.
- /// The number of interface entries in the array.
- public uint NumEntries => IsInvalid ? 0 : handle.ToStructure();
-
- public IEnumerator GetEnumerator()
- {
- return ((IEnumerable)Elements).GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- private static bool Free(IntPtr handle)
- {
- FreeMibTable(handle); return true;
- }
- }
-
[PInvokeData("IpHlpApi.h")]
[CorrespondingType(typeof(MIB_IFROW))]
[DefaultProperty(nameof(table))]
@@ -6757,39 +4386,6 @@ namespace Vanara.PInvoke
}
}
- /// The MIB_IPNET_TABLE2 structure contains a table of neighbor IP address entries.
- [PInvokeData("IpHlpApi.h")]
- [CorrespondingType(typeof(MIB_IPNET_ROW2))]
- [DefaultProperty(nameof(Elements))]
- public class MIB_IPNET_TABLE2 : GenericSafeHandle, IEnumerable
- {
- /// Initializes a new instance of the class.
- public MIB_IPNET_TABLE2() : base(Free) { }
-
- /// Gets the array of MIB_IF_ROW2 structures containing interface entries.
- /// An array of MIB_IF_ROW2 structures containing interface entries.
- public MIB_IPNET_ROW2[] Elements => handle.ToArray((int)NumEntries, Marshal.SizeOf(typeof(ulong)));
-
- /// Gets the number of interface entries in the array.
- /// The number of interface entries in the array.
- public uint NumEntries => IsInvalid ? 0 : handle.ToStructure();
-
- public IEnumerator GetEnumerator()
- {
- return ((IEnumerable)Elements).GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- private static bool Free(IntPtr handle)
- {
- FreeMibTable(handle); return true;
- }
- }
-
[PInvokeData("IpHlpApi.h")]
[CorrespondingType(typeof(MIB_IPNETROW))]
[DefaultProperty(nameof(table))]
diff --git a/PInvoke/IpHlpApi/IpTypes.cs b/PInvoke/IpHlpApi/IpTypes.cs
new file mode 100644
index 00000000..9fba36cf
--- /dev/null
+++ b/PInvoke/IpHlpApi/IpTypes.cs
@@ -0,0 +1,734 @@
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using Vanara.Extensions;
+
+namespace Vanara.PInvoke
+{
+ public static partial class IpHlpApi
+ {
+ ///
+ /// The FIXED_INFO structure contains information that is the same across all the interfaces on a computer.
+ ///
+ ///
+ /// The FIXED_INFO structure is retrieved by the GetNetworkParams function.
+ ///
+ /// In the Microsoft Windows Software Development Kit (SDK), the FIXED_INFO_WIN2KSP1 structure is defined. When compiling an
+ /// application if the target platform is Windows 2000 with Service Pack 1 (SP1) and later (, , or ), the FIXED_INFO_WIN2KSP1
+ /// struct is typedefed to the FIXED_INFO structure. When compiling an application if the target platform is not Windows 2000
+ /// with SP1 and later, the FIXED_INFO structure is undefined.
+ ///
+ ///
+ /// The GetNetworkParams function and the FIXED_INFO structure are supported on Windows 98and later. But to build an
+ /// application for a target platform earlier than Windows 2000 with Service Pack 1 (SP1), an earlier version of the Platform
+ /// Software Development Kit (SDK) must be used.
+ ///
+ /// Examples
+ ///
+ /// The following code retrieves a FIXED_INFO structure that contains network configuration information for the local
+ /// computer. The code prints selected members from the structure.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-fixed_info_w2ksp1 typedef struct FIXED_INFO_W2KSP1 { char
+ // HostName[MAX_HOSTNAME_LEN + 4]; char DomainName[MAX_DOMAIN_NAME_LEN + 4]; PIP_ADDR_STRING CurrentDnsServer; IP_ADDR_STRING
+ // DnsServerList; UINT NodeType; char ScopeId[MAX_SCOPE_ID_LEN + 4]; UINT EnableRouting; UINT EnableProxy; UINT EnableDns; } *PFIXED_INFO_W2KSP1;
+ [PInvokeData("iptypes.h", MSDNShortId = "6dcf33c6-33dc-4583-9b04-5231948d3d9a")]
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
+ public struct FIXED_INFO
+ {
+ ///
+ /// Type: char[MAX_HOSTNAME_LEN + 4]
+ ///
+ /// The hostname for the local computer. This may be the fully qualified hostname (including the domain) for a computer that is
+ /// joined to a domain.
+ ///
+ ///
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_HOSTNAME_LEN + 4)]
+ public string HostName;
+
+ ///
+ /// Type: char[MAX_DOMAIN_NAME_LEN + 4]
+ /// The domain in which the local computer is registered.
+ ///
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_HOSTNAME_LEN + 4)]
+ public string DomainName;
+
+ ///
+ /// Type: PIP_ADDR_STRING
+ /// Reserved. Use the DnsServerList member to obtain the DNS servers for the local computer.
+ ///
+ public IntPtr CurrentDnsServer;
+
+ ///
+ /// Type: IP_ADDR_STRING
+ /// A linked list of IP_ADDR_STRING structures that specify the set of DNS servers used by the local computer.
+ ///
+ public IP_ADDR_STRING DnsServerList;
+
+ ///
+ /// Type: UINT
+ /// The node type of the local computer. These values are defined in the Iptypes.h header file.
+ ///
+ ///
+ /// NodeType
+ /// Meaning
+ ///
+ /// -
+ /// BROADCAST_NODETYPE 0x0001
+ /// A broadcast nodetype.
+ ///
+ /// -
+ /// PEER_TO_PEER_NODETYPE 0x0002
+ /// A peer to peer nodetype.
+ ///
+ /// -
+ /// MIXED_NODETYPE 0x0004
+ /// A mixed nodetype.
+ ///
+ /// -
+ /// HYBRID_NODETYPE 0x0008
+ /// A hybrid nodetype.
+ ///
+ ///
+ ///
+ public NetBiosNodeType NodeType;
+
+ ///
+ /// Type: char[MAX_SCOPE_ID_LEN + 4]
+ /// The DHCP scope name.
+ ///
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_SCOPE_ID_LEN + 4)]
+ public string ScopeId;
+
+ ///
+ /// Type: UINT
+ /// A Boolean value that specifies whether routing is enabled on the local computer.
+ ///
+ [MarshalAs(UnmanagedType.Bool)]
+ public bool EnableRouting;
+
+ ///
+ /// Type: UINT
+ /// A Boolean value that specifies whether the local computer is acting as an ARP proxy.
+ ///
+ [MarshalAs(UnmanagedType.Bool)]
+ public bool EnableProxy;
+
+ ///
+ /// Type: UINT
+ /// A Boolean value that specifies whether DNS is enabled on the local computer.
+ ///
+ [MarshalAs(UnmanagedType.Bool)]
+ public bool EnableDns;
+ }
+
+ ///
+ ///
+ /// The IP_ADAPTER_ADDRESSES structure is the header node for a linked list of addresses for a particular adapter. This
+ /// structure can simultaneously be used as part of a linked list of IP_ADAPTER_ADDRESSES structures.
+ ///
+ ///
+ ///
+ ///
+ /// The GetAdaptersAddresses function retrieves information for IPv4 and IPv6 addresses and returns this information as a linked list
+ /// of IP_ADAPTER_ADDRESSES structures
+ ///
+ ///
+ /// The adapter index values specified in the IfIndex and Ipv6IfIndex members may change when an adapter is disabled
+ /// and then enabled, or under other circumstances, and should not be considered persistent.
+ ///
+ ///
+ /// The values for the IfType member are defined in the Ipifcons.h header file. Only the possible values listed in the
+ /// description of the IfType member are currently supported.
+ ///
+ ///
+ /// The size of the IP_ADAPTER_ADDRESSES structure changed on Windows XP with SP1 and later. The size of the
+ /// IP_ADAPTER_ADDRESSES structure also changed on Windows Vista and later. The size of the IP_ADAPTER_ADDRESSES
+ /// structure also changed on Windows Vista with SP1and later and onWindows Server 2008 and later. The Length member should be
+ /// used to determine which version of the IP_ADAPTER_ADDRESSES structure is being used.
+ ///
+ ///
+ /// The version of the IP_ADAPTER_ADDRESSES structure on Windows XP with SP1 and later has the following new members added:
+ /// Ipv6IfIndex, ZoneIndices, and FirstPrefix.
+ ///
+ ///
+ /// The version of the IP_ADAPTER_ADDRESSES structure on Windows Vista and later has the following new members added:
+ /// TransmitLinkSpeed, ReceiveLinkSpeed, FirstWinsServerAddress, FirstGatewayAddress, Ipv4Metric,
+ /// Ipv6Metric, Luid, Dhcpv4Server, CompartmentId, NetworkGuid, ConnectionType,
+ /// TunnelType, Dhcpv6Server, Dhcpv6ClientDuid, Dhcpv6ClientDuidLength, and Dhcpv6Iaid.
+ ///
+ ///
+ /// The version of the IP_ADAPTER_ADDRESSES structure on Windows Vista with SP1and later and on Windows Server 2008 and later
+ /// has the following new member added: FirstDnsSuffix.
+ ///
+ ///
+ /// The Ipv4Metric and Ipv6Metric members are used to prioritize route metrics for routes connected to multiple
+ /// interfaces on the local computer.
+ ///
+ ///
+ /// The order of linked IP_ADAPTER_UNICAST_ADDRESS structures pointed to by the FirstUnicastAddress member that are returned
+ /// by the GetAdaptersAddresses function does not reflect the order that IP addresses were added to an adapter and may vary between
+ /// versions of Windows. Similarly, the order of linked IP_ADAPTER_ANYCAST_ADDRESS structures pointed to by the
+ /// FirstAnycastAddress member and the order of linked IP_ADAPTER_MULTICAST_ADDRESS structures pointed to by the
+ /// FirstMulticastAddress member do not reflect the order that IP addresses were added to an adapter and may vary between
+ /// versions of Windows.
+ ///
+ ///
+ /// In addition, the linked IP_ADAPTER_UNICAST_ADDRESS structures pointed to by the FirstUnicastAddress member and the linked
+ /// IP_ADAPTER_PREFIXstructures pointed to by the FirstPrefix member are maintained as separate internal linked lists by the
+ /// operating system. As a result, the order of linked IP_ADAPTER_UNICAST_ADDRESS structures pointed to by the
+ /// FirstUnicastAddress member does not have any relationship with the order of linked IP_ADAPTER_PREFIX structures
+ /// pointed to by the FirstPrefix member.
+ ///
+ ///
+ /// On Windows Vista and later, the linked IP_ADAPTER_PREFIXstructures pointed to by the FirstPrefix member include three IP
+ /// adapter prefixes for each IP address assigned to the adapter. These include the host IP address prefix, the subnet IP address
+ /// prefix, and the subnet broadcast IP address prefix. In addition, for each adapter there is a multicast address prefix and a
+ /// broadcast address prefix.
+ ///
+ ///
+ /// On Windows XP with SP1 and later prior to Windows Vista, the linked IP_ADAPTER_PREFIXstructures pointed to by the
+ /// FirstPrefix member include only a single IP adapter prefix for each IP address assigned to the adapter.
+ ///
+ ///
+ /// In the Windows SDK, the version of the structure for use on Windows Vista and later is defined as IP_ADAPTER_ADDRESSES_LH.
+ /// In the Microsoft Windows Software Development Kit (SDK), the version of this structure to be used on earlier systems including
+ /// Windows XP with SP1 and later is defined as IP_ADAPTER_ADDRESSES_XP. When compiling an application if the target platform
+ /// is Windows Vista and later (, , or ), the IP_ADAPTER_ADDRESSES_LH structure is typedefed to the
+ /// IP_ADAPTER_ADDRESSES structure. When compiling an application if the target platform is not Windows Vista and later, the
+ /// IP_ADAPTER_ADDRESSES_XP structure is typedefed to the IP_ADAPTER_ADDRESSES structure.
+ ///
+ ///
+ /// The SOCKET_ADDRESS structure is used in the IP_ADAPTER_ADDRESSES structure. On the Windows SDK released for Windows Vista
+ /// and later, the organization of header files has changed and the SOCKET_ADDRESS structure is defined in the Ws2def.h header
+ /// file which is automatically included by the Winsock2.h header file. On the Platform Software Development Kit (SDK) released for
+ /// Windows Server 2003 and Windows XP, the SOCKET_ADDRESS structure is declared in the Winsock2.h header file. In order to
+ /// use the IP_ADAPTER_ADDRESSES structure, the Winsock2.h header file must be included before the Iphlpapi.h header file.
+ ///
+ /// Examples
+ ///
+ /// This example retrieves the IP_ADAPTER_ADDRESSES structure for the adapters associated with the system and prints some
+ /// members for each adapter interface.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_adapter_addresses_lh typedef struct
+ // _IP_ADAPTER_ADDRESSES_LH { union { ULONGLONG Alignment; struct { ULONG Length; IF_INDEX IfIndex; }; }; struct
+ // _IP_ADAPTER_ADDRESSES_LH *Next; PCHAR AdapterName; PIP_ADAPTER_UNICAST_ADDRESS_LH FirstUnicastAddress;
+ // PIP_ADAPTER_ANYCAST_ADDRESS_XP FirstAnycastAddress; PIP_ADAPTER_MULTICAST_ADDRESS_XP FirstMulticastAddress;
+ // PIP_ADAPTER_DNS_SERVER_ADDRESS_XP FirstDnsServerAddress; PWCHAR DnsSuffix; PWCHAR Description; PWCHAR FriendlyName; BYTE
+ // PhysicalAddress[MAX_ADAPTER_ADDRESS_LENGTH]; ULONG PhysicalAddressLength; union { ULONG Flags; struct { ULONG DdnsEnabled : 1;
+ // ULONG RegisterAdapterSuffix : 1; ULONG Dhcpv4Enabled : 1; ULONG ReceiveOnly : 1; ULONG NoMulticast : 1; ULONG
+ // Ipv6OtherStatefulConfig : 1; ULONG NetbiosOverTcpipEnabled : 1; ULONG Ipv4Enabled : 1; ULONG Ipv6Enabled : 1; ULONG
+ // Ipv6ManagedAddressConfigurationSupported : 1; }; }; ULONG Mtu; IFTYPE IfType; IF_OPER_STATUS OperStatus; IF_INDEX Ipv6IfIndex;
+ // ULONG ZoneIndices[16]; PIP_ADAPTER_PREFIX_XP FirstPrefix; ULONG64 TransmitLinkSpeed; ULONG64 ReceiveLinkSpeed;
+ // PIP_ADAPTER_WINS_SERVER_ADDRESS_LH FirstWinsServerAddress; PIP_ADAPTER_GATEWAY_ADDRESS_LH FirstGatewayAddress; ULONG Ipv4Metric;
+ // ULONG Ipv6Metric; IF_LUID Luid; SOCKET_ADDRESS Dhcpv4Server; NET_IF_COMPARTMENT_ID CompartmentId; NET_IF_NETWORK_GUID NetworkGuid;
+ // NET_IF_CONNECTION_TYPE ConnectionType; TUNNEL_TYPE TunnelType; SOCKET_ADDRESS Dhcpv6Server; BYTE
+ // Dhcpv6ClientDuid[MAX_DHCPV6_DUID_LENGTH]; ULONG Dhcpv6ClientDuidLength; ULONG Dhcpv6Iaid; PIP_ADAPTER_DNS_SUFFIX FirstDnsSuffix; }
+ // IP_ADAPTER_ADDRESSES_LH, *PIP_ADAPTER_ADDRESSES_LH;
+ [PInvokeData("iptypes.h", MSDNShortId = "a2df3749-6c75-40c0-8952-1656bbe639a6")]
+ [StructLayout(LayoutKind.Sequential)]
+ public struct IP_ADAPTER_ADDRESSES
+ {
+ public uint Length;
+ public uint IfIndex;
+
+ ///
+ /// Type: struct _IP_ADAPTER_ADDRESSES*
+ /// A pointer to the next adapter addresses structure in the list.
+ ///
+ public IntPtr Next;
+
+ ///
+ /// Type: PCHAR
+ ///
+ /// An array of characters that contains the name of the adapter with which these addresses are associated. Unlike an adapter's
+ /// friendly name, the adapter name specified in AdapterName is permanent and cannot be modified by the user.
+ ///
+ ///
+ [MarshalAs(UnmanagedType.LPStr)]
+ public string AdapterName;
+
+ ///
+ /// Type: PIP_ADAPTER_UNICAST_ADDRESS
+ /// A pointer to the first IP_ADAPTER_UNICAST_ADDRESS structure in a linked list of IP unicast addresses for the adapter.
+ ///
+ public IntPtr FirstUnicastAddress;
+
+ ///
+ /// Type: PIP_ADAPTER_ANYCAST_ADDRESS
+ /// A pointer to the first IP_ADAPTER_ANYCAST_ADDRESS structure in a linked list of IP anycast addresses for the adapter.
+ ///
+ public IntPtr FirstAnycastAddress;
+
+ ///
+ /// Type: PIP_ADAPTER_MULTICAST_ADDRESS
+ /// A pointer to the first IP_ADAPTER_MULTICAST_ADDRESS structure in a list of IP multicast addresses for the adapter.
+ ///
+ public IntPtr FirstMulticastAddress;
+
+ ///
+ /// Type: PIP_ADAPTER_DNS_SERVER_ADDRESS
+ /// A pointer to the first IP_ADAPTER_DNS_SERVER_ADDRESS structure in a linked list of DNS server addresses for the adapter.
+ ///
+ public IntPtr FirstDnsServerAddress;
+
+ ///
+ /// Type: PWCHAR
+ /// The Domain Name System (DNS) suffix associated with this adapter.
+ ///
+ [MarshalAs(UnmanagedType.LPWStr)]
+ public string DnsSuffix;
+
+ ///
+ /// Type: PWCHAR
+ /// A description for the adapter. This member is read-only.
+ ///
+ [MarshalAs(UnmanagedType.LPWStr)]
+ public string Description;
+
+ ///
+ /// Type: PWCHAR
+ ///
+ /// A user-friendly name for the adapter. For example: "Local Area Connection 1." This name appears in contexts such as the
+ /// ipconfig command line program and the Connection folder. This member is read only and can't be modified using any IP
+ /// Helper functions.
+ ///
+ ///
+ /// This member is the ifAlias field used by NDIS as described in RFC 2863. The ifAlias field can be set by an NDIS interface
+ /// provider when the NDIS driver is installed. For NDIS miniport drivers, this field is set by NDIS.
+ ///
+ ///
+ [MarshalAs(UnmanagedType.LPWStr)]
+ public string FriendlyName;
+
+ ///
+ /// Type: BYTE[MAX_ADAPTER_ADDRESS_LENGTH]
+ ///
+ /// The Media Access Control (MAC) address for the adapter. For example, on an Ethernet network this member would specify the
+ /// Ethernet hardware address.
+ ///
+ ///
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_ADAPTER_ADDRESS_LENGTH)]
+ public byte[] PhysicalAddress;
+
+ ///
+ /// Type: DWORD
+ ///
+ /// The length, in bytes, of the address specified in the PhysicalAddress member. For interfaces that do not have a
+ /// data-link layer, this value is zero.
+ ///
+ ///
+ public uint PhysicalAddressLength;
+
+ public IP_ADAPTER_FLAGS Flags;
+
+ ///
+ /// Type: DWORD
+ /// The maximum transmission unit (MTU) size, in bytes.
+ ///
+ public uint Mtu;
+
+ ///
+ /// Type: DWORD
+ ///
+ /// The interface type as defined by the Internet Assigned Names Authority (IANA). Possible values for the interface type are
+ /// listed in the Ipifcons.h header file.
+ ///
+ /// The table below lists common values for the interface type although many other values are possible.
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// IF_TYPE_OTHER 1
+ /// Some other type of network interface.
+ ///
+ /// -
+ /// IF_TYPE_ETHERNET_CSMACD 6
+ /// An Ethernet network interface.
+ ///
+ /// -
+ /// IF_TYPE_ISO88025_TOKENRING 9
+ /// A token ring network interface.
+ ///
+ /// -
+ /// IF_TYPE_PPP 23
+ /// A PPP network interface.
+ ///
+ /// -
+ /// IF_TYPE_SOFTWARE_LOOPBACK 24
+ /// A software loopback network interface.
+ ///
+ /// -
+ /// IF_TYPE_ATM 37
+ /// An ATM network interface.
+ ///
+ /// -
+ /// IF_TYPE_IEEE80211 71
+ ///
+ /// An IEEE 802.11 wireless network interface. On Windows Vista and later, wireless network cards are reported as
+ /// IF_TYPE_IEEE80211. On earlier versions of Windows, wireless network cards are reported as IF_TYPE_ETHERNET_CSMACD. On Windows
+ /// XP with SP3 and on Windows XP with SP2 x86 with the Wireless LAN API for Windows XP with SP2 installed, the
+ /// WlanEnumInterfaces function can be used to enumerate wireless interfaces on the local computer.
+ ///
+ ///
+ /// -
+ /// IF_TYPE_TUNNEL 131
+ /// A tunnel type encapsulation network interface.
+ ///
+ /// -
+ /// IF_TYPE_IEEE1394 144
+ /// An IEEE 1394 (Firewire) high performance serial bus network interface.
+ ///
+ ///
+ ///
+ public IFTYPE IfType;
+
+ ///
+ /// Type: IF_OPER_STATUS
+ ///
+ /// The operational status for the interface as defined in RFC 2863. For more information, see
+ /// http://www.ietf.org/rfc/rfc2863.txt. This member can be one of the values from the IF_OPER_STATUS enumeration type
+ /// defined in the Iftypes.h header file. On Windows Vista and later, the header files were reorganized and this enumeration is
+ /// defined in the Ifdef.h header file.
+ ///
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// IfOperStatusUp 1
+ /// The interface is up and able to pass packets.
+ ///
+ /// -
+ /// IfOperStatusDown 2
+ ///
+ /// The interface is down and not in a condition to pass packets. The IfOperStatusDown state has two meanings, depending on the
+ /// value of AdminStatus member. If AdminStatus is not set to NET_IF_ADMIN_STATUS_DOWN and ifOperStatus is set to
+ /// IfOperStatusDown then a fault condition is presumed to exist on the interface. If AdminStatus is set to IfOperStatusDown,
+ /// then ifOperStatus will normally also be set to IfOperStatusDown or IfOperStatusNotPresent and there is not necessarily a
+ /// fault condition on the interface.
+ ///
+ ///
+ /// -
+ /// IfOperStatusTesting 3
+ /// The interface is in testing mode.
+ ///
+ /// -
+ /// IfOperStatusUnknown 4
+ /// The operational status of the interface is unknown.
+ ///
+ /// -
+ /// IfOperStatusDormant 5
+ ///
+ /// The interface is not actually in a condition to pass packets (it is not up), but is in a pending state, waiting for some
+ /// external event. For on-demand interfaces, this new state identifies the situation where the interface is waiting for events
+ /// to place it in the IfOperStatusUp state.
+ ///
+ ///
+ /// -
+ /// IfOperStatusNotPresent 6
+ ///
+ /// A refinement on the IfOperStatusDown state which indicates that the relevant interface is down specifically because some
+ /// component (typically, a hardware component) is not present in the managed system.
+ ///
+ ///
+ /// -
+ /// IfOperStatusLowerLayerDown 7
+ ///
+ /// A refinement on the IfOperStatusDown state. This new state indicates that this interface runs on top of one or more other
+ /// interfaces and that this interface is down specifically because one or more of these lower-layer interfaces are down.
+ ///
+ ///
+ ///
+ ///
+ public IF_OPER_STATUS OperStatus;
+
+ ///
+ /// Type: DWORD
+ /// The interface index for the IPv6 IP address. This member is zero if IPv6 is not available on the interface.
+ /// Note This structure member is only available on Windows XP with SP1 and later.
+ ///
+ private readonly uint Ipv6IfIndex;
+
+ ///
+ /// Type: DWORD[16]
+ ///
+ /// An array of scope IDs for each scope level used for composing sockaddr structures. The SCOPE_LEVEL enumeration is used to
+ /// index the array. On IPv6, a single interface may be assigned multiple IPv6 multicast addresses based on a scope ID.
+ ///
+ /// Note This structure member is only available on Windows XP with SP1 and later.
+ ///
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
+ public SCOPE_LEVEL[] ZoneIndices;
+
+ ///
+ /// Type: PIP_ADAPTER_PREFIX
+ /// A pointer to the first IP_ADAPTER_PREFIX structure in a linked list of IP adapter prefixes for the adapter.
+ /// Note This structure member is only available on Windows XP with SP1 and later.
+ ///
+ public IntPtr FirstPrefix;
+
+ ///
+ /// Type: ULONG64
+ /// The current speed in bits per second of the transmit link for the adapter.
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ public ulong TrasmitLinkSpeed;
+
+ ///
+ /// Type: ULONG64
+ /// The current speed in bits per second of the receive link for the adapter.
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ public ulong ReceiveLinkSpeed;
+
+ ///
+ /// Type: PIP_ADAPTER_WINS_SERVER_ADDRESS_LH
+ ///
+ /// A pointer to the first IP_ADAPTER_WINS_SERVER_ADDRESS structure in a linked list of Windows Internet Name Service (WINS)
+ /// server addresses for the adapter.
+ ///
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ public IntPtr FirstWinsServerAddress;
+
+ ///
+ /// Type: PIP_ADAPTER_GATEWAY_ADDRESS_LH
+ /// A pointer to the first IP_ADAPTER_GATEWAY_ADDRESS structure in a linked list of gateways for the adapter.
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ public IntPtr FirstGatewayAddress;
+
+ ///
+ /// Type: ULONG
+ /// The IPv4 interface metric for the adapter address. This member is only applicable to an IPv4 adapter address.
+ ///
+ /// The actual route metric used to compute the route preferences for IPv4 is the summation of the route metric offset specified
+ /// in the Metric member of the MIB_IPFORWARD_ROW2 structure and the interface metric specified in this member for IPv4.
+ ///
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ public uint Ipv4Metric;
+
+ ///
+ /// Type: ULONG
+ /// The IPv6 interface metric for the adapter address. This member is only applicable to an IPv6 adapter address.
+ ///
+ /// The actual route metric used to compute the route preferences for IPv6 is the summation of the route metric offset specified
+ /// in the Metric member of the MIB_IPFORWARD_ROW2 structure and the interface metric specified in this member for IPv4.
+ ///
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ public uint Ipv6Metric;
+
+ ///
+ /// Type: IF_LUID
+ /// The interface LUID for the adapter address.
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ public NET_LUID Luid;
+
+ ///
+ /// Type: SOCKET_ADDRESS
+ ///
+ /// The IPv4 address of the DHCP server for the adapter address. This member is only applicable to an IPv4 adapter address
+ /// configured using DHCP.
+ ///
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ public SOCKET_ADDRESS Dhcpv4Server;
+
+ ///
+ /// Type: NET_IF_COMPARTMENT_ID
+ /// The routing compartment ID for the adapter address.
+ ///
+ /// Note This structure member is only available on Windows Vista and later. This member is not currently supported and is
+ /// reserved for future use.
+ ///
+ ///
+ public uint CompartmentId;
+
+ ///
+ /// Type: NET_IF_NETWORK_GUID
+ /// The GUID that is associated with the network that the interface belongs to.
+ ///
+ /// If the interface provider cannot provide the network GUID, this member can be a zero GUID. In this case, the interface
+ /// was registered by NDIS in the default network.
+ ///
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ public Guid NetworkGuid;
+
+ ///
+ /// Type: NET_IF_CONNECTION_TYPE
+ /// The interface connection type for the adapter address.
+ ///
+ /// This member can be one of the values from the NET_IF_CONNECTION_TYPE enumeration type defined in the Ifdef.h header file.
+ ///
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// NET_IF_CONNECTION_DEDICATED 1
+ ///
+ /// The connection type is dedicated. The connection comes up automatically when media sense is TRUE. For example, an Ethernet
+ /// connection is dedicated.
+ ///
+ ///
+ /// -
+ /// NET_IF_CONNECTION_PASSIVE 2
+ ///
+ /// The connection type is passive. The remote end must bring up the connection to the local station. For example, a RAS
+ /// interface is passive.
+ ///
+ ///
+ /// -
+ /// NET_IF_CONNECTION_DEMAND 3
+ ///
+ /// The connection type is demand-dial. A connection of this type comes up in response to a local action (sending a packet, for example).
+ ///
+ ///
+ /// -
+ /// NET_IF_CONNECTION_MAXIMUM 4
+ ///
+ /// The maximum possible value for the NET_IF_CONNECTION_TYPE enumeration type. This is not a legal value for ConnectionType member.
+ ///
+ ///
+ ///
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ public NET_IF_CONNECTION_TYPE ConnectionType;
+
+ ///
+ /// Type: TUNNEL_TYPE
+ /// The encapsulation method used by a tunnel if the adapter address is a tunnel.
+ /// Note This structure member is only available on Windows Vista and later.
+ /// The tunnel type is defined by the Internet Assigned Names Authority (IANA). For more information, see
+ /// http://www.iana.org/assignments/ianaiftype-mib
+ /// . This member can be one of the values from the
+ /// TUNNEL_TYPE
+ /// enumeration type defined in the
+ /// Ifdef.h
+ /// header file.
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// TUNNEL_TYPE_NONE 0
+ /// Not a tunnel.
+ ///
+ /// -
+ /// TUNNEL_TYPE_OTHER 1
+ /// None of the following tunnel types.
+ ///
+ /// -
+ /// TUNNEL_TYPE_DIRECT 2
+ ///
+ /// A packet is encapsulated directly within a normal IP header, with no intermediate header, and unicast to the remote tunnel endpoint.
+ ///
+ ///
+ /// -
+ /// TUNNEL_TYPE_6TO4 11
+ ///
+ /// An IPv6 packet is encapsulated directly within an IPv4 header, with no intermediate header, and unicast to the destination
+ /// determined by the 6to4 protocol.
+ ///
+ ///
+ /// -
+ /// TUNNEL_TYPE_ISATAP 13
+ ///
+ /// An IPv6 packet is encapsulated directly within an IPv4 header, with no intermediate header, and unicast to the destination
+ /// determined by the ISATAP protocol.
+ ///
+ ///
+ /// -
+ /// TUNNEL_TYPE_TEREDO 14
+ /// Teredo encapsulation for IPv6 packets.
+ ///
+ /// -
+ /// TUNNEL_TYPE_IPHTTPS 15
+ /// IP over HTTPS encapsulation for IPv6 packets.
+ ///
+ ///
+ ///
+ public TUNNEL_TYPE TunnelType;
+
+ ///
+ /// Type: SOCKET_ADDRESS
+ ///
+ /// The IPv6 address of the DHCPv6 server for the adapter address. This member is only applicable to an IPv6 adapter address
+ /// configured using DHCPv6. This structure member is not currently supported and is reserved for future use.
+ ///
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ public SOCKET_ADDRESS Dhcpv6Server;
+
+ ///
+ /// Type: BYTE[MAX_DHCPV6_DUID_LENGTH]
+ ///
+ /// The DHCP unique identifier (DUID) for the DHCPv6 client. This member is only applicable to an IPv6 adapter address configured
+ /// using DHCPv6.
+ ///
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_DHCPV6_DUID_LENGTH)]
+ public byte[] Dhcpv6ClientDuid;
+
+ ///
+ /// Type: ULONG
+ ///
+ /// The length, in bytes, of the DHCP unique identifier (DUID) for the DHCPv6 client. This member is only applicable to an IPv6
+ /// adapter address configured using DHCPv6.
+ ///
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ public uint Dhcpv6ClientDuidLength;
+
+ ///
+ /// Type: ULONG
+ ///
+ /// The identifier for an identity association chosen by the DHCPv6 client. This member is only applicable to an IPv6 adapter
+ /// address configured using DHCPv6.
+ ///
+ /// Note This structure member is only available on Windows Vista and later.
+ ///
+ public uint Dhcpv6Iaid;
+
+ ///
+ /// Type: PIP_ADAPTER_DNS_SUFFIX
+ /// A pointer to the first IP_ADAPTER_DNS_SUFFIX structure in a linked list of DNS suffixes for the adapter.
+ ///
+ /// Note This structure member is only available on Windows Vista with SP1and later and on Windows Server 2008 and later.
+ ///
+ ///
+ public IntPtr FirstDnsSuffix;
+
+ public IEnumerable UnicastAddresses => FirstUnicastAddress.LinkedListToIEnum(t => t.Next);
+ public IEnumerable AnycastAddresses => FirstAnycastAddress.LinkedListToIEnum(t => t.Next);
+ public IEnumerable MulticastAddresses => FirstMulticastAddress.LinkedListToIEnum(t => t.Next);
+ public IEnumerable DnsServerAddresses => FirstDnsServerAddress.LinkedListToIEnum(t => t.Next);
+ public IEnumerable Prefixes => FirstPrefix.LinkedListToIEnum(t => t.Next);
+ public IEnumerable WinsServerAddresses => FirstWinsServerAddress.LinkedListToIEnum(t => t.Next);
+ public IEnumerable GatewayAddresses => FirstGatewayAddress.LinkedListToIEnum(t => t.Next);
+ public IEnumerable DnsSuffixes => FirstDnsSuffix.LinkedListToIEnum(t => t.Next);
+
+ public IP_ADAPTER_ADDRESSES? GetNext()
+ {
+ return Next.ToNullableStructure();
+ }
+
+ public static IEnumerable ListFromPtr(IntPtr ptr)
+ {
+ return ptr.LinkedListToIEnum(t => t.Next);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/PInvoke/IpHlpApi/NetIOApi.cs b/PInvoke/IpHlpApi/NetIOApi.cs
new file mode 100644
index 00000000..73b9d042
--- /dev/null
+++ b/PInvoke/IpHlpApi/NetIOApi.cs
@@ -0,0 +1,3719 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Runtime.InteropServices;
+using System.Text;
+using Vanara.Extensions;
+using Vanara.InteropServices;
+
+namespace Vanara.PInvoke
+{
+ public static partial class IpHlpApi
+ {
+ [PInvokeData("netioapi.h")]
+ public enum MIB_IF_ENTRY_LEVEL
+ {
+ MibIfEntryNormal = 0,
+ MibIfEntryNormalWithoutStatistics = 2
+ }
+
+ ///
+ /// The MIB_IF_TABLE_LEVEL enumeration type defines the level of interface information to retrieve.
+ ///
+ ///
+ ///
+ /// The MIB_IF_TABLE_LEVEL enumeration type is used with the GetIfTable2Ex function to specify the level of interface information to retrieve.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/ne-netioapi-_mib_if_table_level typedef enum _MIB_IF_TABLE_LEVEL {
+ // MibIfTableNormal , MibIfTableRaw , MibIfTableNormalWithoutStatistics } MIB_IF_TABLE_LEVEL, *PMIB_IF_TABLE_LEVEL;
+ [PInvokeData("netioapi.h", MSDNShortId = "ffbde22e-9851-4acd-b820-b71f2788b4d2")]
+ public enum MIB_IF_TABLE_LEVEL
+ {
+ ///
+ /// The values of statistics and state that are returned in members of the MIB_IF_ROW2 structure in the MIB_IF_TABLE2 structure
+ /// that the Table parameter points to in the GetIfTable2Ex function are returned from the top of the filter stack.
+ ///
+ MibIfTableNormal,
+
+ ///
+ /// The values of statistics and state that are returned in members of the MIB_IF_ROW2 structure in the MIB_IF_TABLE2 structure
+ /// that the Table parameter points to in the GetIfTable2Ex function are returned directly for the interface that is being queried.
+ ///
+ MibIfTableRaw,
+
+ /// The values returned are the same as for the MibIfTableNormal value, but without the statistics.
+ MibIfTableNormalWithoutStatistics,
+ }
+
+ /// Undocumented.
+ [PInvokeData("netioapi.h", MSDNShortId = "164dbd93-4464-40f9-989a-17597102b1d8")]
+ [Flags]
+ public enum MIB_IPNET_ROW2_FLAGS : uint
+ {
+ /// Undocumented.
+ IsRouther = 1,
+
+ /// Undocumented.
+ IsUnreachable = 2
+ }
+
+ /// The NL_DAD_STATE enumeration type defines the duplicate address detection (DAD) state.
+ // typedef enum { NldsInvalid, NldsTentative, NldsDuplicate, NldsDeprecated, NldsPreferred, IpDadStateInvalid = 0,
+ // IpDadStateTentative, IpDadStateDuplicate, IpDadStateDeprecated, IpDadStatePreferred} NL_DAD_STATE; https://msdn.microsoft.com/en-us/library/windows/hardware/ff568758(v=vs.85).aspx
+ [PInvokeData("Nldef.h", MSDNShortId = "ff568758")]
+ public enum NL_DAD_STATE
+ {
+ /// The DAD state is invalid.
+ IpDadStateInvalid,
+
+ /// The DAD state is tentative.
+ IpDadStateTentative,
+
+ /// A duplicate IP address has been detected.
+ IpDadStateDuplicate,
+
+ /// The IP address has been deprecated.
+ IpDadStateDeprecated,
+
+ /// The IP address is the preferred address.
+ IpDadStatePreferred,
+ }
+
+ /// The NL_PREFIX_ORIGIN enumeration type defines the origin of the prefix or network part of the IP address.
+ // typedef enum { IpPrefixOriginOther = 0, IpPrefixOriginManual, IpPrefixOriginWellKnown, IpPrefixOriginDhcp,
+ // IpPrefixOriginRouterAdvertisement, IpPrefixOriginUnchanged = 1 << 4} NL_PREFIX_ORIGIN; https://msdn.microsoft.com/en-us/library/windows/hardware/ff568762(v=vs.85).aspx
+ [PInvokeData("Nldef.h", MSDNShortId = "ff568762")]
+ public enum NL_PREFIX_ORIGIN
+ {
+ ///
+ /// The IP address prefix was configured by using a source other than those that are defined in this enumeration. This value
+ /// applies to an IPv6 or IPv4 address.
+ ///
+ IpPrefixOriginOther = 0,
+
+ /// The IP address prefix was configured manually. This value applies to an IPv6 or IPv4 address.
+ IpPrefixOriginManual,
+
+ ///
+ /// The IP address prefix was configured by using a well-known address. This value applies to an IPv6 link-local address or an
+ /// IPv6 loopback address.
+ ///
+ IpPrefixOriginWellKnown,
+
+ ///
+ /// The IP address prefix was configured by using DHCP. This value applies to an IPv4 address configured by using DHCP or an IPv6
+ /// address configured by using DHCPv6.
+ ///
+ IpPrefixOriginDhcp,
+
+ ///
+ /// The IP address prefix was configured by using router advertisement. This value applies to an anonymous IPv6 address that was
+ /// generated after receiving a router advertisement.
+ ///
+ IpPrefixOriginRouterAdvertisement,
+
+ ///
+ /// The IP address prefix should be unchanged. This value is used when setting the properties for a unicast IP interface when the
+ /// value for the IP prefix origin should be unchanged.
+ ///
+ IpPrefixOriginUnchanged = 1 << 4,
+ }
+
+ ///
+ ///
+ /// The IP_SUFFIX_ORIGIN enumeration specifies the origin of an IPv4 or IPv6 address suffix, and is used with the
+ /// IP_ADAPTER_UNICAST_ADDRESS structure.
+ ///
+ ///
+ ///
+ /// The IP_SUFFIX_ORIGIN enumeration is used in the SuffixOrigin member of the IP_ADAPTER_UNICAST_ADDRESS structure.
+ ///
+ /// On the Microsoft Windows Software Development Kit (SDK) released for Windows Vista and later, the organization of header files
+ /// has changed and the IP_SUFFIX_ORIGIN enumeration is defined in the Nldef.h header file which is automatically included by
+ /// the Iptypes.h header file. In order to use the IP_SUFFIX_ORIGIN enumeration, the Winsock2.h header file must be included
+ /// before the Iptypes.h header file.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/nldef/ne-nldef-nl_suffix_origin typedef enum NL_SUFFIX_ORIGIN { NlsoOther ,
+ // NlsoManual , NlsoWellKnown , NlsoDhcp , NlsoLinkLayerAddress , NlsoRandom , IpSuffixOriginOther , IpSuffixOriginManual ,
+ // IpSuffixOriginWellKnown , IpSuffixOriginDhcp , IpSuffixOriginLinkLayerAddress , IpSuffixOriginRandom , IpSuffixOriginUnchanged } ;
+ [PInvokeData("nldef.h", MSDNShortId = "0ffeae3d-cfc4-472e-87f8-ae6d584fb869")]
+ public enum NL_SUFFIX_ORIGIN
+ {
+ /// The IP address suffix was provided by a source other than those defined in this enumeration.
+ IpSuffixOriginOther = 0,
+
+ /// The IP address suffix was manually specified.
+ IpSuffixOriginManual,
+
+ /// The IP address suffix is from a well-known source.
+ IpSuffixOriginWellKnown,
+
+ /// The IP address suffix was provided by DHCP settings.
+ IpSuffixOriginDhcp,
+
+ /// The IP address suffix was obtained from the link-layer address.
+ IpSuffixOriginLinkLayerAddress,
+
+ /// The IP address suffix was obtained from a random source.
+ IpSuffixOriginRandom,
+
+ ///
+ /// The IP address suffix should be unchanged. This value is used when setting the properties for a unicast IP interface when the
+ /// value for the IP suffix origin should be left unchanged.
+ ///
+ IpSuffixOriginUnchanged = 1 << 4,
+ }
+
+ ///
+ /// The CancelMibChangeNotify2 function deregisters a driver change notification for IP interface changes, IP address changes,
+ /// IP route changes, and requests to retrieve the stable Unicast IP address table.
+ ///
+ ///
+ /// The handle that is returned from a notification registration or retrieval function to indicate which notification to cancel.
+ ///
+ ///
+ /// CancelMibChangeNotify2 returns STATUS_SUCCESS if the function succeeds.
+ /// If the function fails, CancelMibChangeNotify2 returns one of the following error codes:
+ ///
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// STATUS_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. CancelMibChangeNotify2 returns this error if the NotificationHandle parameter
+ /// was a NULL pointer.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use the FormatMessage function to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ // NETIOAPI_API CancelMibChangeNotify2( _In_ HANDLE NotificationHandle); https://msdn.microsoft.com/en-us/library/windows/hardware/ff544864(v=vs.85).aspx
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("Netioapi.h", MSDNShortId = "ff544864")]
+ public static extern Win32Error CancelMibChangeNotify2([In] IntPtr NotificationHandle);
+
+ ///
+ ///
+ /// The ConvertInterfaceAliasToLuid function converts an interface alias name for a network interface to the locally unique
+ /// identifier (LUID) for the interface.
+ ///
+ ///
+ ///
+ /// A pointer to a NULL-terminated Unicode string containing the alias name of the network interface.
+ ///
+ ///
+ /// A pointer to the NET_LUID for this interface.
+ ///
+ ///
+ ///
+ /// On success, ConvertInterfaceAliasToLuid returns NO_ERROR. Any nonzero return value indicates failure and a NULL is
+ /// returned in the InterfaceLuid parameter.
+ ///
+ ///
+ ///
+ /// Error code
+ /// Meaning
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// One of the parameters was invalid. This error is returned if either the InterfaceAlias or InterfaceLuid parameter was NULL or if
+ /// the InterfaceAlias parameter was invalid.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// The ConvertInterfaceAliasToLuid function is available on Windows Vistaand later.
+ ///
+ /// The ConvertInterfaceAliasToLuid function is protocol independent and works with network interfaces for both the IPv6 and
+ /// IPv4 protocol.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-convertinterfacealiastoluid _NETIOAPI_SUCCESS_
+ // NETIOAPI_API ConvertInterfaceAliasToLuid( CONST WCHAR *InterfaceAlias, PNET_LUID InterfaceLuid );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "7fa80938-d475-4ace-b463-a53aac26e88b")]
+ public static extern Win32Error ConvertInterfaceAliasToLuid([MarshalAs(UnmanagedType.LPWStr)] string InterfaceAlias, out NET_LUID InterfaceLuid);
+
+ ///
+ ///
+ /// The ConvertInterfaceGuidToLuid function converts a globally unique identifier (GUID) for a network interface to the
+ /// locally unique identifier (LUID) for the interface.
+ ///
+ ///
+ ///
+ /// A pointer to a GUID for a network interface.
+ ///
+ ///
+ /// A pointer to the NET_LUID for this interface.
+ ///
+ ///
+ ///
+ /// On success, ConvertInterfaceGuidToLuid returns NO_ERROR. Any nonzero return value indicates failure and a NULL is
+ /// returned in the InterfaceLuid parameter.
+ ///
+ ///
+ ///
+ /// Error code
+ /// Meaning
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// One of the parameters was invalid. This error is returned if either the InterfaceAlias or InterfaceLuid parameter was NULL or if
+ /// the InterfaceGuid parameter was invalid.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// The ConvertInterfaceGuidToLuid function is available on Windows Vistaand later.
+ ///
+ /// The ConvertInterfaceGuidToLuid function is protocol independent and works with network interfaces for both the IPv6 and
+ /// IPv4 protocol.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-convertinterfaceguidtoluid _NETIOAPI_SUCCESS_
+ // NETIOAPI_API ConvertInterfaceGuidToLuid( CONST GUID *InterfaceGuid, PNET_LUID InterfaceLuid );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "cae669dc-899b-4485-b70a-5f58207a07df")]
+ public static extern Win32Error ConvertInterfaceGuidToLuid([MarshalAs(UnmanagedType.LPStruct)] Guid InterfaceGuid, out NET_LUID InterfaceLuid);
+
+ ///
+ ///
+ /// The ConvertInterfaceIndexToLuid function converts a local index for a network interface to the locally unique identifier
+ /// (LUID) for the interface.
+ ///
+ ///
+ ///
+ /// The local index value for a network interface.
+ ///
+ ///
+ /// A pointer to the NET_LUID for this interface.
+ ///
+ ///
+ ///
+ /// On success, ConvertInterfaceIndexToLuid returns NO_ERROR. Any nonzero return value indicates failure and a NULL is
+ /// returned in the InterfaceLuid parameter.
+ ///
+ ///
+ ///
+ /// Error code
+ /// Meaning
+ ///
+ /// -
+ /// ERROR_FILE_NOT_FOUND
+ ///
+ /// The system cannot find the file specified. This error is returned if the network interface specified by the InterfaceIndex
+ /// parameter was not a value on the local machine.
+ ///
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// One of the parameters was invalid. This error is returned if the InterfaceLuid parameter was NULL or if the InterfaceIndex
+ /// parameter was invalid.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// The ConvertInterfaceIndexToLuid function is available on Windows Vistaand later.
+ ///
+ /// The ConvertInterfaceIndexToLuid function is protocol independent and works with network interfaces for both the IPv6 and
+ /// IPv4 protocol.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-convertinterfaceindextoluid _NETIOAPI_SUCCESS_
+ // NETIOAPI_API ConvertInterfaceIndexToLuid( NET_IFINDEX InterfaceIndex, PNET_LUID InterfaceLuid );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "c757228c-93f1-4545-8921-9d048bca580c")]
+ public static extern Win32Error ConvertInterfaceIndexToLuid(uint InterfaceIndex, out NET_LUID InterfaceLuid);
+
+ ///
+ ///
+ /// The ConvertInterfaceLuidToAlias function converts a locally unique identifier (LUID) for a network interface to an
+ /// interface alias.
+ ///
+ ///
+ ///
+ /// A pointer to a NET_LUID for a network interface.
+ ///
+ ///
+ ///
+ /// A pointer to a buffer to hold the NULL-terminated Unicode string containing the alias name of the network interface when
+ /// the function returns successfully.
+ ///
+ ///
+ ///
+ ///
+ /// The length, in characters, of the buffer pointed to by the InterfaceAlias parameter. This value must be large enough to
+ /// accommodate the alias name of the network interface and the terminating NULL character. The maximum required length is
+ /// NDIS_IF_MAX_STRING_SIZE + 1.
+ ///
+ ///
+ ///
+ /// On success, ConvertInterfaceLuidToAlias returns NO_ERROR. Any nonzero return value indicates failure.
+ ///
+ ///
+ /// Error code
+ /// Meaning
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// One of the parameters was invalid. This error is returned if either the InterfaceLuid or InterfaceAlias parameter was NULL or if
+ /// the InterfaceLuid parameter was invalid.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_ENOUGH_MEMORY
+ ///
+ /// Not enough storage is available to process this command. This error is returned if the size of the buffer pointed to by the
+ /// InterfaceAlias parameter was not large enough as specified in the Length parameter to hold the alias name.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// The ConvertInterfaceLuidToAlias function is available on Windows Vistaand later.
+ ///
+ /// The ConvertInterfaceLuidToAlias function is protocol independent and works with network interfaces for both the IPv6 and
+ /// IPv4 protocol.
+ ///
+ ///
+ /// The maximum length of the alias name for a network interface, NDIS_IF_MAX_STRING_SIZE, without the terminating NULL
+ /// is declared in the Ntddndis.h header file. The NDIS_IF_MAX_STRING_SIZE is defined to be the IF_MAX_STRING_SIZE
+ /// constant defined in the Ifdef.h header file. The Ntddndis.h and Ifdef.h header files are automatically included in the Netioapi.h
+ /// header file which is automatically included by the IpHlpApi.h header file. The Ntddndis.h, Ifdef.h, and Netioapi.h header files
+ /// should never be used directly.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-convertinterfaceluidtoalias _NETIOAPI_SUCCESS_
+ // NETIOAPI_API ConvertInterfaceLuidToAlias( CONST NET_LUID *InterfaceLuid, PWSTR InterfaceAlias, SIZE_T Length );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "86a821c1-e04b-4bc3-846d-767c55008aed")]
+ public static extern Win32Error ConvertInterfaceLuidToAlias([MarshalAs(UnmanagedType.LPStruct)] NET_LUID InterfaceLuid, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder InterfaceAlias, SizeT Length);
+
+ ///
+ ///
+ /// The ConvertInterfaceLuidToGuid function converts a locally unique identifier (LUID) for a network interface to a globally
+ /// unique identifier (GUID) for the interface.
+ ///
+ ///
+ ///
+ /// A pointer to a NET_LUID for a network interface.
+ ///
+ ///
+ /// A pointer to the GUID for this interface.
+ ///
+ ///
+ ///
+ /// On success, ConvertInterfaceLuidToGuid returns NO_ERROR. Any nonzero return value indicates failure and a NULL is
+ /// returned in the InterfaceGuid parameter.
+ ///
+ ///
+ ///
+ /// Error code
+ /// Meaning
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// One of the parameters was invalid. This error is returned if either the InterfaceLuid or InterfaceGuid parameter was NULL or if
+ /// the InterfaceLuid parameter was invalid.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// The ConvertInterfaceLuidToGuid function is available on Windows Vistaand later.
+ ///
+ /// The ConvertInterfaceLuidToGuid function is protocol independent and works with network interfaces for both the IPv6 and
+ /// IPv4 protocol.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-convertinterfaceluidtoguid _NETIOAPI_SUCCESS_
+ // NETIOAPI_API ConvertInterfaceLuidToGuid( CONST NET_LUID *InterfaceLuid, GUID *InterfaceGuid );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "9d5bd1e9-0bf1-405a-8726-8e2c9ba4e022")]
+ public static extern Win32Error ConvertInterfaceLuidToGuid([MarshalAs(UnmanagedType.LPStruct)] NET_LUID InterfaceLuid, out Guid InterfaceGuid);
+
+ ///
+ /// The ConvertInterfaceLuidToIndex function converts a locally unique identifier (LUID) for a network interface to the local
+ /// index for the interface.
+ ///
+ /// A pointer to a NET_LUID for a network interface.
+ /// The local index value for the interface.
+ ///
+ ///
+ /// On success, ConvertInterfaceLuidToIndex returns NO_ERROR. Any nonzero return value indicates failure and a
+ /// NET_IFINDEX_UNSPECIFIED is returned in the InterfaceIndex parameter.
+ ///
+ ///
+ ///
+ ///
+ /// Error code
+ /// Meaning
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// One of the parameters was invalid. This error is returned if either the InterfaceLuid or InterfaceIndex parameter was NULL or if
+ /// the InterfaceLuid parameter was invalid.
+ ///
+ ///
+ ///
+ ///
+ ///
+ // NETIO_STATUS WINAPI ConvertInterfaceLuidToIndex( _In_ const NET_LUID *InterfaceLuid, _Out_ PNET_IFINDEX InterfaceIndex); https://msdn.microsoft.com/en-us/library/windows/desktop/aa365835(v=vs.85).aspx
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("Netioapi.h", MSDNShortId = "aa365835")]
+ public static extern Win32Error ConvertInterfaceLuidToIndex([In, MarshalAs(UnmanagedType.LPStruct)] NET_LUID InterfaceLuid, out uint InterfaceIndex);
+
+ ///
+ ///
+ /// The ConvertInterfaceLuidToNameA function converts a locally unique identifier (LUID) for a network interface to the ANSI
+ /// interface name.
+ ///
+ ///
+ ///
+ /// A pointer to a NET_LUID for a network interface.
+ ///
+ ///
+ ///
+ /// A pointer to a buffer to hold the NULL-terminated ANSI string containing the interface name when the function returns successfully.
+ ///
+ ///
+ ///
+ ///
+ /// The length, in bytes, of the buffer pointed to by the InterfaceName parameter. This value must be large enough to accommodate the
+ /// interface name and the terminating null character. The maximum required length is NDIS_IF_MAX_STRING_SIZE + 1.
+ ///
+ ///
+ ///
+ ///
+ /// On success, ConvertInterfaceLuidToNameA returns NETIO_ERROR_SUCCESS. Any nonzero return value indicates failure.
+ ///
+ ///
+ ///
+ /// Error code
+ /// Meaning
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// One of the parameters was invalid. This error is returned if either the InterfaceLuid or the InterfaceName parameter was NULL or
+ /// if the InterfaceLuid parameter was invalid.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_ENOUGH_MEMORY
+ ///
+ /// Not enough storage is available to process this command. This error is returned if the size of the buffer pointed to by
+ /// InterfaceName parameter was not large enough as specified in the Length parameter to hold the interface name.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// The ConvertInterfaceLuidToNameA function is available on Windows Vistaand later.
+ ///
+ /// The ConvertInterfaceLuidToNameA function is protocol independent and works with network interfaces for both the IPv6 and
+ /// IPv4 protocol. The ConvertInterfaceLuidToNameA converts a network interface LUID to an ANSI interface name.
+ ///
+ /// The ConvertInterfaceLuidToNameW converts a network interface LUID to a Unicode interface name.
+ ///
+ /// The maximum length of an interface name, NDIS_IF_MAX_STRING_SIZE, without the terminating NULL is declared in the
+ /// Ntddndis.h header file. The NDIS_IF_MAX_STRING_SIZE is defined to be the IF_MAX_STRING_SIZE constant defined in the
+ /// Ifdef.h header file. The Ntddndis.h and Ifdef.h header files are automatically included in the Netioapi.h header file which is
+ /// automatically included by the IpHlpApi.h header file. The Ntddndis.h, Ifdef.h, and Netioapi.h header files should never be used directly.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-convertinterfaceluidtonamea _NETIOAPI_SUCCESS_
+ // NETIOAPI_API ConvertInterfaceLuidToNameA( CONST NET_LUID *InterfaceLuid, PSTR InterfaceName, SIZE_T Length );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, CharSet = CharSet.Auto)]
+ [PInvokeData("netioapi.h", MSDNShortId = "c65f7b3c-55f4-40f8-9a7a-19d1066deca4")]
+ public static extern Win32Error ConvertInterfaceLuidToName([In, MarshalAs(UnmanagedType.LPStruct)] NET_LUID InterfaceLuid, StringBuilder InterfaceName, SizeT Length);
+
+ ///
+ ///
+ /// The ConvertInterfaceNameToLuidA function converts an ANSI network interface name to the locally unique identifier (LUID)
+ /// for the interface.
+ ///
+ ///
+ ///
+ /// A pointer to a NULL-terminated ANSI string containing the network interface name.
+ ///
+ ///
+ /// A pointer to the NET_LUID for this interface.
+ ///
+ ///
+ ///
+ /// On success, ConvertInterfaceNameToLuidA returns NETIO_ERROR_SUCCESS. Any nonzero return value indicates failure.
+ ///
+ ///
+ ///
+ /// Error code
+ /// Meaning
+ ///
+ /// -
+ /// ERROR_BUFFER_OVERFLOW
+ ///
+ /// The length of the ANSI interface name was invalid. This error is returned if the InterfaceName parameter exceeded the maximum
+ /// allowed string length for this parameter.
+ ///
+ ///
+ /// -
+ /// ERROR_INVALID_NAME
+ /// The interface name was invalid. This error is returned if the InterfaceName parameter contained an invalid name.
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ /// One of the parameters was invalid. This error is returned if the InterfaceLuid parameter was NULL.
+ ///
+ ///
+ ///
+ ///
+ /// The ConvertInterfaceNameToLuidA function is available on Windows Vistaand later.
+ ///
+ /// The ConvertInterfaceNameToLuidA function is protocol independent and works with network interfaces for both the IPv6 and
+ /// IPv4 protocol. The ConvertInterfaceNameToLuidA converts an ANSI interface name to a LUID.
+ ///
+ /// The ConvertInterfaceNameToLuidW converts a Unicode interface name to a LUID.
+ ///
+ /// The maximum length of an interface name, NDIS_IF_MAX_STRING_SIZE, without the terminating NULL is declared in the
+ /// Ntddndis.h header file. The NDIS_IF_MAX_STRING_SIZE is defined to be the IF_MAX_STRING_SIZE constant defined in the
+ /// Ifdef.h header file. The Ntddndis.h and Ifdef.h header files are automatically included in the Netioapi.h header file which is
+ /// automatically included by the IpHlpApi.h header file. The Ntddndis.h, Ifdef.h, and Netioapi.h header files should never be used directly.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-convertinterfacenametoluida _NETIOAPI_SUCCESS_
+ // NETIOAPI_API ConvertInterfaceNameToLuidA( CONST CHAR *InterfaceName, NET_LUID *InterfaceLuid );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, CharSet = CharSet.Auto)]
+ [PInvokeData("netioapi.h", MSDNShortId = "daceabf9-ff43-4206-9f8f-f3924de9c5a5")]
+ public static extern Win32Error ConvertInterfaceNameToLuid(string InterfaceName, out NET_LUID InterfaceLuid);
+
+ ///
+ /// The ConvertIpv4MaskToLength function converts an IPv4 subnet mask to an IPv4 prefix length.
+ ///
+ ///
+ /// The IPv4 subnet mask.
+ ///
+ ///
+ /// A pointer to a UINT8 value to hold the IPv4 prefix length, in bits, when the function returns successfully.
+ ///
+ ///
+ /// On success, ConvertIpv4MaskToLength returns NO_ERROR. Any nonzero return value indicates failure.
+ ///
+ ///
+ /// Error code
+ /// Meaning
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ /// One of the parameters was invalid. This error is returned if the Mask parameter was invalid.
+ ///
+ ///
+ ///
+ ///
+ /// The ConvertIpv4MaskToLength function is available on Windows Vistaand later.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-convertipv4masktolength NETIOAPI_API
+ // ConvertIpv4MaskToLength( ULONG Mask, PUINT8 MaskLength );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "63a3c558-24e0-41ef-9417-a3b6b2075977")]
+ public static extern Win32Error ConvertIpv4MaskToLength(uint Mask, out byte MaskLength);
+
+ ///
+ /// The ConvertLengthToIpv4Mask function converts an IPv4 prefix length to an IPv4 subnet mask.
+ ///
+ ///
+ /// The IPv4 prefix length, in bits.
+ ///
+ ///
+ /// A pointer to a LONG value to hold the IPv4 subnet mask when the function returns successfully.
+ ///
+ ///
+ ///
+ /// On success, ConvertLengthToIpv4Mask returns NO_ERROR. Any nonzero return value indicates failure and the Mask
+ /// parameter is set to INADDR_NONE defined in the Ws2def.h header file.
+ ///
+ ///
+ ///
+ /// Error code
+ /// Meaning
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ /// One of the parameters was invalid. This error is returned if the MaskLength parameter was invalid.
+ ///
+ ///
+ ///
+ ///
+ /// The ConvertLengthToIpv4Mask function is available on Windows Vistaand later.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-convertlengthtoipv4mask NETIOAPI_API
+ // ConvertLengthToIpv4Mask( ULONG MaskLength, PULONG Mask );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "5d986301-368e-4984-9f90-e2af1f87cbea")]
+ public static extern Win32Error ConvertLengthToIpv4Mask(uint MaskLength, out uint Mask);
+
+ ///
+ /// The CreateIpForwardEntry2 function creates a new IP route entry on the local computer.
+ ///
+ ///
+ /// A pointer to a MIB_IPFORWARD_ROW2 structure entry for an IP route entry.
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_ACCESS_DENIED
+ ///
+ /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required
+ /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in
+ /// Administrator (RunAs administrator).
+ ///
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
+ /// DestinationPrefix member of the MIB_IPFORWARD_ROW2 pointed to by the Row parameter was not specified, the NextHop member of the
+ /// MIB_IPFORWARD_ROW2 pointed to by the Row parameter was not specified, or both the InterfaceLuid or InterfaceIndex members of the
+ /// MIB_IPFORWARD_ROW2 pointed to by the Row parameter were unspecified. This error is also returned if the PreferredLifetime member
+ /// specified in the MIB_IPFORWARD_ROW2 is greater than the ValidLifetime member or if the SitePrefixLength in the MIB_IPFORWARD_ROW2
+ /// is greater than the prefix length specified in the DestinationPrefix.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_FOUND
+ ///
+ /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
+ /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if the interface specified does not support routes. This error is also
+ /// returned if no IPv4 stack is on the local computer and AF_INET was specified in the address family in the DestinationPrefix
+ /// member of the MIB_IPFORWARD_ROW2 pointed to by the Row parameter. This error is also returned if no IPv6 stack is on the local
+ /// computer and AF_INET6 was specified for the address family in the DestinationPrefix member.
+ ///
+ ///
+ /// -
+ /// ERROR_OBJECT_ALREADY_EXISTS
+ ///
+ /// The object already exists. This error is returned if the DestinationPrefix member of the MIB_IPFORWARD_ROW2 pointed to by the Row
+ /// parameter is a duplicate of an existing IP route entry on the interface specified by the InterfaceLuid or InterfaceIndex member
+ /// of the MIB_IPFORWARD_ROW2.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The CreateIpForwardEntry2 function is defined on Windows Vista and later.
+ ///
+ /// The CreateIpForwardEntry2 function is used to add a new neighbor IP address entry on a local computer. The
+ /// InitializeIpForwardEntry function should be used to initialize the members of a MIB_IPFORWARD_ROW2 structure entry with default
+ /// values. An application can then change the members in the MIB_IPFORWARD_ROW2 entry it wishes to modify, and then call the
+ /// CreateIpForwardEntry2 function.
+ ///
+ ///
+ /// The DestinationPrefix member in the MIB_IPFORWARD_ROW2 structure pointed to by the Row parameter must be initialized to a
+ /// valid IPv4 or IPv6 address prefix. The NextHop member in the MIB_IPFORWARD_ROW2 structure pointed to by the Row
+ /// parameter must be initialized to a valid IPv4 or IPv6 address and family. In addition, at least one of the following members in
+ /// the MIB_IPFORWARD_ROW2 structure pointed to the Row parameter must be initialized to the interface: the
+ /// InterfaceLuid or InterfaceIndex.
+ ///
+ ///
+ /// The route metric offset specified in the Metric member of the MIB_IPFORWARD_ROW2 structure pointed to by Row parameter
+ /// represents only part of the complete route metric. The complete metric is a combination of this route metric offset added to the
+ /// interface metric specified in the Metric member of the MIB_IPINTERFACE_ROW structure of the associated interface. An
+ /// application can retrieve the interface metric by calling the GetIpInterfaceEntry function.
+ ///
+ ///
+ /// The Age and Origin members of the MIB_IPFORWARD_ROW2 structure pointed to by the Row are ignored when the
+ /// CreateIpForwardEntry2 function is called. These members are set by the network stack and cannot be set using the
+ /// CreateIpForwardEntry2 function.
+ ///
+ ///
+ /// The CreateIpForwardEntry2 function will fail if the DestinationPrefix and NextHop members of the
+ /// MIB_IPFORWARD_ROW2 pointed to by the Row parameter are a duplicate of an existing IP route entry on the interface specified in
+ /// the InterfaceLuid or InterfaceIndex members.
+ ///
+ ///
+ /// The CreateIpForwardEntry2 function can only be called by a user logged on as a member of the Administrators group. If
+ /// CreateIpForwardEntry2 is called by a user that is not a member of the Administrators group, the function call will fail
+ /// and ERROR_ACCESS_DENIED is returned. This function can also fail because of user account control (UAC) on Windows Vista
+ /// and later. If an application that contains this function is executed by a user logged on as a member of the Administrators group
+ /// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
+ /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a
+ /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced
+ /// shell as the built-in Administrator (RunAs administrator) for this function to succeed.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-createipforwardentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // CreateIpForwardEntry2( CONST MIB_IPFORWARD_ROW2 *Row );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "d2d065d3-daad-4167-8b87-4229199ee76a")]
+ public static extern Win32Error CreateIpForwardEntry2(ref MIB_IPFORWARD_ROW2 Row);
+
+ ///
+ /// The CreateIpNetEntry2 function creates a new neighbor IP address entry on the local computer.
+ ///
+ ///
+ /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry.
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_ACCESS_DENIED
+ ///
+ /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required
+ /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in
+ /// Administrator (RunAs administrator).
+ ///
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
+ /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid unicast, anycast, or multicast IPv4
+ /// or IPv6 address, the PhysicalAddress and PhysicalAddressLength members of the MIB_IPNET_ROW2 pointed to by the Row parameter were
+ /// not set to a valid physical address, or both the InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the
+ /// Row parameter were unspecified. This error is also returned if a loopback address was passed in the Address member.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_FOUND
+ ///
+ /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
+ /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
+ /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter. This error is also returned if no IPv6 stack is on
+ /// the local computer and an IPv6 address was specified in the Address member.
+ ///
+ ///
+ /// -
+ /// ERROR_OBJECT_ALREADY_EXISTS
+ ///
+ /// The object already exists. This error is returned if the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter is
+ /// a duplicate of an existing neighbor IP address on the interface specified by the InterfaceLuid or InterfaceIndex member of the MIB_IPNET_ROW2.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The CreateIpNetEntry2 function is defined on Windows Vista and later.
+ /// The CreateIpNetEntry2 function is used to add a new neighbor IP address entry on a local computer.
+ ///
+ /// The Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid unicast,
+ /// anycast, or multicast IPv4 or IPv6 address and family. The PhysicalAddress and PhysicalAddressLength members in the
+ /// MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid physical address. In addition, at
+ /// least one of the following members in the MIB_IPNET_ROW2 structure pointed to the Row parameter must be initialized to the
+ /// interface: the InterfaceLuid or InterfaceIndex.
+ ///
+ ///
+ /// The CreateIpNetEntry2 function will fail if the IP address passed in the Address member of the MIB_IPNET_ROW2
+ /// pointed to by the Row parameter is a duplicate of an existing neighbor IP address on the interface.
+ ///
+ ///
+ /// The CreateIpNetEntry2 function can only be called by a user logged on as a member of the Administrators group. If
+ /// CreateIpNetEntry2 is called by a user that is not a member of the Administrators group, the function call will fail and
+ /// ERROR_ACCESS_DENIED is returned. This function can also fail because of user account control (UAC) on Windows Vista and
+ /// later. If an application that contains this function is executed by a user logged on as a member of the Administrators group
+ /// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
+ /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a
+ /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced
+ /// shell as the built-in Administrator (RunAs administrator) for this function to succeed.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-createipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // CreateIpNetEntry2( CONST MIB_IPNET_ROW2 *Row );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "ca92b9f8-ec3c-4889-b649-f606c3920f92")]
+ public static extern Win32Error CreateIpNetEntry2(ref MIB_IPNET_ROW2 Row);
+
+ ///
+ ///
+ /// The CreateSortedAddressPairs function takes a supplied list of potential IP destination addresses, pairs the destination
+ /// addresses with the host machine's local IP addresses, and sorts the pairs according to which address pair is best suited for
+ /// communication between the two peers.
+ ///
+ ///
+ ///
+ /// Must be NULL. Reserved for future use.
+ ///
+ ///
+ /// Must be 0. Reserved for future use.
+ ///
+ ///
+ ///
+ /// A pointer to an array of SOCKADDR_IN6 structures that contain a list of potential IPv6 destination addresses. Any IPv4 addresses
+ /// must be represented in the IPv4-mapped IPv6 address format which enables an IPv6 only application to communicate with an IPv4 node.
+ ///
+ ///
+ ///
+ /// The number of destination addresses pointed to by the DestinationAddressList parameter.
+ ///
+ ///
+ /// Reserved for future use.
+ ///
+ ///
+ ///
+ /// A pointer to store an array of SOCKADDR_IN6_PAIR structures that contain a list of pairs of IPv6 addresses sorted in the
+ /// preferred order of communication, if the function call is successful.
+ ///
+ ///
+ ///
+ ///
+ /// A pointer to store the number of address pairs pointed to by the SortedAddressPairList parameter, if the function call is successful.
+ ///
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if the DestinationAddressList, SortedAddressPairList, or
+ /// SortedAddressPairCount parameters NULL, or the DestinationAddressCount was greated than 500. This error is also returned if the
+ /// SourceAddressList is not NULL or the SourceAddressPairCount parameter is not zero.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_ENOUGH_MEMORY
+ /// Not enough storage is available to process this command.
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ /// The request is not supported. This error is returned if no IPv6 stack is on the local computer.
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The CreateSortedAddressPairs function is defined on Windows Vista and later.
+ ///
+ /// The CreateSortedAddressPairs function takes a list of source and destination IPv6 addresses, and returns a list of pairs
+ /// of addresses in sorted order. The list is sorted by which address pair is best suited for communication between the source and
+ /// destination address.
+ ///
+ ///
+ /// The list of source addresses pointed to by the SourceAddressList is currently reserved for future and must be a NULL
+ /// pointer. The SourceAddressCount is currently reserved for future and must be zero. The CreateSortedAddressPairs function
+ /// currently uses all of the host machine's local addresses for the source address list.
+ ///
+ ///
+ /// The list of destination addresses is pointed to by the DestinationAddressList parameter. The list of destination addresses is an
+ /// array of SOCKADDR_IN6 structures. Any IPv4 addresses 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 DestinationAddressCount parameter contains the number of destination addresses pointed to by the
+ /// DestinationAddressList parameter. The CreateSortedAddressPairs function supports a maximum of 500 destination addresses.
+ ///
+ ///
+ /// If the CreateSortedAddressPairs function is successful, the SortedAddressPairList parameter points to an array of
+ /// SOCKADDR_IN6_PAIR structures that contain the sorted address pairs. When this returned list is no longer required, free the
+ /// memory used by the list by calling the FreeMibTable function.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-createsortedaddresspairs _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // CreateSortedAddressPairs( const PSOCKADDR_IN6 SourceAddressList, ULONG SourceAddressCount, const PSOCKADDR_IN6
+ // DestinationAddressList, ULONG DestinationAddressCount, ULONG AddressSortOptions, PSOCKADDR_IN6_PAIR *SortedAddressPairList, ULONG
+ // *SortedAddressPairCount );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "cdc90d63-15a4-4278-afc3-dbf9ad6ba698")]
+ public static extern Win32Error CreateSortedAddressPairs(IntPtr SourceAddressList, uint SourceAddressCount, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] SOCKADDR_IN6[] DestinationAddressList, uint DestinationAddressCount, uint AddressSortOptions, out SafeMibTableHandle SortedAddressPairList, out uint SortedAddressPairCount);
+
+ ///
+ /// The CreateSortedAddressPairs function takes a supplied list of potential IP destination addresses, pairs the destination
+ /// addresses with the host machine's local IP addresses, and sorts the pairs according to which address pair is best suited for
+ /// communication between the two peers.
+ ///
+ ///
+ /// An array of SOCKADDR_IN6 structures that contain a list of potential IPv6 destination addresses. Any IPv4 addresses must be
+ /// represented in the IPv4-mapped IPv6 address format which enables an IPv6 only application to communicate with an IPv4 node.
+ ///
+ /// An array of SOCKADDR_IN6_PAIR structures that contain the sorted address pairs.
+ public static SOCKADDR_IN6_PAIR[] CreateSortedAddressPairs(SOCKADDR_IN6[] DestinationAddressList)
+ {
+ CreateSortedAddressPairs(IntPtr.Zero, 0, DestinationAddressList, (uint)DestinationAddressList.Length, 0, out SafeMibTableHandle pairs, out uint cnt).ThrowIfFailed();
+ return pairs.ToArray((int)cnt);
+ }
+
+ ///
+ /// The CreateUnicastIpAddressEntry function adds a new unicast IP address entry on the local computer.
+ ///
+ ///
+ /// A pointer to a MIB_UNICASTIPADDRESS_ROW structure entry for a unicast IP address entry.
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_ACCESS_DENIED
+ ///
+ /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required
+ /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in
+ /// Administrator (RunAs administrator).
+ ///
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
+ /// Address member of the MIB_UNICASTIPADDRESS_ROW pointed to by the Row parameter was not set to a valid unicast IPv4 or IPv6
+ /// address, or both the InterfaceLuid and InterfaceIndex members of the MIB_UNICASTIPADDRESS_ROW pointed to by the Row parameter
+ /// were unspecified. This error is also returned for other errors in the values set for members in the MIB_UNICASTIPADDRESS_ROW
+ /// structure. These errors include the following: if the ValidLifetime member is less than than the PreferredLifetime member, if the
+ /// PrefixOrigin member is set to IpPrefixOriginUnchanged and the SuffixOrigin is the not set to IpSuffixOriginUnchanged, if the
+ /// PrefixOrigin member is not set to IpPrefixOriginUnchanged and the SuffixOrigin is set to IpSuffixOriginUnchanged, if the
+ /// PrefixOrigin member is not set to a value from the NL_PREFIX_ORIGIN enumeration, if the SuffixOrigin member is not set to a value
+ /// from the NL_SUFFIX_ORIGIN enumeration, or if the OnLinkPrefixLength member is set to a value greater than the IP address length,
+ /// in bits (32 for a unicast IPv4 address or 128 for a unicast IPv6 address).
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_FOUND
+ ///
+ /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
+ /// InterfaceIndex member of the MIB_UNICASTIPADDRESS_ROW pointed to by the Row parameter could not be found.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
+ /// in the Address member of the MIB_UNICASTIPADDRESS_ROW pointed to by the Row parameter. This error is also returned if no IPv6
+ /// stack is on the local computer and an IPv6 address was specified in the Address member.
+ ///
+ ///
+ /// -
+ /// ERROR_OBJECT_ALREADY_EXISTS
+ ///
+ /// The object already exists. This error is returned if the Address member of the MIB_UNICASTIPADDRESS_ROW pointed to by the Row
+ /// parameter is a duplicate of an existing unicast IP address on the interface specified by the InterfaceLuid or InterfaceIndex
+ /// member of the MIB_UNICASTIPADDRESS_ROW.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The CreateUnicastIpAddressEntry function is defined on Windows Vista and later.
+ ///
+ /// The CreateUnicastIpAddressEntry function is used to add a new unicast IP address entry on a local computer. The unicast IP
+ /// address added by the CreateUnicastIpAddressEntry function is not persistent. The IP address exists only as long as the
+ /// adapter object exists. Restarting the computer destroys the IP address, as does manually resetting the network interface card
+ /// (NIC). Also, certain PnP events may destroy the address.
+ ///
+ ///
+ /// To create an IPv4 address that persists, the EnableStatic method of the Win32_NetworkAdapterConfiguration Class in the Windows
+ /// Management Instrumentation (WMI) controls may be used. The netsh command can also be used to create a persistent IPv4 or IPv6 address.
+ ///
+ /// For more information, please see the documentation on Netsh.exe in the Windows Sockets documentation.
+ ///
+ /// The InitializeUnicastIpAddressEntry function should be used to initialize the members of a MIB_UNICASTIPADDRESS_ROW structure
+ /// entry with default values. An application can then change the members in the MIB_UNICASTIPADDRESS_ROW entry it wishes to
+ /// modify, and then call the CreateUnicastIpAddressEntry function.
+ ///
+ ///
+ /// The Address member in the MIB_UNICASTIPADDRESS_ROW structure pointed to by the Row parameter must be initialized to a
+ /// valid unicast IPv4 or IPv6 address. The si_family member of the SOCKADDR_INET structure in the Address
+ /// member must be initialized to either AF_INET or AF_INET6 and the related Ipv4 or Ipv6 member of the
+ /// SOCKADDR_INET structure must be set to a valid unicast IP address. In addition, at least one of the following members in
+ /// the MIB_UNICASTIPADDRESS_ROW structure pointed to the Row parameter must be initialized to the interface: the
+ /// InterfaceLuid or InterfaceIndex.
+ ///
+ ///
+ /// If the OnLinkPrefixLength member of the MIB_UNICASTIPADDRESS_ROW pointed to by the Row parameter is set to 255, then
+ /// CreateUnicastIpAddressEntry will add the new unicast IP address with the OnLinkPrefixLength member set equal to the
+ /// length of the IP address. So for a unicast IPv4 address, the OnLinkPrefixLength is set to 32 and the
+ /// OnLinkPrefixLength is set to 128 for a unicast IPv6 address. If this would result in the incorrect subnet mask for an IPv4
+ /// address or the incorrect link prefix for an IPv6 address, then the application should set this member to the correct value before
+ /// calling CreateUnicastIpAddressEntry.
+ ///
+ ///
+ /// If a unicast IP address is created with the OnLinkPrefixLength member set incorrectly, then the IP address may be changed
+ /// by calling SetUnicastIpAddressEntry with the OnLinkPrefixLength member set to the correct value.
+ ///
+ ///
+ /// The DadState, ScopeId, and CreationTimeStamp members of the MIB_UNICASTIPADDRESS_ROW structure pointed to by
+ /// the Row are ignored when the CreateUnicastIpAddressEntry function is called. These members are set by the network stack.
+ /// The ScopeId member is automatically determined by the interface on which the address is added. Beginning in Windows 10, if
+ /// DadState is set to IpDadStatePreferred in the MIB_UNICASTIPADDRESS_ROW structure when calling
+ /// CreateUnicastIpAddressEntry, the stack will set the initial DAD state of the address to “preferred” instead of “tentative”
+ /// and will do optimistic DAD for the address.
+ ///
+ ///
+ /// The CreateUnicastIpAddressEntry function will fail if the unicast IP address passed in the Address member of the
+ /// MIB_UNICASTIPADDRESS_ROW pointed to by the Row parameter is a duplicate of an existing unicast IP address on the interface. Note
+ /// that a loopback IP address can only be added to a loopback interface using the CreateUnicastIpAddressEntry function.
+ ///
+ ///
+ /// The unicast IP address passed in the Address member of the MIB_UNICASTIPADDRESS_ROW pointed to by the Row parameter is not
+ /// usable immediately. The IP address is usable after the duplicate address detection process has completed successfully. It can
+ /// take several seconds for the duplicate address detection process to complete since IP packets need to be sent and potential
+ /// responses must be awaited. For IPv6, the duplicate address detection process typically takes about a second. For IPv4, the
+ /// duplicate address detection process typically takes about three seconds.
+ ///
+ ///
+ /// If an application that needs to know when an IP address is usable after a call to the CreateUnicastIpAddressEntry
+ /// function, there are two methods that can be used. One method uses polling and the GetUnicastIpAddressEntry function. The second
+ /// method calls one of the notification functions, NotifyAddrChange, NotifyIpInterfaceChange, or NotifyUnicastIpAddressChange to set
+ /// up an asynchronous notification for when an address changes.
+ ///
+ ///
+ /// The following method describes how to use the GetUnicastIpAddressEntry and polling. After the call to the
+ /// CreateUnicastIpAddressEntry function returns successfully, pause for one to three seconds (depending on whether an IPv6 or
+ /// IPv4 address is being created) to allow time for the successful completion of the duplication address detection process. Then
+ /// call the GetUnicastIpAddressEntry function to retrieve the updated MIB_UNICASTIPADDRESS_ROW structure and examine the
+ /// value of the DadState member. If the value of the DadState member is set to IpDadStatePreferred, the IP
+ /// address is now usable. If the value of the DadState member is set to IpDadStateTentative, then duplicate address
+ /// detection has not yet completed. In this case, call the GetUnicastIpAddressEntry function again every half a second while
+ /// the DadState member is still set to IpDadStateTentative. If the value of the DadState member returns with
+ /// some value other than IpDadStatePreferred or IpDadStateTentative, duplicate address detection has failed and the IP
+ /// address is not usable.
+ ///
+ ///
+ /// The following method describes how to use an appropriate notification function. After the call to the
+ /// CreateUnicastIpAddressEntry function returns successfully, call the NotifyUnicastIpAddressChange function to register to
+ /// be notified of changes to either IPv6 or IPv4 unicast IP addresses, depending on the type of IP address being created. When a
+ /// notification is received for the IP address being created, call the GetUnicastIpAddressEntry function to retrieve the
+ /// DadState member. If the value of the DadState member is set to IpDadStatePreferred, the IP address is now
+ /// usable. If the value of the DadState member is set to IpDadStateTentative, then duplicate address detection has not
+ /// yet completed and the application needs to wait for future notifications. If the value of the DadState member returns with
+ /// some value other than IpDadStatePreferred or IpDadStateTentative, duplicate address detection has failed and the IP
+ /// address is not usable.
+ ///
+ ///
+ /// If during the duplicate address detection process the media is disconnected and then reconnected, the duplicate address detection
+ /// process is restarted. So it is possible for the time to complete the process to increase beyond the typical 1 second value for
+ /// IPv6 or 3 second value for IPv4.
+ ///
+ ///
+ /// The CreateUnicastIpAddressEntry function can only be called by a user logged on as a member of the Administrators group.
+ /// If CreateUnicastIpAddressEntry is called by a user that is not a member of the Administrators group, the function call
+ /// will fail and ERROR_ACCESS_DENIED is returned. This function can also fail because of user account control (UAC) on Windows Vista
+ /// and later. If an application that contains this function is executed by a user logged on as a member of the Administrators group
+ /// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
+ /// requestedExecutionLevel set to requireAdministrator. If the application on lacks this manifest file, a user logged on as a
+ /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced
+ /// shell as the built-in Administrator (RunAs administrator) for this function to succeed.
+ ///
+ /// Examples
+ ///
+ /// The following example demonstrates how to use the CreateUnicastIpAddressEntry function to add a new unicast IP address
+ /// entry on the local computer.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-createunicastipaddressentry _NETIOAPI_SUCCESS_
+ // NETIOAPI_API CreateUnicastIpAddressEntry( CONST MIB_UNICASTIPADDRESS_ROW *Row );
+ [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "8afca4e9-a4c4-4f93-bb4d-25e2eea71ae0")]
+ public static extern Win32Error CreateUnicastIpAddressEntry(ref MIB_UNICASTIPADDRESS_ROW Row);
+
+ ///
+ /// The DeleteAnycastIpAddressEntry function deletes an existing anycast IP address entry on the local computer.
+ ///
+ ///
+ ///
+ /// A pointer to a MIB_ANYCASTIPADDRESS_ROW structure entry for an existing anycast IP address entry to delete from the local computer.
+ ///
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_ACCESS_DENIED
+ ///
+ /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required
+ /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in
+ /// Administrator (RunAs administrator).
+ ///
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
+ /// Address member of the MIB_ANYCASTIPADDRESS_ROW pointed to by the Row parameter was not set to a valid unicast IPv4 or IPv6
+ /// address, or both the InterfaceLuid or InterfaceIndex members of the MIB_ANYCASTIPADDRESS_ROW pointed to by the Row parameter were unspecified.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_FOUND
+ ///
+ /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
+ /// InterfaceIndex member of the MIB_ANYCASTIPADDRESS_ROW pointed to by the Row parameter could not be found.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
+ /// in the Address member MIB_ANYCASTIPADDRESS_ROW pointed to by the Row parameter. This error is also returned if no IPv6 stack is
+ /// on the local computer and an IPv6 address was specified in the Address member .
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The DeleteAnycastIpAddressEntry function is defined on Windows Vista and later.
+ ///
+ /// The DeleteAnycastIpAddressEntry function is used to delete an existing MIB_ANYCASTIPADDRESS_ROW structure entry on the
+ /// local computer.
+ ///
+ ///
+ /// On input, the Address member in the MIB_ANYCASTIPADDRESS_ROW structure pointed to by the Row parameter must be set to a
+ /// valid unicast IPv4 or IPv6 address and family. In addition, at least one of the following members in the
+ /// MIB_ANYCASTIPADDRESS_ROW structure pointed to the Row parameter must be initialized: the InterfaceLuid or InterfaceIndex.
+ ///
+ /// If the function is successful, the existing IP address represented by the Row parameter was deleted.
+ ///
+ /// The GetAnycastIpAddressTable function can be called to enumerate the anycast IP address entries on a local computer. The
+ /// GetAnycastIpAddressEntry function can be called to retrieve a specific existing anycast IP address entry.
+ ///
+ ///
+ /// The DeleteAnycastIpAddressEntry function can only be called by a user logged on as a member of the Administrators group.
+ /// If DeleteAnycastIpAddressEntry is called by a user that is not a member of the Administrators group, the function call
+ /// will fail and ERROR_ACCESS_DENIED is returned. This function can also fail because of user account control (UAC) on
+ /// Windows Vista and later. If an application that contains this function is executed by a user logged on as a member of the
+ /// Administrators group other than the built-in Administrator, this call will fail unless the application has been marked in the
+ /// manifest file with a requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a
+ /// user logged on as a member of the Administrators group other than the built-in Administrator must then be executing the
+ /// application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-deleteanycastipaddressentry _NETIOAPI_SUCCESS_
+ // NETIOAPI_API DeleteAnycastIpAddressEntry( CONST MIB_ANYCASTIPADDRESS_ROW *Row );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "3d6b7c5c-97a8-4a1d-a4cd-7ccf1f585305")]
+ public static extern Win32Error DeleteAnycastIpAddressEntry(ref MIB_ANYCASTIPADDRESS_ROW Row);
+
+ ///
+ /// The DeleteIpForwardEntry2 function deletes an IP route entry on the local computer.
+ ///
+ ///
+ /// A pointer to a MIB_IPFORWARD_ROW2 structure entry for an IP route entry. On successful return, this entry will be deleted.
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_ACCESS_DENIED
+ ///
+ /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required
+ /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in
+ /// Administrator (RunAs administrator).
+ ///
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
+ /// DestinationPrefix member of the MIB_IPFORWARD_ROW2 pointed to by the Row parameter was not specified, the NextHop member of the
+ /// MIB_IPFORWARD_ROW2 pointed to by the Row parameter was not specified, or both the InterfaceLuid or InterfaceIndex members of the
+ /// MIB_IPFORWARD_ROW2 pointed to by the Row parameter were unspecified.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_FOUND
+ ///
+ /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
+ /// InterfaceIndex member of the MIB_IPFORWARD_ROW2 pointed to by the Row parameter could not be found.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
+ /// in the Address member of the MIB_IPFORWARD_ROW2 pointed to by the Row parameter. This error is also returned if no IPv6 stack is
+ /// on the local computer and an IPv6 address was specified in the Address member.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The DeleteIpForwardEntry2 function is defined on Windows Vista and later.
+ /// The DeleteIpForwardEntry2 function is used to delete a MIB_IPFORWARD_ROW2 structure entry.
+ ///
+ /// On input, the DestinationPrefix member in the MIB_IPFORWARD_ROW2 structure pointed to by the Row parameter must be
+ /// initialized to a valid IPv4 or IPv6 address prefix and family. On input, the NextHop member in the
+ /// MIB_IPFORWARD_ROW2 structure pointed to by the Row parameter must be initialized to a valid IPv4 or IPv6 address and
+ /// family. In addition, at least one of the following members in the MIB_IPFORWARD_ROW2 structure pointed to the Row
+ /// parameter must be initialized: the InterfaceLuid or InterfaceIndex.
+ ///
+ /// On output when the call is successful, DeleteIpForwardEntry2 deletes the IP route entry.
+ ///
+ /// The DeleteIpForwardEntry2 function will fail if the DestinationPrefix and NextHop members of the
+ /// MIB_IPFORWARD_ROW2 pointed to by the Row parameter do not match an existing IP route entry on the interface specified in the
+ /// InterfaceLuid or InterfaceIndex members.
+ ///
+ /// The GetIpForwardTable2 function can be called to enumerate the IP route entries on a local computer.
+ ///
+ /// The DeleteIpForwardEntry2 function can only be called by a user logged on as a member of the Administrators group. If
+ /// DeleteIpForwardEntry2 is called by a user that is not a member of the Administrators group, the function call will fail
+ /// and ERROR_ACCESS_DENIED is returned. This function can also fail because of user account control (UAC) on Windows Vista
+ /// and later. If an application that contains this function is executed by a user logged on as a member of the Administrators group
+ /// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
+ /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a
+ /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced
+ /// shell as the built-in Administrator (RunAs administrator) for this function to succeed.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-deleteipforwardentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // DeleteIpForwardEntry2( CONST MIB_IPFORWARD_ROW2 *Row );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "68d5a5a5-21cf-4337-8a35-7f847f5e2138")]
+ public static extern Win32Error DeleteIpForwardEntry2(ref MIB_IPFORWARD_ROW2 Row);
+
+ ///
+ /// The DeleteIpNetEntry2 function deletes a neighbor IP address entry on the local computer.
+ ///
+ ///
+ ///
+ /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this entry will be deleted.
+ ///
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_ACCESS_DENIED
+ ///
+ /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required
+ /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in
+ /// Administrator (RunAs administrator).
+ ///
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
+ /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid neighbor IPv4 or IPv6 address, or
+ /// both the InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the Row parameter were unspecified.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_FOUND
+ ///
+ /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
+ /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
+ /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter. This error is also returned if no IPv6 stack is on
+ /// the local computer and an IPv6 address was specified in the Address member.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The DeleteIpNetEntry2 function is defined on Windows Vista and later.
+ /// The DeleteIpNetEntry2 function is used to delete a MIB_IPNET_ROW2 structure entry.
+ ///
+ /// On input, the Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a
+ /// valid neighbor IPv4 or IPv6 address and family. In addition, at least one of the following members in the MIB_IPNET_ROW2
+ /// structure pointed to the Row parameter must be initialized: the InterfaceLuid or InterfaceIndex.
+ ///
+ /// On output when the call is successful, DeleteIpNetEntry2 deletes the neighbor IP address.
+ /// The GetIpNetTable2 function can be called to enumerate the neighbor IP address entries on a local computer.
+ ///
+ /// The DeleteIpNetEntry2 function can only be called by a user logged on as a member of the Administrators group. If
+ /// DeleteIpNetEntry2 is called by a user that is not a member of the Administrators group, the function call will fail and
+ /// ERROR_ACCESS_DENIED is returned. This function can also fail because of user account control (UAC) on Windows Vista and
+ /// later. If an application that contains this function is executed by a user logged on as a member of the Administrators group
+ /// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
+ /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a
+ /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced
+ /// shell as the built-in Administrator (RunAs administrator) for this function to succeed.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-deleteipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // DeleteIpNetEntry2( CONST MIB_IPNET_ROW2 *Row );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "85bace04-6c95-4cf2-a212-764de292aed6")]
+ public static extern Win32Error DeleteIpNetEntry2(ref MIB_IPNET_ROW2 Row);
+
+ ///
+ /// The FlushIpNetTable2 function flushes the IP neighbor table on the local computer.
+ ///
+ ///
+ /// The address family to flush.
+ ///
+ /// Possible values for the address family are listed in the Winsock2.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.
+ ///
+ ///
+ /// On the Windows SDK released for Windows Vista and later, the organization of header files has changed and possible values for
+ /// this member are 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.
+ ///
+ /// The values currently supported are AF_INET, AF_INET6, and AF_UNSPEC.
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// AF_UNSPEC 0
+ ///
+ /// The address family is unspecified. When this parameter is specified, this function flushes the neighbor IP address table
+ /// containing both IPv4 and IPv6 entries.
+ ///
+ ///
+ /// -
+ /// AF_INET 2
+ ///
+ /// The Internet Protocol version 4 (IPv4) address family. When this parameter is specified, this function flushes the neighbor IP
+ /// address table containing only IPv4 entries.
+ ///
+ ///
+ /// -
+ /// AF_INET6 23
+ ///
+ /// The Internet Protocol version 6 (IPv6) address family. When this parameter is specified, this function flushes the neighbor IP
+ /// address table containing only IPv6 entries.
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// The interface index. If the index is specified, flush the neighbor IP address entries on a specific interface, otherwise flush
+ /// the neighbor IP address entries on all the interfaces. To ignore the interface, set this parameter to zero.
+ ///
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_ACCESS_DENIED
+ ///
+ /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required
+ /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in
+ /// Administrator (RunAs administrator).
+ ///
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if the Family parameter was not specified as AF_INET,
+ /// AF_INET6, or AF_UNSPEC.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and AF_INET was specified in the
+ /// Family parameter. This error is also returned if no IPv6 stack is on the local computer and AF_INET6 was specified in the Family
+ /// parameter. This error is also returned on versions of Windows where this function is not supported.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The FlushIpNetTable2 function is defined on Windows Vista and later.
+ ///
+ /// The FlushIpNetTable2 function flushes or deletes the neighbor IP addresses on a local system. The Family parameter can be
+ /// used to limit neighbor IP addresses to delete to a particular IP address family. If neighbor IP addresses for both IPv4 and IPv6
+ /// should be deleted, set the Family parameter to AF_UNSPEC. The InterfaceIndex parameter can be used to limit neighbor IP
+ /// addresses to delete to a particular interface. If neighbor IP addresses for all interfaces should be deleted, set the
+ /// InterfaceIndex parameter to zero.
+ ///
+ /// The Family parameter must be initialized to either AF_INET, AF_INET6, or AF_UNSPEC.
+ ///
+ /// The FlushIpNetTable2 function can only be called by a user logged on as a member of the Administrators group. If
+ /// FlushIpNetTable2 is called by a user that is not a member of the Administrators group, the function call will fail and
+ /// ERROR_ACCESS_DENIED is returned. This function can also fail because of user account control (UAC) on Windows Vista and
+ /// later. If an application that contains this function is executed by a user logged on as a member of the Administrators group
+ /// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
+ /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a
+ /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced
+ /// shell as the built-in Administrator (RunAs administrator) for this function to succeed.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-flushipnettable2 _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // FlushIpNetTable2( ADDRESS_FAMILY Family, NET_IFINDEX InterfaceIndex );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "6ebfca41-acc3-450c-a3c5-881b8c3fca5e")]
+ public static extern Win32Error FlushIpNetTable2(ADDRESS_FAMILY Family, uint InterfaceIndex);
+
+ ///
+ ///
+ /// The FreeMibTable function frees the buffer allocated by the functions that return tables of network interfaces, addresses,
+ /// and routes (GetIfTable2 and GetAnycastIpAddressTable, for example).
+ ///
+ ///
+ ///
+ /// A pointer to the buffer to free.
+ ///
+ ///
+ /// This function does not return a value.
+ ///
+ ///
+ /// The FreeMibTable function is defined on Windows Vista and later.
+ ///
+ /// The FreeMibTable function is used to free the internal buffers used by various functions to retrieve tables of interfaces,
+ /// addresses, and routes. When these tables are no longer needed, then FreeMibTable should be called to release the memory
+ /// used by these tables.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-freemibtable VOID NETIOAPI_API_ FreeMibTable( PVOID
+ // Memory );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "31c8cdc4-73c7-4e82-8226-c90320046199")]
+ public static extern void FreeMibTable(IntPtr Memory);
+
+ ///
+ ///
+ /// The GetBestRoute2 function retrieves the IP route entry on the local computer for the best route to the specified
+ /// destination IP address.
+ ///
+ ///
+ ///
+ /// The locally unique identifier (LUID) to specify the network interface associated with an IP route entry.
+ ///
+ ///
+ ///
+ /// The local index value to specify the network interface associated with an IP route entry. This index value may change when a
+ /// network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.
+ ///
+ ///
+ ///
+ /// The source IP address. This parameter may be omitted and passed as a NULL pointer.
+ ///
+ ///
+ /// The destination IP address.
+ ///
+ ///
+ /// A set of options that affect how IP addresses are sorted. This parameter is not currently used.
+ ///
+ ///
+ /// A pointer to the MIB_IPFORWARD_ROW2 for the best route from the source IP address to the destination IP address.
+ ///
+ ///
+ /// A pointer to the best source IP address.
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the DestinationAddress,
+ /// BestSourceAddress, or the BestRoute parameter. This error is also returned if the DestinationAddress parameter does not specify
+ /// an IPv4 or IPv6 address and family.
+ ///
+ ///
+ /// -
+ /// ERROR_FILE_NOT_FOUND
+ ///
+ /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
+ /// InterfaceIndex parameter could not be found.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address and family was
+ /// specified in the DestinationAddress parameter. This error is also returned if no IPv6 stack is on the local computer and an IPv6
+ /// address and family was specified in the DestinationAddress parameter.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The GetBestRoute2 function is defined on Windows Vista and later.
+ ///
+ /// The GetBestRoute2 function is used to retrieve a MIB_IPFORWARD_ROW2 structure entry for the best route from a source IP
+ /// address to a destination IP address.
+ ///
+ ///
+ /// On input, the DestinationAddress parameter must be initialized to a valid IPv4 or IPv6 address and family. On input, the
+ /// SourceAddress parameter may be initialized to the preferred IPv4 or IPv6 address and family. In addition, at least one of the
+ /// following parameters must be initialized: the InterfaceLuid or InterfaceIndex.
+ ///
+ ///
+ /// On output when the call is successful, GetBestRoute2 retrieves and MIB_IPFORWARD_ROW2 structure for the best route from
+ /// the source IP address the destination IP address.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getbestroute2 _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // GetBestRoute2( NET_LUID *InterfaceLuid, NET_IFINDEX InterfaceIndex, CONST SOCKADDR_INET *SourceAddress, CONST SOCKADDR_INET
+ // *DestinationAddress, ULONG AddressSortOptions, PMIB_IPFORWARD_ROW2 BestRoute, SOCKADDR_INET *BestSourceAddress );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "7bc16824-c98f-4cd5-a589-e198b48b637c")]
+ public static extern Win32Error GetBestRoute2(ref NET_LUID InterfaceLuid, uint InterfaceIndex, ref SOCKADDR_INET SourceAddress, ref SOCKADDR_INET DestinationAddress, uint AddressSortOptions, out MIB_IPFORWARD_ROW2 BestRoute, out SOCKADDR_INET BestSourceAddress);
+
+ ///
+ ///
+ /// The GetBestRoute2 function retrieves the IP route entry on the local computer for the best route to the specified
+ /// destination IP address.
+ ///
+ ///
+ ///
+ /// The locally unique identifier (LUID) to specify the network interface associated with an IP route entry.
+ ///
+ ///
+ ///
+ /// The local index value to specify the network interface associated with an IP route entry. This index value may change when a
+ /// network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.
+ ///
+ ///
+ ///
+ /// The source IP address. This parameter may be omitted and passed as a NULL pointer.
+ ///
+ ///
+ /// The destination IP address.
+ ///
+ ///
+ /// A set of options that affect how IP addresses are sorted. This parameter is not currently used.
+ ///
+ ///
+ /// A pointer to the MIB_IPFORWARD_ROW2 for the best route from the source IP address to the destination IP address.
+ ///
+ ///
+ /// A pointer to the best source IP address.
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the DestinationAddress,
+ /// BestSourceAddress, or the BestRoute parameter. This error is also returned if the DestinationAddress parameter does not specify
+ /// an IPv4 or IPv6 address and family.
+ ///
+ ///
+ /// -
+ /// ERROR_FILE_NOT_FOUND
+ ///
+ /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
+ /// InterfaceIndex parameter could not be found.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address and family was
+ /// specified in the DestinationAddress parameter. This error is also returned if no IPv6 stack is on the local computer and an IPv6
+ /// address and family was specified in the DestinationAddress parameter.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The GetBestRoute2 function is defined on Windows Vista and later.
+ ///
+ /// The GetBestRoute2 function is used to retrieve a MIB_IPFORWARD_ROW2 structure entry for the best route from a source IP
+ /// address to a destination IP address.
+ ///
+ ///
+ /// On input, the DestinationAddress parameter must be initialized to a valid IPv4 or IPv6 address and family. On input, the
+ /// SourceAddress parameter may be initialized to the preferred IPv4 or IPv6 address and family. In addition, at least one of the
+ /// following parameters must be initialized: the InterfaceLuid or InterfaceIndex.
+ ///
+ ///
+ /// On output when the call is successful, GetBestRoute2 retrieves and MIB_IPFORWARD_ROW2 structure for the best route from
+ /// the source IP address the destination IP address.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getbestroute2 _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // GetBestRoute2( NET_LUID *InterfaceLuid, NET_IFINDEX InterfaceIndex, CONST SOCKADDR_INET *SourceAddress, CONST SOCKADDR_INET
+ // *DestinationAddress, ULONG AddressSortOptions, PMIB_IPFORWARD_ROW2 BestRoute, SOCKADDR_INET *BestSourceAddress );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "7bc16824-c98f-4cd5-a589-e198b48b637c")]
+ public static extern Win32Error GetBestRoute2(IntPtr InterfaceLuid, uint InterfaceIndex, ref SOCKADDR_INET SourceAddress, ref SOCKADDR_INET DestinationAddress, uint AddressSortOptions, out MIB_IPFORWARD_ROW2 BestRoute, out SOCKADDR_INET BestSourceAddress);
+
+ ///
+ ///
+ /// The GetBestRoute2 function retrieves the IP route entry on the local computer for the best route to the specified
+ /// destination IP address.
+ ///
+ ///
+ ///
+ /// The locally unique identifier (LUID) to specify the network interface associated with an IP route entry.
+ ///
+ ///
+ ///
+ /// The local index value to specify the network interface associated with an IP route entry. This index value may change when a
+ /// network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.
+ ///
+ ///
+ ///
+ /// The source IP address. This parameter may be omitted and passed as a NULL pointer.
+ ///
+ ///
+ /// The destination IP address.
+ ///
+ ///
+ /// A set of options that affect how IP addresses are sorted. This parameter is not currently used.
+ ///
+ ///
+ /// A pointer to the MIB_IPFORWARD_ROW2 for the best route from the source IP address to the destination IP address.
+ ///
+ ///
+ /// A pointer to the best source IP address.
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the DestinationAddress,
+ /// BestSourceAddress, or the BestRoute parameter. This error is also returned if the DestinationAddress parameter does not specify
+ /// an IPv4 or IPv6 address and family.
+ ///
+ ///
+ /// -
+ /// ERROR_FILE_NOT_FOUND
+ ///
+ /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
+ /// InterfaceIndex parameter could not be found.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address and family was
+ /// specified in the DestinationAddress parameter. This error is also returned if no IPv6 stack is on the local computer and an IPv6
+ /// address and family was specified in the DestinationAddress parameter.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The GetBestRoute2 function is defined on Windows Vista and later.
+ ///
+ /// The GetBestRoute2 function is used to retrieve a MIB_IPFORWARD_ROW2 structure entry for the best route from a source IP
+ /// address to a destination IP address.
+ ///
+ ///
+ /// On input, the DestinationAddress parameter must be initialized to a valid IPv4 or IPv6 address and family. On input, the
+ /// SourceAddress parameter may be initialized to the preferred IPv4 or IPv6 address and family. In addition, at least one of the
+ /// following parameters must be initialized: the InterfaceLuid or InterfaceIndex.
+ ///
+ ///
+ /// On output when the call is successful, GetBestRoute2 retrieves and MIB_IPFORWARD_ROW2 structure for the best route from
+ /// the source IP address the destination IP address.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getbestroute2 _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // GetBestRoute2( NET_LUID *InterfaceLuid, NET_IFINDEX InterfaceIndex, CONST SOCKADDR_INET *SourceAddress, CONST SOCKADDR_INET
+ // *DestinationAddress, ULONG AddressSortOptions, PMIB_IPFORWARD_ROW2 BestRoute, SOCKADDR_INET *BestSourceAddress );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "7bc16824-c98f-4cd5-a589-e198b48b637c")]
+ public static extern Win32Error GetBestRoute2(IntPtr InterfaceLuid, uint InterfaceIndex, IntPtr SourceAddress, ref SOCKADDR_INET DestinationAddress, uint AddressSortOptions, out MIB_IPFORWARD_ROW2 BestRoute, out SOCKADDR_INET BestSourceAddress);
+
+ ///
+ /// The GetIfEntry2 function retrieves information for the specified interface on the local computer.
+ ///
+ ///
+ ///
+ /// A pointer to a MIB_IF_ROW2 structure that, on successful return, receives information for an interface on the local computer. On
+ /// input, the InterfaceLuid or the InterfaceIndex member of the MIB_IF_ROW2 must be set to the interface for
+ /// which to retrieve information.
+ ///
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_FILE_NOT_FOUND
+ ///
+ /// The system cannot find the file specified. This error is returned if the network interface LUID or interface index specified by
+ /// the InterfaceLuid or InterfaceIndex member of the MIB_IF_ROW2 pointed to by the Row parameter was not a value on the local machine.
+ ///
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL parameter is passed in the Row parameter. This
+ /// error is also returned if the both the InterfaceLuid and InterfaceIndex member of the MIB_IF_ROW2 pointed to by the Row parameter
+ /// are unspecified.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use the FormatMessage function to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The GetIfEntry2 function is defined on Windows Vista and later.
+ ///
+ /// On input, at least one of the following members in the MIB_IF_ROW2 structure passed in the Row parameter must be initialized:
+ /// InterfaceLuid or InterfaceIndex.
+ ///
+ /// On output, the remaining fields of the MIB_IF_ROW2 structure pointed to by the Row parameter are filled in.
+ /// Note that the Netioapi.h header file is automatically included in IpHlpApi.h header file, and should never be used directly.
+ /// Examples
+ ///
+ /// The following example retrieves a interface entry specified on the command line and prints some values from the retrieved
+ /// MIB_IF_ROW2 structure.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getifentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API GetIfEntry2(
+ // PMIB_IF_ROW2 Row );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "da787dae-5e89-4bf2-a9b6-90e727995414")]
+ public static extern Win32Error GetIfEntry2(ref MIB_IF_ROW2 Row);
+
+ ///
+ ///
+ /// The GetIfEntry2Ex function retrieves the specified level of information for the specified interface on the local computer.
+ ///
+ ///
+ ///
+ ///
+ /// The level of interface information to retrieve. This parameter can be one of the values from the MIB_IF_ENTRY_LEVEL
+ /// enumeration type defined in the Netioapi.h header file.
+ ///
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// MibIfEntryNormal 0
+ ///
+ /// The values of statistics and state returned in members of the MIB_IF_ROW2 structure pointed to by the Row parameter are returned
+ /// from the top of the filter stack.
+ ///
+ ///
+ /// -
+ /// MibIfEntryNormalWithoutStatistics 2
+ ///
+ /// The values of state (without statistics) returned in members of the MIB_IF_ROW2 structure pointed to by the Row parameter are
+ /// returned from the top of the filter stack.
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// A pointer to a MIB_IF_ROW2 structure that, on successful return, receives information for an interface on the local computer. On
+ /// input, the InterfaceLuid or the InterfaceIndex member of the MIB_IF_ROW2 must be set to the interface for
+ /// which to retrieve information.
+ ///
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_FILE_NOT_FOUND
+ ///
+ /// The system cannot find the file specified. This error is returned if the network interface LUID or interface index specified by
+ /// the InterfaceLuid or InterfaceIndex member of the MIB_IF_ROW2 pointed to by the Row parameter was not a value on the local machine.
+ ///
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL parameter is passed in the Row parameter. This
+ /// error is also returned if the both the InterfaceLuid and InterfaceIndex member of the MIB_IF_ROW2 pointed to by the Row parameter
+ /// are unspecified.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use the FormatMessage function to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// The GetIfEntry2Ex function retrieves information for a specified interface on a local system and returns this information
+ /// in a pointer to a MIB_IF_ROW2 structure. GetIfEntry2Ex is an enhanced version of the GetIfEntry2 function that allows
+ /// selecting the level of interface information to retrieve.
+ ///
+ ///
+ /// On input, at least one of the following members in the MIB_IF_ROW2 structure passed in the Row parameter must be initialized:
+ /// InterfaceLuid or InterfaceIndex.
+ ///
+ /// On output, the remaining fields of the MIB_IF_ROW2 structure pointed to by the Row parameter are filled in.
+ /// Note that the Netioapi.h header file is automatically included in IpHlpApi.h header file, and should never be used directly.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getifentry2ex _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // GetIfEntry2Ex( MIB_IF_ENTRY_LEVEL Level, PMIB_IF_ROW2 Row );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "98C25986-1B38-4878-B578-3D30394F49E4")]
+ public static extern Win32Error GetIfEntry2Ex(MIB_IF_ENTRY_LEVEL Level, ref MIB_IF_ROW2 Row);
+
+ ///
+ /// The GetIfTable2 function retrieves the MIB-II interface table.
+ ///
+ ///
+ /// A pointer to a buffer that receives the table of interfaces in a MIB_IF_TABLE2 structure.
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_NOT_ENOUGH_MEMORY
+ /// Insufficient memory resources are available to complete the operation.
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// The GetIfTable2 function enumerates the logical and physical interfaces on a local system and returns this information in
+ /// a MIB_IF_TABLE2 structure. GetIfTable2 is an enhanced version of the GetIfTable function.
+ ///
+ ///
+ /// A similar GetIfTable2Ex function can be used to specify the level of interfaces to return. Calling the GetIfTable2Ex
+ /// function with the Level parameter set to MibIfTableNormal retrieves the same results as calling the GetIfTable2 function.
+ ///
+ ///
+ /// Interfaces are returned in a MIB_IF_TABLE2 structure in the buffer pointed to by the Table parameter. The MIB_IF_TABLE2
+ /// structure contains an interface count and an array of MIB_IF_ROW2 structures for each interface. Memory is allocated by the
+ /// GetIfTable2 function for the MIB_IF_TABLE2 structure and the MIB_IF_ROW2 entries in this structure. When
+ /// these returned structures are no longer required, free the memory by calling the FreeMibTable.
+ ///
+ ///
+ /// Note that the returned MIB_IF_TABLE2 structure pointed to by the Table parameter may contain padding for alignment between the
+ /// NumEntries member and the first MIB_IF_ROW2 array entry in the Table member of the MIB_IF_TABLE2 structure.
+ /// Padding for alignment may also be present between the MIB_IF_ROW2 array entries. Any access to a MIB_IF_ROW2 array
+ /// entry should assume padding may exist.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getiftable2 _NETIOAPI_SUCCESS_ NETIOAPI_API GetIfTable2(
+ // PMIB_IF_TABLE2 *Table );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "0153c41c-b02b-4832-87b3-88dc3a9f4ff1")]
+ public static extern Win32Error GetIfTable2(out MIB_IF_TABLE2 pIfTable);
+
+ ///
+ /// The GetIfTable2Ex function retrieves the MIB-II interface table.
+ ///
+ ///
+ ///
+ /// The level of interface information to retrieve. This parameter can be one of the values from the MIB_IF_TABLE_LEVEL
+ /// enumeration type defined in the Netioapi.h header file.
+ ///
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// MibIfTableNormal
+ ///
+ /// The values of statistics and state returned in members of the MIB_IF_ROW2 structure in the MIB_IF_TABLE2 structure pointed to by
+ /// the Table parameter are returned from the top of the filter stack when this parameter is specified.
+ ///
+ ///
+ /// -
+ /// MibIfTableRaw
+ ///
+ /// The values of statistics and state returned in members of the MIB_IF_ROW2 structure in the MIB_IF_TABLE2 structure pointed to by
+ /// the Table parameter are returned directly for the interface being queried.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// A pointer to a buffer that receives the table of interfaces in a MIB_IF_TABLE2 structure.
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ /// An invalid parameter was passed to the function. This error is returned if an illegal value was passed in the Level parameter.
+ ///
+ /// -
+ /// ERROR_NOT_ENOUGH_MEMORY
+ /// Insufficient memory resources are available to complete the operation.
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// The GetIfTable2Ex function enumerates the logical and physical interfaces on a local system and returns this information
+ /// in a MIB_IF_TABLE2 structure. GetIfTable2Ex is an enhanced version of the GetIfTable function that allows selecting
+ /// the level of interface information to retrieve.
+ ///
+ ///
+ /// A similar GetIfTable2 function can also be used to retrieve interfaces. but does not allow specifying the level of interfaces to
+ /// return. Calling the GetIfTable2Ex function with the Level parameter set to MibIfTableNormal retrieves the same
+ /// results as calling the GetIfTable2 function.
+ ///
+ ///
+ /// Interfaces are returned in a MIB_IF_TABLE2 structure in the buffer pointed to by the Table parameter. The MIB_IF_TABLE2
+ /// structure contains an interface count and an array of MIB_IF_ROW2 structures for each interface. Memory is allocated by the
+ /// GetIfTable2 function for the MIB_IF_TABLE2 structure and the MIB_IF_ROW2 entries in this structure. When these
+ /// returned structures are no longer required, free the memory by calling the FreeMibTable.
+ ///
+ ///
+ /// All interfaces including NDIS intermediate driver interfaces and NDIS filter driver interfaces are returned for either of the
+ /// possible values for the Level parameter. The setting for the Level parameter affects how statistics and state members of the
+ /// MIB_IF_ROW2 structure in the MIB_IF_TABLE2 structure pointed to by the Table parameter for the interface are returned. For
+ /// example, a network interface card (NIC) will have a NDIS miniport driver. An NDIS intermediate driver can be installed to
+ /// interface between upper-level protocol drivers and NDIS miniport drivers. An NDIS filter driver (LWF) can be attached on top of
+ /// the NDIS intermediate driver. Assume that the NIC reports the MediaConnectState member of the MIB_IF_ROW2 structure as
+ /// MediaConnectStateConnected but NDIS filter driver modifies the state and reports the state as
+ /// MediaConnectStateDisconnected. When the interface information is queried with Level parameter set to
+ /// MibIfTableNormal, the state at the top of the filter stack, that is MediaConnectStateDisconnected is reported. When
+ /// the interface is queried with the Level parameter set to MibIfTableRaw, the state at the interface level directly, that is
+ /// MediaConnectStateConnected is returned.
+ ///
+ ///
+ /// Note that the returned MIB_IF_TABLE2 structure pointed to by the Table parameter may contain padding for alignment between the
+ /// NumEntries member and the first MIB_IF_ROW2 array entry in the Table member of the MIB_IF_TABLE2 structure.
+ /// Padding for alignment may also be present between the MIB_IF_ROW2 array entries. Any access to a MIB_IF_ROW2 array
+ /// entry should assume padding may exist.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getiftable2ex _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // GetIfTable2Ex( MIB_IF_TABLE_LEVEL Level, PMIB_IF_TABLE2 *Table );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "d8663894-50b1-4ca2-a1f4-6ca0970795a7")]
+ public static extern Win32Error GetIfTable2Ex(MIB_IF_TABLE_LEVEL Level, out MIB_IF_TABLE2 pIfTable);
+
+ ///
+ /// The GetIpNetEntry2 function retrieves information for a neighbor IP address entry on the local computer.
+ ///
+ ///
+ ///
+ /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this structure will be
+ /// updated with the properties for neighbor IP address.
+ ///
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_FILE_NOT_FOUND
+ ///
+ /// The system cannot find the file specified. This error is returned if the network interface LUID or interface index specified by
+ /// the InterfaceLuid or InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not a value on the local machine.
+ ///
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
+ /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid neighbor IPv4 or IPv6 address, or
+ /// both the InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the Row parameter were unspecified.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_FOUND
+ ///
+ /// Element not found. This error is returned if the network interface specified by the InterfaceLuid or InterfaceIndex member of the
+ /// MIB_IPNET_ROW2 structure pointed to by the Row parameter does not match the neighbor IP address and address family specified in
+ /// the Address member in the MIB_IPNET_ROW2 structure.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
+ /// in the Address member of the MIB_IPNET_ROW2 structure pointed to by the Row parameter. This error is also returned if no IPv6
+ /// stack is on the local computer and an IPv6 address was specified in the Address member of the MIB_IPNET_ROW2 structure.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The GetIpNetEntry2 function is defined on Windows Vista and later.
+ /// The GetIpNetEntry2 function is used to retrieve a MIB_IPNET_ROW2 structure entry.
+ ///
+ /// On input, the Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a
+ /// valid neighbor IPv4 or IPv6 address and family. In addition, at least one of the following members in the MIB_IPNET_ROW2
+ /// structure pointed to the Row parameter must be initialized: the InterfaceLuid or InterfaceIndex.
+ ///
+ ///
+ /// On output when the call is successful, GetIpNetEntry2 retrieves the other properties for the neighbor IP address and fills
+ /// out the MIB_IPNET_ROW2 structure pointed to by the Row parameter.
+ ///
+ /// The GetIpNetTable2 function can be called to enumerate the neighbor IP address entries on a local computer.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // GetIpNetEntry2( PMIB_IPNET_ROW2 Row );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "c77e01da-2d5a-4c74-b581-62fa6ee52c9e")]
+ public static extern Win32Error GetIpNetEntry2(ref MIB_IPNET_ROW2 Row);
+
+ ///
+ /// The GetIpNetTable2 function retrieves the IP neighbor table on the local computer.
+ ///
+ ///
+ /// The address family to retrieve.
+ ///
+ /// Possible values for the address family are listed in the Winsock2.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.
+ ///
+ ///
+ /// On the Windows SDK released for Windows Vista and later, the organization of header files has changed and possible values for
+ /// this member are 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.
+ ///
+ /// The values currently supported are AF_INET, AF_INET6, and AF_UNSPEC.
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// AF_UNSPEC 0
+ ///
+ /// The address family is unspecified. When this parameter is specified, this function returns the neighbor IP address table
+ /// containing both IPv4 and IPv6 entries.
+ ///
+ ///
+ /// -
+ /// AF_INET 2
+ ///
+ /// The Internet Protocol version 4 (IPv4) address family. When this parameter is specified, this function returns the neighbor IP
+ /// address table containing only IPv4 entries.
+ ///
+ ///
+ /// -
+ /// AF_INET6 23
+ ///
+ /// The Internet Protocol version 6 (IPv6) address family. When this parameter is specified, this function returns the neighbor IP
+ /// address table containing only IPv6 entries.
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// A pointer to a MIB_IPNET_TABLE2 structure that contains a table of neighbor IP address entries on the local computer.
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR or ERROR_NOT_FOUND.
+ /// If the function fails or returns no data, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Table parameter or the
+ /// Family parameter was not specified as AF_INET, AF_INET6, or AF_UNSPEC.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_ENOUGH_MEMORY
+ /// Insufficient memory resources are available to complete the operation.
+ ///
+ /// -
+ /// ERROR_NOT_FOUND
+ ///
+ /// No neighbor IP address entries as specified in the Family parameter were found. This return value indicates that the call to the
+ /// GetIpNetTable2 function succeeded, but there was no data to return. This can occur when AF_INET is specified in the Family
+ /// parameter and there are no ARP entries to return.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and AF_INET was specified in the
+ /// Family parameter. This error is also returned if no IPv6 stack is on the local computer and AF_INET6 was specified in the Family
+ /// parameter. This error is also returned on versions of Windows where this function is not supported.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The GetIpNetTable2 function is defined on Windows Vista and later.
+ ///
+ /// The GetIpNetTable2 function enumerates the neighbor IP addresses on a local system and returns this information in a
+ /// MIB_IPNET_TABLE2 structure.
+ ///
+ ///
+ /// The neighbor IP address entries are returned in a MIB_IPNET_TABLE2 structure in the buffer pointed to by the Table parameter. The
+ /// MIB_IPNET_TABLE2 structure contains a neighbor IP address entry count and an array of MIB_IPNET_ROW2 structures for each
+ /// neighbor IP address entry. When these returned structures are no longer required, free the memory by calling the FreeMibTable.
+ ///
+ /// The Family parameter must be initialized to either AF_INET, AF_INET6, or AF_UNSPEC.
+ ///
+ /// Note that the returned MIB_IPNET_TABLE2 structure pointed to by the Table parameter may contain padding for alignment between the
+ /// NumEntries member and the first MIB_IPNET_ROW2 array entry in the Table member of the MIB_IPNET_TABLE2
+ /// structure. Padding for alignment may also be present between the MIB_IPNET_ROW2 array entries. Any access to a
+ /// MIB_IPNET_ROW2 array entry should assume padding may exist.
+ ///
+ /// Examples
+ /// The following example retrieves the IP neighbor table, then prints the values for IP neighbor row entries in the table.
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getipnettable2 _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // GetIpNetTable2( ADDRESS_FAMILY Family, PMIB_IPNET_TABLE2 *Table );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "6c45d735-9a07-41ca-8d8a-919f32c98a3c")]
+ public static extern Win32Error GetIpNetTable2(ADDRESS_FAMILY Family, out MIB_IPNET_TABLE2 Table);
+
+ ///
+ /// The ResolveIpNetEntry2 function resolves the physical address for a neighbor IP address entry on the local computer.
+ ///
+ ///
+ ///
+ /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this structure will be
+ /// updated with the properties for neighbor IP address.
+ ///
+ ///
+ ///
+ ///
+ /// A pointer to a an optional source IP address used to select the interface to send the requests on for the neighbor IP address entry.
+ ///
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_BAD_NET_NAME
+ /// The network name cannot be found. This error is returned if the network with the neighbor IP address is unreachable.
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
+ /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid IPv4 or IPv6 address, or both the
+ /// InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the Row parameter were unspecified. This error is
+ /// also returned if a loopback address was passed in the Address member.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_FOUND
+ ///
+ /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
+ /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
+ /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter or no IPv6 stack is on the local computer and an IPv6
+ /// address was specified in the Address member.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The ResolveIpNetEntry2 function is defined on Windows Vista and later.
+ ///
+ /// The ResolveIpNetEntry2 function is used to resolve the physical address for a neighbor IP address entry on a local
+ /// computer. This function flushes any existing neighbor entry that matches the IP address on the interface and then resolves the
+ /// physical address (MAC) address by sending ARP requests for an IPv4 address or neighbor solicitation requests for an IPv6 address.
+ /// If the SourceAddress parameter is specified, the ResolveIpNetEntry2 function will select the interface with this source IP
+ /// address to send the requests on. If the SourceAddress parameter is not specified (NULL was passed in this parameter), the
+ /// ResolveIpNetEntry2 function will automatically select the best interface to send the requests on.
+ ///
+ ///
+ /// The Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid IPv4 or
+ /// IPv6 address and family. In addition, at least one of the following members in the MIB_IPNET_ROW2 structure pointed to the
+ /// Row parameter must be initialized to the interface: the InterfaceLuid or InterfaceIndex.
+ ///
+ ///
+ /// If the IP address passed in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter is a duplicate of an
+ /// existing neighbor IP address on the interface, the ResolveIpNetEntry2 function will flush the existing entry before
+ /// resolving the IP address.
+ ///
+ ///
+ /// On output when the call is successful, ResolveIpNetEntry2 retrieves the other properties for the neighbor IP address and
+ /// fills out the MIB_IPNET_ROW2 structure pointed to by the Row parameter. The PhysicalAddress and
+ /// PhysicalAddressLength members in the MIB_IPNET_ROW2 structure pointed to by the Row parameter will be initialized
+ /// to a valid physical address.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-resolveipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // ResolveIpNetEntry2( PMIB_IPNET_ROW2 Row, CONST SOCKADDR_INET *SourceAddress );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "37f9dc58-362d-413e-a593-4dda52fb7d8b")]
+ public static extern Win32Error ResolveIpNetEntry2(ref MIB_IPNET_ROW2 Row, IntPtr SourceAddress = default(IntPtr));
+
+ ///
+ /// The ResolveIpNetEntry2 function resolves the physical address for a neighbor IP address entry on the local computer.
+ ///
+ ///
+ ///
+ /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this structure will be
+ /// updated with the properties for neighbor IP address.
+ ///
+ ///
+ ///
+ ///
+ /// A pointer to a an optional source IP address used to select the interface to send the requests on for the neighbor IP address entry.
+ ///
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_BAD_NET_NAME
+ /// The network name cannot be found. This error is returned if the network with the neighbor IP address is unreachable.
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
+ /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid IPv4 or IPv6 address, or both the
+ /// InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the Row parameter were unspecified. This error is
+ /// also returned if a loopback address was passed in the Address member.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_FOUND
+ ///
+ /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
+ /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
+ /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter or no IPv6 stack is on the local computer and an IPv6
+ /// address was specified in the Address member.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The ResolveIpNetEntry2 function is defined on Windows Vista and later.
+ ///
+ /// The ResolveIpNetEntry2 function is used to resolve the physical address for a neighbor IP address entry on a local
+ /// computer. This function flushes any existing neighbor entry that matches the IP address on the interface and then resolves the
+ /// physical address (MAC) address by sending ARP requests for an IPv4 address or neighbor solicitation requests for an IPv6 address.
+ /// If the SourceAddress parameter is specified, the ResolveIpNetEntry2 function will select the interface with this source IP
+ /// address to send the requests on. If the SourceAddress parameter is not specified (NULL was passed in this parameter), the
+ /// ResolveIpNetEntry2 function will automatically select the best interface to send the requests on.
+ ///
+ ///
+ /// The Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid IPv4 or
+ /// IPv6 address and family. In addition, at least one of the following members in the MIB_IPNET_ROW2 structure pointed to the
+ /// Row parameter must be initialized to the interface: the InterfaceLuid or InterfaceIndex.
+ ///
+ ///
+ /// If the IP address passed in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter is a duplicate of an
+ /// existing neighbor IP address on the interface, the ResolveIpNetEntry2 function will flush the existing entry before
+ /// resolving the IP address.
+ ///
+ ///
+ /// On output when the call is successful, ResolveIpNetEntry2 retrieves the other properties for the neighbor IP address and
+ /// fills out the MIB_IPNET_ROW2 structure pointed to by the Row parameter. The PhysicalAddress and
+ /// PhysicalAddressLength members in the MIB_IPNET_ROW2 structure pointed to by the Row parameter will be initialized
+ /// to a valid physical address.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-resolveipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // ResolveIpNetEntry2( PMIB_IPNET_ROW2 Row, CONST SOCKADDR_INET *SourceAddress );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "37f9dc58-362d-413e-a593-4dda52fb7d8b")]
+ public static extern Win32Error ResolveIpNetEntry2(ref MIB_IPNET_ROW2 Row, ref SOCKADDR_INET SourceAddress);
+
+ ///
+ /// The SetIpNetEntry2 function sets the physical address of an existing neighbor IP address entry on the local computer.
+ ///
+ ///
+ /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry.
+ ///
+ ///
+ /// If the function succeeds, the return value is NO_ERROR.
+ /// If the function fails, the return value is one of the following error codes.
+ ///
+ ///
+ /// Return code
+ /// Description
+ ///
+ /// -
+ /// ERROR_ACCESS_DENIED
+ ///
+ /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required
+ /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in
+ /// Administrator (RunAs administrator).
+ ///
+ ///
+ /// -
+ /// ERROR_INVALID_PARAMETER
+ ///
+ /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the
+ /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid unicast, anycast, or multicast IPv4
+ /// or IPv6 address, the PhysicalAddress and PhysicalAddressLength members of the MIB_IPNET_ROW2 pointed to by the Row parameter were
+ /// not set to a valid physical address, or both the InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the
+ /// Row parameter were unspecified. This error is also returned if a loopback address was passed in the Address member.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_FOUND
+ ///
+ /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or
+ /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found.
+ ///
+ ///
+ /// -
+ /// ERROR_NOT_SUPPORTED
+ ///
+ /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified
+ /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter or no IPv6 stack is on the local computer and an IPv6
+ /// address was specified in the Address member.
+ ///
+ ///
+ /// -
+ /// Other
+ /// Use FormatMessage to obtain the message string for the returned error.
+ ///
+ ///
+ ///
+ ///
+ /// The SetIpNetEntry2 function is defined on Windows Vista and later.
+ ///
+ /// The SetIpNetEntry2 function is used to set the physical address for an existing neighbor IP address entry on a local computer.
+ ///
+ ///
+ /// The Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid unicast,
+ /// anycast, or multicast IPv4 or IPv6 address and family. The PhysicalAddress and PhysicalAddressLength members in the
+ /// MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid physical address. In addition, at
+ /// least one of the following members in the MIB_IPNET_ROW2 structure pointed to the Row parameter must be initialized to the
+ /// interface: the InterfaceLuid or InterfaceIndex.
+ ///
+ ///
+ /// The SetIpNetEntry2 function will fail if the IP address passed in the Address member of the MIB_IPNET_ROW2 pointed
+ /// to by the Row parameter is not an existing neighbor IP address on the interface specified.
+ ///
+ ///
+ /// The SetIpNetEntry2 function can only be called by a user logged on as a member of the Administrators group. If
+ /// SetIpNetEntry2 is called by a user that is not a member of the Administrators group, the function call will fail and
+ /// ERROR_ACCESS_DENIED is returned.
+ ///
+ ///
+ /// The SetIpNetEntry2 function can also fail because of user account control (UAC) on Windows Vista and later. If an
+ /// application that contains this function is executed by a user logged on as a member of the Administrators group other than the
+ /// built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
+ /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a
+ /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced
+ /// shell as the built-in Administrator (RunAs administrator) for this function to succeed.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-setipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API
+ // SetIpNetEntry2( PMIB_IPNET_ROW2 Row );
+ [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)]
+ [PInvokeData("netioapi.h", MSDNShortId = "4f423700-f721-44a9-ade3-ea5b5b86e394")]
+ public static extern Win32Error SetIpNetEntry2(ref MIB_IPNET_ROW2 Row);
+
+ ///
+ /// The MIB_ANYCASTIPADDRESS_ROW structure stores information about an anycast IP address.
+ ///
+ ///
+ /// The MIB_ANYCASTIPADDRESS_ROW structure is defined on Windows Vista and later.
+ ///
+ /// Note that the Netioapi.h header file is automatically included in the Iphlpapi.h header file. The Netioapi.h header file should
+ /// never be used directly.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/ns-netioapi-_mib_anycastipaddress_row typedef struct
+ // _MIB_ANYCASTIPADDRESS_ROW { SOCKADDR_INET Address; NET_LUID InterfaceLuid; NET_IFINDEX InterfaceIndex; SCOPE_ID ScopeId; }
+ // MIB_ANYCASTIPADDRESS_ROW, *PMIB_ANYCASTIPADDRESS_ROW;
+ [PInvokeData("netioapi.h", MSDNShortId = "bdbe43b8-88aa-48af-aa6b-c88c4e8e404e")]
+ [StructLayout(LayoutKind.Sequential)]
+ public struct MIB_ANYCASTIPADDRESS_ROW
+ {
+ ///
+ /// The anycast IP address. This member can be an IPv6 address or an IPv4 address.
+ ///
+ public SOCKADDR_INET Address;
+
+ ///
+ /// The locally unique identifier (LUID) for the network interface associated with this IP address.
+ ///
+ public NET_LUID InterfaceLuid;
+
+ ///
+ ///
+ /// The local index value for the network interface associated with this IP address. This index value may change when a network
+ /// adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.
+ ///
+ ///
+ public uint InterfaceIndex;
+
+ ///
+ ///
+ /// The scope ID of the anycast IP address. This member is applicable only to an IPv6 address. This member cannot be set. It is
+ /// automatically determined by the interface on which the address was added.
+ ///
+ ///
+ public SCOPE_ID ScopeId;
+ }
+
+ ///
+ /// The MIB_IF_ROW2 structure stores information about a particular interface.
+ ///
+ ///
+ /// The MIB_IF_ROW2 structure is defined on Windows Vista and later.
+ ///
+ /// The values for the Type field are defined in the Ipifcons.h header file. Only the possible values listed in the
+ /// description of the Type member are currently supported.
+ ///
+ ///
+ /// Note that the Netioapi.h header file is automatically included in the Iphlpapi.h header file. The Netioapi.h header file should
+ /// never be used directly.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/ns-netioapi-_mib_if_row2 typedef struct _MIB_IF_ROW2 { NET_LUID
+ // InterfaceLuid; NET_IFINDEX InterfaceIndex; GUID InterfaceGuid; WCHAR Alias[IF_MAX_STRING_SIZE + 1]; WCHAR
+ // Description[IF_MAX_STRING_SIZE + 1]; ULONG PhysicalAddressLength; UCHAR PhysicalAddress[IF_MAX_PHYS_ADDRESS_LENGTH]; UCHAR
+ // PermanentPhysicalAddress[IF_MAX_PHYS_ADDRESS_LENGTH]; ULONG Mtu; IFTYPE Type; TUNNEL_TYPE TunnelType; NDIS_MEDIUM MediaType;
+ // NDIS_PHYSICAL_MEDIUM PhysicalMediumType; NET_IF_ACCESS_TYPE AccessType; NET_IF_DIRECTION_TYPE DirectionType; struct { BOOLEAN
+ // HardwareInterface : 1; BOOLEAN FilterInterface : 1; BOOLEAN ConnectorPresent : 1; BOOLEAN NotAuthenticated : 1; BOOLEAN
+ // NotMediaConnected : 1; BOOLEAN Paused : 1; BOOLEAN LowPower : 1; BOOLEAN EndPointInterface : 1; } InterfaceAndOperStatusFlags;
+ // IF_OPER_STATUS OperStatus; NET_IF_ADMIN_STATUS AdminStatus; NET_IF_MEDIA_CONNECT_STATE MediaConnectState; NET_IF_NETWORK_GUID
+ // NetworkGuid; NET_IF_CONNECTION_TYPE ConnectionType; ULONG64 TransmitLinkSpeed; ULONG64 ReceiveLinkSpeed; ULONG64 InOctets; ULONG64
+ // InUcastPkts; ULONG64 InNUcastPkts; ULONG64 InDiscards; ULONG64 InErrors; ULONG64 InUnknownProtos; ULONG64 InUcastOctets; ULONG64
+ // InMulticastOctets; ULONG64 InBroadcastOctets; ULONG64 OutOctets; ULONG64 OutUcastPkts; ULONG64 OutNUcastPkts; ULONG64 OutDiscards;
+ // ULONG64 OutErrors; ULONG64 OutUcastOctets; ULONG64 OutMulticastOctets; ULONG64 OutBroadcastOctets; ULONG64 OutQLen; } MIB_IF_ROW2, *PMIB_IF_ROW2;
+ [PInvokeData("netioapi.h", MSDNShortId = "e8bb79f9-e7e9-470b-8883-36d08061661b")]
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
+ public struct MIB_IF_ROW2
+ {
+ /// The locally unique identifier (LUID) for the network interface.
+ public NET_LUID InterfaceLuid;
+
+ ///
+ /// The index that identifies the network interface. This index value may change when a network adapter is disabled and then
+ /// enabled, and should not be considered persistent.
+ ///
+ public uint InterfaceIndex;
+
+ /// The GUID for the network interface.
+ public Guid InterfaceGuid;
+
+ /// A NULL-terminated Unicode string that contains the alias name of the network interface.
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = IF_MAX_STRING_SIZE + 1)]
+ public string Alias;
+
+ /// A NULL-terminated Unicode string that contains a description of the network interface.
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = IF_MAX_STRING_SIZE + 1)]
+ public string Description;
+
+ /// The length, in bytes, of the physical hardware address specified by the PhysicalAddress member.
+ public uint physicalAddressLength;
+
+ /// The physical hardware address of the adapter for this network interface.
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = IF_MAX_PHYS_ADDRESS_LENGTH)]
+ public byte[] PhysicalAddress;
+
+ /// The permanent physical hardware address of the adapter for this network interface.
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = IF_MAX_PHYS_ADDRESS_LENGTH)]
+ public byte[] PermanentPhysicalAddress;
+
+ /// The maximum transmission unit (MTU) size, in bytes, for this network interface.
+ public uint Mtu;
+
+ ///
+ /// The interface type as defined by the Internet Assigned Names Authority (IANA). For more information, see
+ /// http://www.iana.org/assignments/ianaiftype-mib. Possible values for the interface type are listed in the Ipifcons.h header file.
+ ///
+ public IFTYPE Type;
+
+ ///
+ /// The encapsulation method used by a tunnel if the Type member is IF_TYPE_TUNNEL. The tunnel type is defined by the Internet
+ /// Assigned Names Authority (IANA). For more information, see http://www.iana.org/assignments/ianaiftype-mib. This member can be
+ /// one of the values from the TUNNEL_TYPE enumeration type defined in the Ifdef.h header file.
+ ///
+ public TUNNEL_TYPE TunnelType;
+
+ ///
+ /// The NDIS media type for the interface. This member can be one of the values from the NDIS_MEDIUM enumeration type defined in
+ /// the Ntddndis.h header file.
+ ///
+ public NDIS_MEDIUM MediaType;
+
+ ///
+ /// The NDIS physical medium type. This member can be one of the values from the NDIS_PHYSICAL_MEDIUM enumeration type defined in
+ /// the Ntddndis.h header file.
+ ///
+ public NDIS_PHYSICAL_MEDIUM PhysicalMediumType;
+
+ ///
+ /// The interface access type. This member can be one of the values from the NET_IF_ACCESS_TYPE enumeration type defined in the
+ /// Ifdef.h header file.
+ ///
+ public NET_IF_ACCESS_TYPE AccessType;
+
+ ///
+ /// The interface direction type. This member can be one of the values from the NET_IF_DIRECTION_TYPE enumeration type defined in
+ /// the Ifdef.h header file.
+ ///
+ public NET_IF_DIRECTION_TYPE DirectionType;
+
+ ///
+ /// A set of flags that provide information about the interface. These flags are combined with a bitwise OR operation. If none of
+ /// the flags applies, then this member is set to zero.
+ ///
+ public InterfaceAndOperStatusFlags InterfaceAndOperStatusFlags;
+
+ ///
+ /// The operational status for the interface as defined in RFC 2863 as IfOperStatus. For more information, see
+ /// http://www.ietf.org/rfc/rfc2863.txt. This member can be one of the values from the IF_OPER_STATUS enumeration type defined in
+ /// the Ifdef.h header file.
+ ///
+ public IF_OPER_STATUS OperStatus;
+
+ ///
+ /// The administrative status for the interface as defined in RFC 2863. For more information, see
+ /// http://www.ietf.org/rfc/rfc2863.txt. This member can be one of the values from the NET_IF_ADMIN_STATUS enumeration type
+ /// defined in the Ifdef.h header file.
+ ///
+ public NET_IF_ADMIN_STATUS AdminStatus;
+
+ ///
+ /// The connection state of the interface. This member can be one of the values from the NET_IF_MEDIA_CONNECT_STATE enumeration
+ /// type defined in the Ifdef.h header file.
+ ///
+ public NET_IF_MEDIA_CONNECT_STATE MediaConnectState;
+
+ /// The GUID that is associated with the network that the interface belongs to.
+ public Guid NetworkGuid;
+
+ ///
+ /// The NDIS network interface connection type. This member can be one of the values from the NET_IF_CONNECTION_TYPE enumeration
+ /// type defined in the Ifdef.h header file.
+ ///
+ public NET_IF_CONNECTION_TYPE ConnectionType;
+
+ /// The speed in bits per second of the transmit link.
+ public ulong TransmitLinkSpeed;
+
+ /// The speed in bits per second of the receive link.
+ public ulong ReceiveLinkSpeed;
+
+ ///
+ /// The number of octets of data received without errors through this interface. This value includes octets in unicast,
+ /// broadcast, and multicast packets.
+ ///
+ public ulong InOctets;
+
+ /// The number of unicast packets received without errors through this interface.
+ public ulong InUcastPkts;
+
+ ///
+ /// The number of non-unicast packets received without errors through this interface. This value includes broadcast and multicast packets.
+ ///
+ public ulong InNUcastPkts;
+
+ ///
+ /// The number of inbound packets which were chosen to be discarded even though no errors were detected to prevent the packets
+ /// from being deliverable to a higher-layer protocol.
+ ///
+ public ulong InDiscards;
+
+ /// The number of incoming packets that were discarded because of errors.
+ public ulong InErrors;
+
+ /// The number of incoming packets that were discarded because the protocol was unknown.
+ public ulong InUnknownProtos;
+
+ /// The number of octets of data received without errors in unicast packets through this interface.
+ public ulong InUcastOctets;
+
+ /// The number of octets of data received without errors in multicast packets through this interface.
+ public ulong InMulticastOctets;
+
+ /// The number of octets of data received without errors in broadcast packets through this interface.
+ public ulong InBroadcastOctets;
+
+ ///
+ /// The number of octets of data transmitted without errors through this interface. This value includes octets in unicast,
+ /// broadcast, and multicast packets.
+ ///
+ public ulong OutOctets;
+
+ /// The number of unicast packets transmitted without errors through this interface.
+ public ulong OutUcastPkts;
+
+ ///
+ /// The number of non-unicast packets transmitted without errors through this interface. This value includes broadcast and
+ /// multicast packets.
+ ///
+ public ulong OutNUcastPkts;
+
+ /// The number of outgoing packets that were discarded even though they did not have errors.
+ public ulong OutDiscards;
+
+ /// The number of outgoing packets that were discarded because of errors.
+ public ulong OutErrors;
+
+ /// The number of octets of data transmitted without errors in unicast packets through this interface.
+ public ulong OutUcastOctets;
+
+ /// The number of octets of data transmitted without errors in multicast packets through this interface.
+ public ulong OutMulticastOctets;
+
+ /// The number of octets of data transmitted without errors in broadcast packets through this interface.
+ public ulong OutBroadcastOctets;
+
+ /// The transmit queue length. This field is not currently used.
+ public ulong OutQLen;
+
+ /// Initializes a new instance of the struct.
+ /// Index of the interface.
+ public MIB_IF_ROW2(uint interfaceIndex) : this()
+ {
+ InterfaceIndex = interfaceIndex;
+ }
+
+ /// Initializes a new instance of the struct.
+ /// The interface luid.
+ public MIB_IF_ROW2(NET_LUID interfaceLuid) : this()
+ {
+ InterfaceLuid = interfaceLuid;
+ }
+ }
+
+ ///
+ /// The MIB_IPFORWARD_ROW2 structure stores information about an IP route entry.
+ ///
+ ///
+ /// The MIB_IPFORWARD_ROW2 structure is defined on Windows Vista and later.
+ ///
+ /// The GetIpForwardTable2 function enumerates the IP route entries on a local system and returns this information in a
+ /// MIB_IPFORWARD_TABLE2 structure as an array of MIB_IPFORWARD_ROW2 entries.
+ ///
+ ///
+ /// The GetIpForwardEntry2 function retrieves a single IP route entry and returns this information in a
+ /// MIB_IPFORWARD_ROW2 structure.
+ ///
+ ///
+ /// An entry with the Prefix and the PrefixLength members of the IP_ADDRESS_PREFIX set to zero in the
+ /// DestinationPrefix member in the MIB_IPFORWARD_ROW2 structure is considered a default route. The
+ /// MIB_IPFORWARD_TABLE2 may contain multiple MIB_IPFORWARD_ROW2 entries with the Prefix and the PrefixLength
+ /// members of the IP_ADDRESS_PREFIX set to zero in the DestinationPrefix member when there are multiple network
+ /// adapters installed.
+ ///
+ ///
+ /// The Metric member of a MIB_IPFORWARD_ROW2 entry is a value that is assigned to an IP route for a particular network
+ /// interface that identifies the cost that is associated with using that route. For example, the metric can be valued in terms of
+ /// link speed, hop count, or time delay. Automatic metric is a feature on Windows XP and later that automatically configures the
+ /// metric for the local routes that are based on link speed. The automatic metric feature is enabled by default (the
+ /// UseAutomaticMetric member of the MIB_IPINTERFACE_ROW structure is set to TRUE) on Windows XP and later. It can also
+ /// be manually configured to assign a specific metric to an IP route.
+ ///
+ ///
+ /// The route metric specified in the Metric member of the MIB_IPFORWARD_ROW2 structure represents just the route
+ /// metric offset. The complete metric is a combination of this route metric offset added to the interface metric specified in the
+ /// Metric member of the MIB_IPINTERFACE_ROW structure of the associated interface. An application can retrieve the interface
+ /// metric by calling the GetIpInterfaceEntry function.
+ ///
+ ///
+ /// Note that the Netioapi.h header file is automatically included in the Iphlpapi.h header file. The Netioapi.h header file should
+ /// never be used directly.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/ns-netioapi-_mib_ipforward_row2 typedef struct _MIB_IPFORWARD_ROW2 {
+ // NET_LUID InterfaceLuid; NET_IFINDEX InterfaceIndex; IP_ADDRESS_PREFIX DestinationPrefix; SOCKADDR_INET NextHop; UCHAR
+ // SitePrefixLength; ULONG ValidLifetime; ULONG PreferredLifetime; ULONG Metric; NL_ROUTE_PROTOCOL Protocol; BOOLEAN Loopback;
+ // BOOLEAN AutoconfigureAddress; BOOLEAN Publish; BOOLEAN Immortal; ULONG Age; NL_ROUTE_ORIGIN Origin; } MIB_IPFORWARD_ROW2, *PMIB_IPFORWARD_ROW2;
+ [PInvokeData("netioapi.h", MSDNShortId = "3678315d-b6ab-48c8-8522-a57deb63f8c9")]
+ [StructLayout(LayoutKind.Sequential, Pack = 1)]
+ public struct MIB_IPFORWARD_ROW2
+ {
+ ///
+ /// Type: NET_LUID
+ /// The locally unique identifier (LUID) for the network interface associated with this IP route entry.
+ ///
+ public NET_LUID InterfaceLuid;
+
+ ///
+ /// Type: NET_IFINDEX
+ ///
+ /// The local index value for the network interface associated with this IP route entry. This index value may change when a
+ /// network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.
+ ///
+ ///
+ public uint InterfaceIndex;
+
+ ///
+ /// Type: IP_ADDRESS_PREFIX
+ /// The IP address prefix for the destination IP address for this route.
+ ///
+ public IP_ADDRESS_PREFIX DestinationPrefix;
+
+ ///
+ /// Type: SOCKADDR_INET
+ ///
+ /// For a remote route, the IP address of the next system or gateway en route. If the route is to a local loopback address or an
+ /// IP address on the local link, the next hop is unspecified (all zeros). For a local loopback route, this member should be an
+ /// IPv4 address of 0.0.0.0 for an IPv4 route entry or an IPv6 address address of 0::0 for an IPv6 route entry.
+ ///
+ ///
+ public SOCKADDR_INET NextHop;
+
+ ///
+ /// Type: UCHAR
+ ///
+ /// The length, in bits, of the site prefix or network part of the IP address for this route. For an IPv4 route entry, any value
+ /// greater than 32 is an illegal value. For an IPv6 route entry, any value greater than 128 is an illegal value. A value of 255
+ /// is commonly used to represent an illegal value.
+ ///
+ ///
+ public byte SitePrefixLength;
+
+ ///
+ /// Type: ULONG
+ /// The maximum time, in seconds, that the IP route entry is valid. A value of 0xffffffff is considered to be infinite.
+ ///
+ public uint ValidLifetime;
+
+ ///
+ /// Type: ULONG
+ /// The preferred time, in seconds, that the IP route entry is valid. A value of 0xffffffff is considered to be infinite.
+ ///
+ public uint PreferredLifetime;
+
+ ///
+ /// Type: ULONG
+ ///
+ /// The route metric offset value for this IP route entry. Note the actual route metric used to compute the route preference is
+ /// the summation of interface metric specified in the Metric member of the MIB_IPINTERFACE_ROW structure and the route
+ /// metric offset specified in this member. The semantics of this metric are determined by the routing protocol specified in the
+ /// Protocol member. If this metric is not used, its value should be set to -1. This value is documented in RFC 4292. For
+ /// more information, see http://www.ietf.org/rfc/rfc4292.txt.
+ ///
+ ///
+ public uint Metric;
+
+ ///
+ /// Type: NL_ROUTE_PROTOCOL
+ ///
+ /// The routing mechanism how this IP route was added. This member can be one of the values from the NL_ROUTE_PROTOCOL
+ /// enumeration type defined in the Nldef.h header file. The member is described in RFC 4292. For more information, see http://www.ietf.org/rfc/rfc4292.txt.
+ ///
+ ///
+ /// Note that the Nldef.h header is automatically included by the Ipmib.h header file which is automatically included by the
+ /// Iprtrmib.h header. The Iphlpapi.h header automatically includes the Iprtrmib.h header file. The Iprtrmib.h, Ipmib.h, and
+ /// Nldef.h header files should never be used directly.
+ ///
+ /// The following list shows the possible values for this member.
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// MIB_IPPROTO_OTHER 1
+ /// The routing mechanism was not specified.
+ ///
+ /// -
+ /// MIB_IPPROTO_LOCAL 2
+ /// A local interface.
+ ///
+ /// -
+ /// MIB_IPPROTO_NETMGMT 3
+ ///
+ /// A static route. This value is used to identify route information for IP routing set through network management such as the
+ /// Dynamic Host Configuration Protocol (DCHP), the Simple Network Management Protocol (SNMP), or by calls to the
+ /// CreateIpForwardEntry2, DeleteIpForwardEntry2, or SetIpForwardEntry2 functions.
+ ///
+ ///
+ /// -
+ /// MIB_IPPROTO_ICMP 4
+ /// The result of an ICMP redirect.
+ ///
+ /// -
+ /// MIB_IPPROTO_EGP 5
+ /// The Exterior Gateway Protocol (EGP), a dynamic routing protocol.
+ ///
+ /// -
+ /// MIB_IPPROTO_GGP 6
+ /// The Gateway-to-Gateway Protocol (GGP), a dynamic routing protocol.
+ ///
+ /// -
+ /// MIB_IPPROTO_HELLO 7
+ ///
+ /// The Hellospeak protocol, a dynamic routing protocol. This is a historical entry no longer in use and was an early routing
+ /// protocol used by the original ARPANET routers that ran special software called the Fuzzball routing protocol, sometimes
+ /// called Hellospeak, as described in RFC 891 and RFC 1305. For more information, see http://www.ietf.org/rfc/rfc891.txt and http://www.ietf.org/rfc/rfc1305.txt.
+ ///
+ ///
+ /// -
+ /// MIB_IPPROTO_RIP 8
+ /// The Berkeley Routing Information Protocol (RIP) or RIP-II, a dynamic routing protocol.
+ ///
+ /// -
+ /// MIB_IPPROTO_IS_IS 9
+ ///
+ /// The Intermediate System-to-Intermediate System (IS-IS) protocol, a dynamic routing protocol. The IS-IS protocol was developed
+ /// for use in the Open Systems Interconnection (OSI) protocol suite.
+ ///
+ ///
+ /// -
+ /// MIB_IPPROTO_ES_IS 10
+ ///
+ /// The End System-to-Intermediate System (ES-IS) protocol, a dynamic routing protocol. The ES-IS protocol was developed for use
+ /// in the Open Systems Interconnection (OSI) protocol suite.
+ ///
+ ///
+ /// -
+ /// MIB_IPPROTO_CISCO 11
+ /// The Cisco Interior Gateway Routing Protocol (IGRP), a dynamic routing protocol.
+ ///
+ /// -
+ /// MIB_IPPROTO_BBN 12
+ ///
+ /// The Bolt, Beranek, and Newman (BBN) Interior Gateway Protocol (IGP) that used the Shortest Path First (SPF) algorithm. This
+ /// was an early dynamic routing protocol.
+ ///
+ ///
+ /// -
+ /// MIB_IPPROTO_OSPF 13
+ /// The Open Shortest Path First (OSPF) protocol, a dynamic routing protocol.
+ ///
+ /// -
+ /// MIB_IPPROTO_BGP 14
+ /// The Border Gateway Protocol (BGP), a dynamic routing protocol.
+ ///
+ /// -
+ /// MIB_IPPROTO_NT_AUTOSTATIC 10002
+ /// A Windows specific entry added originally by a routing protocol, but which is now static.
+ ///
+ /// -
+ /// MIB_IPPROTO_NT_STATIC 10006
+ /// A Windows specific entry added as a static route from the routing user interface or a routing command.
+ ///
+ /// -
+ /// MIB_IPPROTO_NT_STATIC_NON_DOD 10007
+ ///
+ /// A Windows specific entry added as an static route from the routing user interface or a routing command, except these routes
+ /// do not cause Dial On Demand (DOD).
+ ///
+ ///
+ ///
+ ///
+ public MIB_IPPROTOCOL Protocol;
+
+ ///
+ /// Type: BOOLEAN
+ /// A value that specifies if the route is a loopback route (the gateway is on the local host).
+ ///
+ public byte Loopback;
+
+ ///
+ /// Type: BOOLEAN
+ /// A value that specifies if the IP address is autoconfigured.
+ ///
+ public byte AutoconfigureAddress;
+
+ ///
+ /// Type: BOOLEAN
+ /// A value that specifies if the route is published.
+ ///
+ public byte Publish;
+
+ ///
+ /// Type: BOOLEAN
+ /// A value that specifies if the route is immortal.
+ ///
+ public byte Immortal;
+
+ ///
+ /// Type: ULONG
+ /// The number of seconds since the route was added or modified in the network routing table.
+ ///
+ public uint Age;
+
+ ///
+ /// Type: NL_ROUTE_ORIGIN
+ ///
+ /// The origin of the route. This member can be one of the values from the NL_ROUTE_ORIGIN enumeration type defined in the
+ /// Nldef.h header file.
+ ///
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// NlroManual 0
+ /// A result of manual configuration.
+ ///
+ /// -
+ /// NlroWellKnown 1
+ /// A well-known route.
+ ///
+ /// -
+ /// NlroDHCP 2
+ /// A result of DHCP configuration.
+ ///
+ /// -
+ /// NlroRouterAdvertisement 3
+ /// The result of router advertisement.
+ ///
+ /// -
+ /// Nlro6to4 4
+ /// A result of 6to4 tunneling.
+ ///
+ ///
+ ///
+ public NL_ROUTE_ORIGIN Origin;
+ }
+
+ ///
+ /// The MIB_IPNET_ROW2 structure stores information about a neighbor IP address.
+ ///
+ ///
+ /// The MIB_IPNET_ROW2 structure is defined on Windows Vista and later.
+ ///
+ /// The GetIpNetTable2 function enumerates the neighbor IP addresses on a local system and returns this information in an
+ /// MIB_IPNET_TABLE2 structure.
+ ///
+ ///
+ /// For IPv4, this includes addresses determined used the Address Resolution Protocol (ARP). For IPv6, this includes addresses
+ /// determined using the Neighbor Discovery (ND) protocol for IPv6 as specified in RFC 2461. For more information, see http://www.ietf.org/rfc/rfc2461.txt.
+ ///
+ ///
+ /// The GetIpNetEntry2 function retrieves a single neighbor IP address and returns this information in a MIB_IPNET_ROW2 structure.
+ ///
+ ///
+ /// Note that the Netioapi.h header file is automatically included in the Iphlpapi.h header file. The Netioapi.h header file should
+ /// never be used directly.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/ns-netioapi-_mib_ipnet_row2 typedef struct _MIB_IPNET_ROW2 {
+ // SOCKADDR_INET Address; NET_IFINDEX InterfaceIndex; NET_LUID InterfaceLuid; UCHAR PhysicalAddress[IF_MAX_PHYS_ADDRESS_LENGTH];
+ // ULONG PhysicalAddressLength; NL_NEIGHBOR_STATE State; union { struct { BOOLEAN IsRouter : 1; BOOLEAN IsUnreachable : 1; }; UCHAR
+ // Flags; }; union { ULONG LastReachable; ULONG LastUnreachable; } ReachabilityTime; } MIB_IPNET_ROW2, *PMIB_IPNET_ROW2;
+ [PInvokeData("netioapi.h", MSDNShortId = "164dbd93-4464-40f9-989a-17597102b1d8")]
+ [StructLayout(LayoutKind.Sequential, Pack = 2)]
+ public struct MIB_IPNET_ROW2
+ {
+ ///
+ /// Type: SOCKADDR_INET
+ /// The neighbor IP address. This member can be an IPv6 address or an IPv4 address.
+ ///
+ public SOCKADDR_INET Address;
+
+ ///
+ /// Type: NET_IFINDEX
+ ///
+ /// The local index value for the network interface associated with this IP address. This index value may change when a network
+ /// adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.
+ ///
+ ///
+ public uint InterfaceIndex;
+
+ ///
+ /// Type: NET_LUID
+ /// The locally unique identifier (LUID) for the network interface associated with this IP address.
+ ///
+ public NET_LUID InterfaceLuid;
+
+ ///
+ /// Type: UCHAR[IF_MAX_PHYS_ADDRESS_LENGTH]
+ /// The physical hardware address of the adapter for the network interface associated with this IP address.
+ ///
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst = IF_MAX_PHYS_ADDRESS_LENGTH)]
+ public byte[] PhysicalAddress;
+
+ ///
+ /// Type: ULONG
+ ///
+ /// The length, in bytes, of the physical hardware address specified by the PhysicalAddress member. The maximum value
+ /// supported is 32 bytes.
+ ///
+ ///
+ public uint PhysicalAddressLength;
+
+ ///
+ /// Type: NL_NEIGHBOR_STATE
+ ///
+ /// The state of a network neighbor IP address as defined in RFC 2461, section 7.3.2. For more information, see
+ /// http://www.ietf.org/rfc/rfc2461.txt. This member can be one of the values from the NL_NEIGHBOR_STATE enumeration type
+ /// defined in the Nldef.h header file.
+ ///
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// NlnsUnreachable
+ /// The IP address is unreachable.
+ ///
+ /// -
+ /// NlnsIncomplete
+ ///
+ /// Address resolution is in progress and the link-layer address of the neighbor has not yet been determined. Specifically for
+ /// IPv6, a Neighbor Solicitation has been sent to the solicited-node multicast IP address of the target, but the corresponding
+ /// neighbor advertisement has not yet been received.
+ ///
+ ///
+ /// -
+ /// NlnsProbe
+ ///
+ /// The neighbor is no longer known to be reachable, and probes are being sent to verify reachability. For IPv6, a reachability
+ /// confirmation is actively being sought by retransmitting unicast Neighbor Solicitation probes at regular intervals until a
+ /// reachability confirmation is received.
+ ///
+ ///
+ /// -
+ /// NlnsDelay
+ ///
+ /// The neighbor is no longer known to be reachable, and traffic has recently been sent to the neighbor. Rather than probe the
+ /// neighbor immediately, however, delay sending probes for a short while in order to give upper layer protocols a chance to
+ /// provide reachability confirmation. For IPv6, more time has elapsed than is specified in the ReachabilityTime.ReachableTime
+ /// member since the last positive confirmation was received that the forward path was functioning properly and a packet was
+ /// sent. If no reachability confirmation is received within a period of time (used to delay the first probe) of entering the
+ /// NlnsDelay state, then a neighbor solicitation is sent and the State member is changed to NlnsProbe.
+ ///
+ ///
+ /// -
+ /// NlnsStale
+ ///
+ /// The neighbor is no longer known to be reachable but until traffic is sent to the neighbor, no attempt should be made to
+ /// verify its reachability. For IPv6, more time has elapsed than is specified in the ReachabilityTime.ReachableTime member since
+ /// the last positive confirmation was received that the forward path was functioning properly. While the State is NlnsStale, no
+ /// action takes place until a packet is sent. The NlnsStale state is entered upon receiving an unsolicited neighbor discovery
+ /// message that updates the cached IP address. Receipt of such a message does not confirm reachability, and entering the
+ /// NlnsStale state insures reachability is verified quickly if the entry is actually being used. However, reachability is not
+ /// actually verified until the entry is actually used.
+ ///
+ ///
+ /// -
+ /// NlnsReachable
+ ///
+ /// The neighbor is known to have been reachable recently (within tens of seconds ago). For IPv6, a positive confirmation was
+ /// received within the time specified in the ReachabilityTime.ReachableTime member that the forward path to the neighbor was
+ /// functioning properly. While the State is NlnsReachable, no special action takes place as packets are sent.
+ ///
+ ///
+ /// -
+ /// NlnsPermanent
+ /// The IP address is a permanent address.
+ ///
+ /// -
+ /// NlnsMaximum
+ /// The maximum possible value for the NL_NEIGHBOR_STATE enumeration type. This is not a legal value for the State member.
+ ///
+ ///
+ ///
+ public NL_NEIGHBOR_STATE State;
+
+ /// Undocumented.
+ public MIB_IPNET_ROW2_FLAGS Flags;
+
+ ///
+ ///
+ /// Type: ULONG The time, in milliseconds, that a node assumes a neighbor is reachable after having received a
+ /// reachability confirmation or is unreachable after not having received a reachability confirmation.
+ ///
+ ///
+ public uint ReachabilityTime;
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The neighbor IP address.
+ /// The locally unique identifier (LUID) for the network interface associated with this IP address.
+ /// The physical hardware address of the adapter for the network interface associated with this IP address.
+ public MIB_IPNET_ROW2(SOCKADDR_IN ipV4, NET_LUID ifLuid, byte[] macAddr = null) : this(ipV4, macAddr)
+ {
+ InterfaceLuid = ifLuid;
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The neighbor IP address.
+ /// The local index value for the network interface associated with this IP address. This index value may change when a network
+ /// adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.
+ /// The physical hardware address of the adapter for the network interface associated with this IP address.
+ public MIB_IPNET_ROW2(SOCKADDR_IN ipV4, uint ifIdx, byte[] macAddr = null) : this(ipV4, macAddr)
+ {
+ InterfaceIndex = ifIdx;
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The neighbor IP address.
+ /// The locally unique identifier (LUID) for the network interface associated with this IP address.
+ /// The physical hardware address of the adapter for the network interface associated with this IP address.
+ public MIB_IPNET_ROW2(SOCKADDR_IN6 ipV6, NET_LUID ifLuid, byte[] macAddr = null) : this(ipV6, macAddr)
+ {
+ InterfaceLuid = ifLuid;
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The neighbor IP address.
+ /// The local index value for the network interface associated with this IP address. This index value may change when a network
+ /// adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.
+ /// The physical hardware address of the adapter for the network interface associated with this IP address.
+ public MIB_IPNET_ROW2(SOCKADDR_IN6 ipV6, uint ifIdx, byte[] macAddr = null) : this(ipV6, macAddr)
+ {
+ InterfaceIndex = ifIdx;
+ }
+
+ private MIB_IPNET_ROW2(SOCKADDR_IN ipV4, byte[] macAddr) : this()
+ {
+ Address.Ipv4 = ipV4;
+ SetMac(macAddr);
+ }
+
+ private MIB_IPNET_ROW2(SOCKADDR_IN6 ipV6, byte[] macAddr) : this()
+ {
+ Address.Ipv6 = ipV6;
+ SetMac(macAddr);
+ }
+
+ private void SetMac(byte[] macAddr)
+ {
+ if (macAddr == null)
+ {
+ return;
+ }
+
+ PhysicalAddressLength = IF_MAX_PHYS_ADDRESS_LENGTH;
+ PhysicalAddress = new byte[IF_MAX_PHYS_ADDRESS_LENGTH];
+ Array.Copy(macAddr, PhysicalAddress, 6);
+ }
+
+ ///
+ public override string ToString()
+ {
+ return $"{Address}; MAC:{PhysicalAddressToString(PhysicalAddress)}; If:{(InterfaceIndex != 0 ? InterfaceIndex.ToString() : InterfaceLuid.ToString())}";
+ }
+ }
+
+ ///
+ /// The MIB_UNICASTIPADDRESS_ROW structure stores information about a unicast IP address.
+ ///
+ ///
+ /// The MIB_UNICASTIPADDRESS_ROW structure is defined on Windows Vista and later.
+ ///
+ /// The SkipAsSource member of the MIB_UNICASTIPADDRESS_ROW structure affects the operation of the getaddrinfo,
+ /// GetAddrInfoW, and GetAddrInfoEx functions in Windows sockets. If the pNodeName parameter passed to the getaddrinfo or
+ /// GetAddrInfoW functions or the pName parameter passed to the GetAddrInfoEx function points to a computer name, all
+ /// permanent addresses for the computer that can be used as a source address are returned. On Windows Vista and later, these
+ /// addresses would include all unicast IP addresses returned by the GetUnicastIpAddressTable or GetUnicastIpAddressEntry functions
+ /// in which the SkipAsSource member is set to false in the MIB_UNICASTIPADDRESS_ROW structure.
+ ///
+ ///
+ /// If the pNodeName or pName parameter refers to a cluster virtual server name, only virtual server addresses are returned. On
+ /// Windows Vista and later, these addresses would include all unicast IP addresses returned by the GetUnicastIpAddressTable or
+ /// GetUnicastIpAddressEntry functions in which the SkipAsSource member is set to true in the MIB_UNICASTIPADDRESS_ROW
+ /// structure. See Windows Clustering for more information about clustering.
+ ///
+ ///
+ /// Windows 7 with Service Pack 1 (SP1) and Windows Server 2008 R2 with Service Pack 1 (SP1) add support to Netsh.exe for setting the
+ /// SkipAsSource attribute on an IP address. This hotfix also changes the behavior such that if the SkipAsSource member in the
+ /// MIB_UNICASTIPADDRESS_ROW structure is set to false, the IP address will be registered in DNS. If the SkipAsSource
+ /// member is set to true, the IP address is not registered in DNS.
+ ///
+ ///
+ /// A hotfix is available for Windows 7 and Windows Server 2008 R2 that adds support to Netsh.exe for setting the SkipAsSource
+ /// attribute on an IP address. This hotfix also changes the behavior such that if the SkipAsSource member in the
+ /// MIB_UNICASTIPADDRESS_ROW structure is set to false, the IP address will be registered in DNS. If the SkipAsSource
+ /// member is set to true, the IP address is not registered in DNS. For more information, see Knowledge Base (KB) 2386184.
+ ///
+ ///
+ /// A similar hotfix is also available for Windows Vista with Service Pack 2 (SP2) and Windows Server 2008 with Service Pack 2 (SP2)
+ /// that adds support to Netsh.exe for setting the SkipAsSource attribute on an IP address. This hotfix also changes behavior such
+ /// that if the SkipAsSource member in the MIB_UNICASTIPADDRESS_ROW structure is set to false, the IP address will be
+ /// registered in DNS. If the SkipAsSource member is set to true, the IP address is not registered in DNS. For more
+ /// information, see Knowledge Base (KB) 975808.
+ ///
+ /// Examples
+ ///
+ /// The following example retrieves a unicast IP address table and prints some values from each of the retrieved
+ /// MIB_UNICASTIPADDRESS_ROW structures.
+ ///
+ ///
+ // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/ns-netioapi-_mib_unicastipaddress_row typedef struct
+ // _MIB_UNICASTIPADDRESS_ROW { SOCKADDR_INET Address; NET_LUID InterfaceLuid; NET_IFINDEX InterfaceIndex; NL_PREFIX_ORIGIN
+ // PrefixOrigin; NL_SUFFIX_ORIGIN SuffixOrigin; ULONG ValidLifetime; ULONG PreferredLifetime; UINT8 OnLinkPrefixLength; BOOLEAN
+ // SkipAsSource; NL_DAD_STATE DadState; SCOPE_ID ScopeId; LARGE_INTEGER CreationTimeStamp; } MIB_UNICASTIPADDRESS_ROW, *PMIB_UNICASTIPADDRESS_ROW;
+ [PInvokeData("netioapi.h", MSDNShortId = "f329bafd-9e83-4754-a9a9-e7e111229c90")]
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
+ public struct MIB_UNICASTIPADDRESS_ROW
+ {
+ ///
+ /// Type: SOCKADDR_INET
+ /// The unicast IP address. This member can be an IPv6 address or an IPv4 address.
+ ///
+ public SOCKADDR_INET Address;
+
+ ///
+ /// Type: NET_LUID
+ /// The locally unique identifier (LUID) for the network interface associated with this IP address.
+ ///
+ public NET_LUID InterfaceLuid;
+
+ ///
+ /// Type: NET_IFINDEX
+ ///
+ /// The local index value for the network interface associated with this IP address. This index value may change when a network
+ /// adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent.
+ ///
+ ///
+ public uint InterfaceIndex;
+
+ ///
+ /// Type: NL_PREFIX_ORIGIN
+ ///
+ /// The origin of the prefix or network part of IP the address. This member can be one of the values from the
+ /// NL_PREFIX_ORIGIN enumeration type defined in the Nldef.h header file.
+ ///
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// IpPrefixOriginOther 0
+ ///
+ /// The IP address prefix was configured using a source other than those defined in this enumeration. This value is applicable to
+ /// an IPv6 or IPv4 address.
+ ///
+ ///
+ /// -
+ /// IpPrefixOriginManual 1
+ /// The IP address prefix was configured manually. This value is applicable to an IPv6 or IPv4 address.
+ ///
+ /// -
+ /// IpPrefixOriginWellKnown 2
+ ///
+ /// The IP address prefix was configured using a well-known address. This value is applicable to an IPv6 link-local address or an
+ /// IPv6 loopback address.
+ ///
+ ///
+ /// -
+ /// IpPrefixOriginDhcp 3
+ ///
+ /// The IP address prefix was configured using DHCP. This value is applicable to an IPv4 address configured using DHCP or an IPv6
+ /// address configured using DHCPv6.
+ ///
+ ///
+ /// -
+ /// IpPrefixOriginRouterAdvertisement 4
+ ///
+ /// The IP address prefix was configured using router advertisement. This value is applicable to an anonymous IPv6 address that
+ /// was generated after receiving a router advertisement.
+ ///
+ ///
+ /// -
+ /// IpPrefixOriginUnchanged 16
+ ///
+ /// The IP address prefix should be unchanged. This value is used when setting the properties for a unicast IP interface when the
+ /// value for the IP prefix origin should be unchanged.
+ ///
+ ///
+ ///
+ ///
+ public NL_PREFIX_ORIGIN PrefixOrigin;
+
+ ///
+ /// Type: NL_SUFFIX_ORIGIN
+ ///
+ /// The origin of the suffix or host part of IP the address. This member can be one of the values from the
+ /// NL_SUFFIX_ORIGIN enumeration type defined in the Nldef.h header file.
+ ///
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// IpSuffixOriginOther 0
+ ///
+ /// The IP address suffix was configured using a source other than those defined in this enumeration. This value is applicable to
+ /// an IPv6 or IPv4 address.
+ ///
+ ///
+ /// -
+ /// IpSuffixOriginManual 1
+ /// The IP address suffix was configured manually. This value is applicable to an IPv6 or IPv4 address.
+ ///
+ /// -
+ /// IpSuffixOriginWellKnown 2
+ ///
+ /// The IP address suffix was configured using a well-known address. This value is applicable to an IPv6 link-local address or an
+ /// IPv6 loopback address.
+ ///
+ ///
+ /// -
+ /// IpSuffixOriginDhcp 3
+ ///
+ /// The IP address suffix was configured using DHCP. This value is applicable to an IPv4 address configured using DHCP or an IPv6
+ /// address configured using DHCPv6.
+ ///
+ ///
+ /// -
+ /// IpSuffixOriginLinkLayerAddress 4
+ ///
+ /// The IP address suffix was the link local address. This value is applicable to an IPv6 link-local address or an IPv6 address
+ /// where the network part was generated based on a router advertisement and the host part was based on the MAC hardware address.
+ ///
+ ///
+ /// -
+ /// IpSuffixOriginRandom 5
+ ///
+ /// The IP address suffix was generated randomly. This value is applicable to an anonymous IPv6 address where the host part of
+ /// the address was generated randomly from the MAC hardware address after receiving a router advertisement.
+ ///
+ ///
+ /// -
+ /// IpSuffixOriginUnchanged 16
+ ///
+ /// The IP address suffix should be unchanged. This value is used when setting the properties for a unicast IP interface when the
+ /// value for the IP suffix origin should be unchanged.
+ ///
+ ///
+ ///
+ ///
+ public NL_SUFFIX_ORIGIN SuffixOrigin;
+
+ ///
+ /// Type: ULONG
+ /// The maximum time, in seconds, that the IP address is valid. A value of 0xffffffff is considered to be infinite.
+ ///
+ public uint ValidLifetime;
+
+ ///
+ /// Type: ULONG
+ /// The preferred time, in seconds, that the IP address is valid. A value of 0xffffffff is considered to be infinite.
+ ///
+ public uint PreferredLifetime;
+
+ ///
+ /// Type: UINT8
+ ///
+ /// The length, in bits, of the prefix or network part of the IP address. For a unicast IPv4 address, any value greater than 32
+ /// is an illegal value. For a unicast IPv6 address, any value greater than 128 is an illegal value. A value of 255 is commonly
+ /// used to represent an illegal value.
+ ///
+ ///
+ public byte OnLinkPrefixLength;
+
+ ///
+ /// Type: BOOLEAN
+ /// This member specifies if the address can be used as an IP source address.
+ ///
+ [MarshalAs(UnmanagedType.U1)] public bool SkipAsSource;
+
+ ///
+ /// Type: NL_DAD_STATE
+ ///
+ /// The duplicate Address detection (DAD) state. Duplicate address detection is applicable to both IPv6 and IPv4 addresses. This
+ /// member can be one of the values from the NL_DAD_STATE enumeration type defined in the Nldef.h header file.
+ ///
+ ///
+ ///
+ /// Value
+ /// Meaning
+ ///
+ /// -
+ /// IpDadStateInvalid 0
+ /// The DAD state is invalid.
+ ///
+ /// -
+ /// IpDadStateTentative 1
+ /// The DAD state is tentative.
+ ///
+ /// -
+ /// IpDadStateDuplicate 2
+ /// A duplicate IP address has been detected.
+ ///
+ /// -
+ /// IpDadStateDeprecated 3
+ /// The IP address has been deprecated.
+ ///
+ /// -
+ /// IpDadStatePreferred 4
+ /// The IP address is the preferred address.
+ ///
+ ///
+ ///
+ public NL_DAD_STATE DadState;
+
+ ///
+ /// Type: SCOPE_ID
+ ///
+ /// The scope ID of the IP address. This member is applicable only to an IPv6 address. This member cannot be set. It is
+ /// automatically determined by the interface on which the address was added.
+ ///
+ ///
+ public SCOPE_ID ScopeId;
+
+ ///
+ /// Type: LARGE_INTEGER
+ /// The time stamp when the IP address was created.
+ ///
+ public long CreationTimeStamp;
+ }
+
+ [PInvokeData("ws2def.h")]
+ [StructLayout(LayoutKind.Sequential)]
+ public struct SCOPE_ID
+ {
+ public uint Value;
+
+ public uint Zone
+ {
+ get => BitHelper.GetBits(Value, 0, 28);
+ set => BitHelper.SetBits(ref Value, 0, 28, value);
+ }
+
+ public byte Level
+ {
+ get => (byte)BitHelper.GetBits(Value, 28, 4);
+ set => BitHelper.SetBits(ref Value, 28, 4, value);
+ }
+ }
+
+ /// The MIB_IF_TABLE2 structure contains a table of logical and physical interface entries.
+ // https://msdn.microsoft.com/en-us/library/windows/hardware/ff559224(v=vs.85).aspx
+ [PInvokeData("Netioapi.h", MSDNShortId = "ff559224")]
+ [CorrespondingType(typeof(MIB_IF_ROW2)), DefaultProperty(nameof(Elements))]
+ public class MIB_IF_TABLE2 : SafeMibTableHandle, IEnumerable
+ {
+ /// Initializes a new instance of the class.
+ public MIB_IF_TABLE2() : base() { }
+
+ /// Gets the array of MIB_IF_ROW2 structures containing interface entries.
+ /// An array of MIB_IF_ROW2 structures containing interface entries.
+ public MIB_IF_ROW2[] Elements => handle.ToArray((int)NumEntries, Marshal.SizeOf(typeof(ulong)));
+
+ /// Gets the number of interface entries in the array.
+ /// The number of interface entries in the array.
+ public uint NumEntries => IsInvalid ? 0 : handle.ToStructure();
+
+ /// Gets the enumerator.
+ public IEnumerator GetEnumerator()
+ {
+ return ((IEnumerable)Elements).GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+ }
+
+ /// The MIB_IPNET_TABLE2 structure contains a table of neighbor IP address entries.
+ // typedef struct _MIB_IPNET_TABLE2 { ULONG NumEntries; MIB_IPNET_ROW2 Table[ANY_SIZE];} MIB_IPNET_TABLE2, *PMIB_IPNET_TABLE2;
+ // https://msdn.microsoft.com/en-us/library/windows/hardware/ff559267(v=vs.85).aspx
+ [PInvokeData("Netioapi.h", MSDNShortId = "ff559267")]
+ [CorrespondingType(typeof(MIB_IPNET_ROW2)), DefaultProperty(nameof(Elements))]
+ public class MIB_IPNET_TABLE2 : SafeMibTableHandle, IEnumerable
+ {
+ /// Initializes a new instance of the class.
+ public MIB_IPNET_TABLE2() : base() { }
+
+ /// Gets the array of MIB_IF_ROW2 structures containing interface entries.
+ /// An array of MIB_IF_ROW2 structures containing interface entries.
+ public MIB_IPNET_ROW2[] Elements => handle.ToArray((int)NumEntries, Marshal.SizeOf(typeof(ulong)));
+
+ /// Gets the number of interface entries in the array.
+ /// The number of interface entries in the array.
+ public uint NumEntries => IsInvalid ? 0 : handle.ToStructure();
+
+ public IEnumerator GetEnumerator() => ((IEnumerable)Elements).GetEnumerator();
+
+ IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
+ }
+
+ public class SafeMibTableHandle : GenericSafeHandle
+ {
+ public SafeMibTableHandle() : this(IntPtr.Zero)
+ {
+ }
+
+ public SafeMibTableHandle(IntPtr bufferPtr, bool own = true) : base(bufferPtr, h => { FreeMibTable(h); return true; }, own)
+ {
+ }
+
+ public T[] ToArray(int count)
+ {
+ return IsInvalid ? null : handle.ToArray(count);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/PInvoke/IpHlpApi/WinSock2.cs b/PInvoke/IpHlpApi/WinSock2.cs
index a17a9895..a032751e 100644
--- a/PInvoke/IpHlpApi/WinSock2.cs
+++ b/PInvoke/IpHlpApi/WinSock2.cs
@@ -245,6 +245,34 @@ namespace Vanara.PInvoke
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, CharSet = CharSet.Auto)]
+ public struct SOCKADDR_IN6_PAIR
+ {
+ /// 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 IntPtr 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 IntPtr DestinationAddress;
+ }
+
[PInvokeData("winsock2.h")]
[StructLayout(LayoutKind.Explicit)]
public struct SOCKADDR_INET