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; using static Vanara.PInvoke.Ws2_32; namespace Vanara.PInvoke { public static partial class IpHlpApi { /// This function is called when an interface notification is received from . /// /// The CallerContext parameter that is passed to the NotifyRouteChange2 function when it is registering the driver for change notifications. /// /// /// A pointer to the MIB_IPFORWARD_ROW2 entry for the IP route entry that was changed. This parameter is a NULL pointer when the /// MIB_NOTIFICATION_TYPE value that is passed in the NotificationType parameter to the callback function is set to /// MibInitialNotification. This situation can occur only if the InitialNotification parameter that is passed to NotifyRouteChange2 /// was set to TRUE when registering the driver for change notifications. /// /// /// The notification type. This member can be one of the values from the MIB_NOTIFICATION_TYPE enumeration type. /// [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void PIPFORWARD_CHANGE_CALLBACK([In] IntPtr CallerContext, [In, Optional] ref MIB_IPFORWARD_ROW2 Row, [In] MIB_NOTIFICATION_TYPE NotificationType); /// This function is called when an interface notification is received from . /// /// The CallerContext parameter that is passed to the NotifyIpInterfaceChange function when it is registering the driver for change notifications. /// /// /// A pointer to the MIB_IPINTERFACE_ROW entry for the interface that was changed. This parameter is a NULL pointer when the /// MIB_NOTIFICATION_TYPE value that is passed in the NotificationType parameter to the callback function is set to /// MibInitialNotification. This situation can occur only if the InitialNotification parameter that is passed to /// NotifyIpInterfaceChange was set to TRUE when registering the driver for change notifications. /// /// /// The notification type. This member can be one of the values from the MIB_NOTIFICATION_TYPE enumeration type. /// [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void PIPINTERFACE_CHANGE_CALLBACK(IntPtr CallerContext, IntPtr Row, MIB_NOTIFICATION_TYPE NotificationType); /// /// /// The PNETWORK_CONNECTIVITY_HINT_CHANGE_CALLBACK type is a pointer to a function that you define in your application. The /// function is called whenever there's a change in the network aggregate connectivity level and cost hints. /// /// Register your callback with a call to NotifyNetworkConnectivityHintChange. /// /// The user-specific caller context. /// /// A value of type NL_NETWORK_CONNECTIVITY_HINT representing the aggregate connectivity level and cost hints. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/netioapi/nc-netioapi-pnetwork_connectivity_hint_change_callback // PNETWORK_CONNECTIVITY_HINT_CHANGE_CALLBACK PnetworkConnectivityHintChangeCallback; void PnetworkConnectivityHintChangeCallback( PVOID CallerContext, NL_NETWORK_CONNECTIVITY_HINT ConnectivityHint ) {...} [UnmanagedFunctionPointer(CallingConvention.Winapi)] [PInvokeData("netioapi.h", MSDNShortId = "NC:netioapi.PNETWORK_CONNECTIVITY_HINT_CHANGE_CALLBACK")] public delegate void PNETWORK_CONNECTIVITY_HINT_CHANGE_CALLBACK(IntPtr CallerContext, NL_NETWORK_CONNECTIVITY_HINT ConnectivityHint); /// Called if NotifyStableUnicastIpAddressTable returns ERROR_IO_PENDING, which indicates that the I/O request is pending. /// /// The CallerContext parameter that is passed to the NotifyStableUnicastIpAddressTable function when it is registering the driver /// for notifications. /// /// /// A pointer to a MIB_UNICASTIPADDRESS_TABLE structure that contains the stable unicast IP address table on the local computer. /// [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK([In] IntPtr CallerContext, [In] IntPtr AddressTable); /// Function is called when a Teredo port change notification is received. /// /// The CallerContext parameter that is passed to the NotifyTeredoPortChange function when it is registering the driver for change notifications. /// /// /// The UDP port number that the Teredo client currently uses. This parameter is zero when the MIB_NOTIFICATION_TYPE value that is /// passed in the NotificationType parameter to the callback function is set to MibInitialNotification. This situation can occur only /// if the InitialNotification parameter that is passed to NotifyTeredoPortChange was set to TRUE when registering the driver for /// change notifications. /// /// /// The notification type. This member can be one of the values from the MIB_NOTIFICATION_TYPE enumeration type. /// [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void PTEREDO_PORT_CHANGE_CALLBACK([In] IntPtr CallerContext, [In] ushort Port, MIB_NOTIFICATION_TYPE NotificationType); /// This function is called when a unicast IP address notification is received. /// /// The CallerContext parameter that is passed to the NotifyUnicastIpAddressChange function when it is registering the driver for /// change notifications. /// /// /// A pointer to the MIB_UNICASTIPADDRESS_ROW entry for the unicast IP address that was changed. This parameter is a NULL pointer /// when the MIB_NOTIFICATION_TYPE value that is passed in the NotificationType parameter to the callback function is set to /// MibInitialNotification. This situation can occur only if the InitialNotification parameter that is passed to /// NotifyUnicastIpAddressChange was set to TRUE when registering the driver for change notifications. /// /// /// The notification type. This member can be one of the values from the MIB_NOTIFICATION_TYPE enumeration type. /// [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void PUNICAST_IPADDRESS_CHANGE_CALLBACK([In] IntPtr CallerContext, [In, Optional] IntPtr Row, [In] MIB_NOTIFICATION_TYPE NotificationType); /// A set of flags that provide information about an interface. [PInvokeData("netioapi.h")] [Flags] public enum InterfaceAndOperStatusFlags : byte { /// Set if the network interface is for hardware. HardwareInterface = 1 << 0, /// Set if the network interface is for a filter module. FilterInterface = 1 << 1, /// Set if a connector is present on the network interface. This value is set if there is a physical network adapter. ConnectorPresent = 1 << 2, /// /// Set if the default port for the network interface is not authenticated. If a network interface is not authenticated by the /// target, then the network interface is not in an operational mode. Although this applies to both wired and wireless network /// connections, authentication is more common for wireless network connections. /// NotAuthenticated = 1 << 3, /// /// Set if the network interface is not in a media-connected state. If a network cable is unplugged for a wired network, this /// would be set. For a wireless network, this is set for the network adapter that is not connected to a network. /// NotMediaConnected = 1 << 4, /// /// Set if the network stack for the network interface is in the paused or pausing state. This does not mean that the computer is /// in a hibernated state. /// Paused = 1 << 5, /// Set if the network interface is in a low power state. LowPower = 1 << 6, /// /// Set if the network interface is an endpoint device and not a true network interface that connects to a network. This can be /// set by devices such as smart phones which use networking infrastructure to communicate to the PC but do not provide /// connectivity to an external network. It is mandatory for these types of devices to set this flag. /// EndPointInterface = 1 << 7 } /// The level of interface information to retrieve. [PInvokeData("netioapi.h")] public enum MIB_IF_ENTRY_LEVEL { /// /// 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. /// MibIfEntryNormal = 0, /// /// 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. /// 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 MIB_NOTIFICATION_TYPE enumeration type defines the notification type that is passed to a callback function when a /// notification occurs. /// // typedef enum _MIB_NOTIFICATION_TYPE { MibParameterNotification = 0, MibAddInstance = 1, MibDeleteInstance = 2, // MibInitialNotification = 3} MIB_NOTIFICATION_TYPE, *PMIB_NOTIFICATION_TYPE; https://msdn.microsoft.com/en-us/library/windows/hardware/ff559286(v=vs.85).aspx [PInvokeData("Netioapi.h", MSDNShortId = "ff559286")] public enum MIB_NOTIFICATION_TYPE { /// A parameter was changed. MibParameterNotification, /// A new MIB instance was added. MibAddInstance, /// An existing MIB instance was deleted. MibDeleteInstance, /// /// A notification that is invoked immediately after registration for change notification completes. This initial notification /// does not indicate that a change occurred to a MIB instance. The purpose of this initial notification type is to provide /// confirmation that the callback function is properly registered. /// MibInitialNotification, } /// /// 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 Vista and 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 Vista and 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(in 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 Vista and 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 Vista and 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(in 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 Vista and 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(in 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 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 Vista and 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 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 Vista and 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 Vista and 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 Vista and 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 CreateAnycastIpAddressEntry function adds a new anycast IP address entry on the local computer. /// /// /// A pointer to a MIB_ANYCASTIPADDRESS_ROW structure entry for an anycast 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_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 of the 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. /// /// /// /// ERROR_OBJECT_ALREADY_EXISTS /// /// The object already exists. This error is returned if the Address member of the MIB_ANYCASTIPADDRESS_ROW pointed to by the Row /// parameter is a duplicate of an existing anycast IP address on the interface specified by the InterfaceLuid or InterfaceIndex /// member of the MIB_ANYCASTIPADDRESS_ROW. /// /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The CreateAnycastIpAddressEntry function is defined on Windows Vista and later. /// The CreateAnycastIpAddressEntry function is used to add a new anycast IP address entry on a local computer. /// /// The Address member in the MIB_ANYCASTIPADDRESS_ROW structure pointed to by the Row parameter must be initialized 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 to the interface: the /// InterfaceLuid or InterfaceIndex. /// /// /// The ScopeId member of the MIB_ANYCASTIPADDRESS_ROW structure pointed to by the Row is ignored when the /// CreateAnycastIpAddressEntry function is called. The ScopeId member is automatically determined by the interface on /// which the address is added. /// /// /// The CreateAnycastIpAddressEntry function will fail if the anycast IP address passed in the Address member of the /// MIB_ANYCASTIPADDRESS_ROW pointed to by the Row parameter is a duplicate of an existing anycast IP address on the interface. /// /// /// The CreateAnycastIpAddressEntry function can only be called by a user logged on as a member of the Administrators group. /// If CreateAnycastIpAddressEntry 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-createanycastipaddressentry _NETIOAPI_SUCCESS_ // NETIOAPI_API CreateAnycastIpAddressEntry( CONST MIB_ANYCASTIPADDRESS_ROW *Row ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "30393132-0fad-4687-b9e3-7b5cf47fbb96")] public static extern Win32Error CreateAnycastIpAddressEntry(ref MIB_ANYCASTIPADDRESS_ROW Row); /// /// 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 greater 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([Optional] IntPtr SourceAddressList, uint SourceAddressCount, [In] 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_NATIVE[] CreateSortedAddressPairs(SOCKADDR_IN6[] DestinationAddressList) { CreateSortedAddressPairs(IntPtr.Zero, 0, DestinationAddressList, (uint)DestinationAddressList.Length, 0, out var pairs, out var cnt).ThrowIfFailed(); return Array.ConvertAll(pairs.ToArray((int)cnt), up => (SOCKADDR_IN6_PAIR_NATIVE)up); } /// /// 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 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 DeleteUnicastIpAddressEntry function deletes an existing unicast IP address entry on the local computer. /// /// /// /// A pointer to a MIB_UNICASTIPADDRESS_ROW structure entry for an existing unicast 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_UNICASTIPADDRESS_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_UNICASTIPADDRESS_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_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 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. /// /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The DeleteUnicastIpAddressEntry function is defined on Windows Vista and later. /// /// The DeleteUnicastIpAddressEntry function is used to delete an existing MIB_UNICASTIPADDRESS_ROW structure entry on the /// local computer. /// /// /// On input, the Address member in the MIB_UNICASTIPADDRESS_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_UNICASTIPADDRESS_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 GetUnicastIpAddressTable function can be called to enumerate the unicast IP address entries on a local computer. The /// GetUnicastIpAddressEntry function can be called to retrieve a specific existing unicast IP address entry. /// /// /// The DeleteUnicastIpAddressEntry function can only be called by a user logged on as a member of the Administrators group. /// If DeleteUnicastIpAddressEntry 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-deleteunicastipaddressentry _NETIOAPI_SUCCESS_ // NETIOAPI_API DeleteUnicastIpAddressEntry( CONST MIB_UNICASTIPADDRESS_ROW *Row ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "a630397a-ef4a-40c2-b2e7-3e85cd9e8029")] public static extern Win32Error DeleteUnicastIpAddressEntry(ref MIB_UNICASTIPADDRESS_ROW 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 FlushIpPathTable function flushes the IP path 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 IP path 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 IP path 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 IP path table /// containing only IPv6 entries. /// /// /// /// /// /// 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 FlushIpPathTable function is defined on Windows Vista and later. /// /// The FlushIpPathTable function flushes or deletes the IP path entries on a local system. The Family parameter can be used /// to limit the IP path entries to delete to a particular IP address family. If IP path entries for both IPv4 and IPv6 should be /// deleted, set the Family parameter to AF_UNSPEC. /// /// The Family parameter must be initialized to either AF_INET, AF_INET6, or AF_UNSPEC. /// /// The FlushIpPathTable function can only be called by a user logged on as a member of the Administrators group. If /// FlushIpPathTable 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-flushippathtable _NETIOAPI_SUCCESS_ NETIOAPI_API // FlushIpPathTable( ADDRESS_FAMILY Family ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "3b28e0cd-9cab-41ca-b58c-7632768318c2")] public static extern Win32Error FlushIpPathTable(ADDRESS_FAMILY Family); /// /// /// 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 GetAnycastIpAddressEntry function retrieves information for an existing anycast IP address entry on the local computer. /// /// /// /// /// A pointer to a MIB_ANYCASTIPADDRESS_ROW structure entry for an anycast IP address entry. On successful return, this structure /// will be updated with the properties for an existing anycast 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_ANYCASTIPADDRESS_ROW pointed to by the Row parameter is not a value on the /// local machine. /// /// /// /// ERROR_INVALID_PARAMETER /// /// A parameter is incorrect. 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 is not set to a valid anycast 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 /// /// Element not found. This error is returned if the network interface specified by the InterfaceLuid or InterfaceIndex member of the /// MIB_ANYCASTIPADDRESS_ROW structure pointed to by the Row parameter does not match the IP address and address family specified in /// the Address member in the MIB_ANYCASTIPADDRESS_ROW 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 is specified /// in the Address member of the MIB_UNICASTIPADDRESS_ROW structure pointed to by the Row parameter. This error is returned if no /// IPv6 stack is on the local computer and an IPv6 address is specified in the Address member. /// /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The GetAnycastIpAddressEntry function is defined on Windows Vista and later. /// The GetAnycastIpAddressEntry function is used to retrieve an existing MIB_ANYCASTIPADDRESS_ROW structure entry. /// /// On input, the Address member in the MIB_ANYCASTIPADDRESS_ROW structure pointed to by the Row parameter must be initialized /// to a valid anycast 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. /// /// /// On output when the call is successful, GetAnycastIpAddressEntry retrieves the other properties for the anycast IP address /// and fills out the MIB_ANYCASTIPADDRESS_ROW structure pointed to by the Row parameter. /// /// The GetAnycastIpAddressTable function can be called to enumerate the anycast IP address entries on a local computer. /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getanycastipaddressentry _NETIOAPI_SUCCESS_ NETIOAPI_API // GetAnycastIpAddressEntry( PMIB_ANYCASTIPADDRESS_ROW Row ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "d60828ed-e1fd-4e57-92be-08a189c27fe5")] public static extern Win32Error GetAnycastIpAddressEntry(ref MIB_ANYCASTIPADDRESS_ROW Row); /// /// The GetAnycastIpAddressTable function retrieves the anycast IP address 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 anycast 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 anycast 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 anycast IP /// address table containing only IPv6 entries. /// /// /// /// /// /// A pointer to a MIB_ANYCASTIPADDRESS_TABLE structure that contains a table of anycast IP address entries on 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_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 anycast IP address entries as specified in the Family parameter were found. /// /// /// 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 GetAnycastIpAddressTable function is defined on Windows Vista and later. /// /// The GetAnycastIpAddressTable function enumerates the anycast IP addresses on a local system and returns this information /// in a MIB_ANYCASTIPADDRESS_TABLE structure. /// /// /// The anycast IP address entries are returned in a MIB_ANYCASTIPADDRESS_TABLE structure in the buffer pointed to by the Table /// parameter. The MIB_ANYCASTIPADDRESS_TABLE structure contains an anycast IP address entry count and an array of /// MIB_ANYCASTIPADDRESS_ROW structures for each anycast 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_ANYCASTIPADDRESS_TABLE structure pointed to by the Table parameter may contain padding for alignment /// between the NumEntries member and the first MIB_ANYCASTIPADDRESS_ROW array entry in the Table member of the /// MIB_ANYCASTIPADDRESS_TABLE structure. Padding for alignment may also be present between the /// MIB_ANYCASTIPADDRESS_ROW array entries. Any access to a MIB_ANYCASTIPADDRESS_ROW array entry should assume padding /// may exist. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getanycastipaddresstable _NETIOAPI_SUCCESS_ NETIOAPI_API // GetAnycastIpAddressTable( ADDRESS_FAMILY Family, PMIB_ANYCASTIPADDRESS_TABLE *Table ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "4eccae59-00be-4f9c-bb62-a507d7dad2e0")] public static extern Win32Error GetAnycastIpAddressTable(ADDRESS_FAMILY Family, out MIB_ANYCASTIPADDRESS_TABLE Table); /// /// /// 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(in NET_LUID InterfaceLuid, uint InterfaceIndex, in SOCKADDR_INET SourceAddress, in 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([Optional] IntPtr InterfaceLuid, uint InterfaceIndex, in SOCKADDR_INET SourceAddress, in 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([Optional] IntPtr InterfaceLuid, uint InterfaceIndex, [Optional] IntPtr SourceAddress, in 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 GetIfStackTable function retrieves a table of network interface stack row entries that specify the relationship of the /// network interfaces on an interface stack. /// /// /// /// A pointer to a buffer that receives the table of interface stack row entries in a MIB_IFSTACK_TABLE 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 a NULL pointer is passed in the Table parameter. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// Insufficient memory resources are available to complete the operation. /// /// /// ERROR_NOT_FOUND /// No interface stack entries were found. /// /// /// Other /// Use the FormatMessage function to obtain the message string for the returned error. /// /// /// /// /// The GetIfStackTable function is defined on Windows Vista and later. /// /// The GetIfStackTable function enumerates the physical and logical network interfaces on an interface stack on a local /// system and returns this information in a MIB_IFSTACK_TABLE structure. /// /// /// Interface stack entries are returned in a MIB_IFSTACK_TABLE structure in the buffer pointed to by the Table parameter. The /// MIB_IFSTACK_TABLE structure contains an interface stack entry count and an array of MIB_IFSTACK_ROW structures for each /// interface stack entry. /// /// /// The relationship between the interfaces in the interface stack is that the interface with index in the /// HigherLayerInterfaceIndex member of the MIB_IFSTACK_ROW structure is immediately above the interface with index in the /// LowerLayerInterfaceIndex member of the MIB_IFSTACK_ROW structure. /// /// /// Memory is allocated by the GetIfStackTable function for the MIB_IFSTACK_TABLE structure and the MIB_IFSTACK_ROW entries in /// this structure. When these returned structures are no longer required, free the memory by calling the FreeMibTable. /// /// /// Note that the returned MIB_IFSTACK_TABLE structure pointed to by the Table parameter may contain padding for alignment between /// the NumEntries member and the first MIB_IFSTACK_ROW array entry in the Table member of the MIB_IFSTACK_TABLE /// structure. Padding for alignment may also be present between the MIB_IFSTACK_ROW array entries. Any access to a /// MIB_IFSTACK_ROW array entry should assume padding may exist. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getifstacktable _NETIOAPI_SUCCESS_ NETIOAPI_API // GetIfStackTable( PMIB_IFSTACK_TABLE *Table ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "c1b0f091-2aef-447e-9866-a886838a6267")] public static extern Win32Error GetIfStackTable(out MIB_IFSTACK_TABLE Table); /// /// 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 Table); /// /// 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 Table); /// /// /// The GetInvertedIfStackTable function retrieves a table of inverted network interface stack row entries that specify the /// relationship of the network interfaces on an interface stack. /// /// /// /// A pointer to a buffer that receives the table of inverted interface stack row entries in a MIB_INVERTEDIFSTACK_TABLE 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 a NULL pointer is passed in the Table parameter. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// Insufficient memory resources are available to complete the operation. /// /// /// ERROR_NOT_FOUND /// No interface stack entries were found. /// /// /// Other /// Use the FormatMessage function to obtain the message string for the returned error. /// /// /// /// /// The GetInvertedIfStackTable function is defined on Windows Vista and later. /// /// The GetInvertedIfStackTable function enumerates the physical and logical network interfaces on an interface stack on a /// local system and returns this information in an inverted form in the MIB_INVERTEDIFSTACK_TABLE structure. /// /// /// Interface stack entries are returned in a MIB_INVERTEDIFSTACK_TABLE structure in the buffer pointed to by the Table parameter. /// The MIB_INVERTEDIFSTACK_TABLE structure contains an interface stack entry count and an array of MIB_INVERTEDIFSTACK_ROW /// structures for each interface stack entry. /// /// /// The relationship between the interfaces in the interface stack is that the interface with index in the /// HigherLayerInterfaceIndex member of the MIB_INVERTEDIFSTACK_ROW structure is immediately above the interface with index in /// the LowerLayerInterfaceIndex member of the MIB_INVERTEDIFSTACK_ROW structure. /// /// /// Memory is allocated by the GetInvertedIfStackTable function for the MIB_INVERTEDIFSTACK_TABLE structure and the /// MIB_INVERTEDIFSTACK_ROW entries in this structure. When these returned structures are no longer required, free the memory by /// calling the FreeMibTable. /// /// /// Note that the returned MIB_INVERTEDIFSTACK_TABLE structure pointed to by the Table parameter may contain padding for alignment /// between the NumEntries member and the first MIB_INVERTEDIFSTACK_ROW array entry in the Table member of the /// MIB_INVERTEDIFSTACK_TABLE structure. Padding for alignment may also be present between the MIB_INVERTEDIFSTACK_ROW /// array entries. Any access to a MIB_INVERTEDIFSTACK_ROW array entry should assume padding may exist. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getinvertedifstacktable _NETIOAPI_SUCCESS_ NETIOAPI_API // GetInvertedIfStackTable( PMIB_INVERTEDIFSTACK_TABLE *Table ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "d1808ded-2798-46cc-8021-fdbcd3da60ea")] public static extern Win32Error GetInvertedIfStackTable(out MIB_INVERTEDIFSTACK_TABLE Table); /// /// The GetIpForwardEntry2 function retrieves information for 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 structure will be updated /// with the properties for the 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_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 /// /// Element not found. This error is returned if the network interface specified by the InterfaceLuid or InterfaceIndex member of the /// MIB_IPFORWARD_ROW2 structure pointed to by the Row parameter does not match the IP address prefix and address family specified in /// the DestinationPrefix member in the MIB_IPFORWARD_ROW2 structure. /// /// /// /// 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 /// 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. /// /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The GetIpForwardEntry2 function is defined on Windows Vista and later. /// The GetIpForwardEntry2 function is used to retrieve 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, GetIpForwardEntry2 retrieves the other properties for the IP route entry and fills /// out the MIB_IPFORWARD_ROW2 structure pointed to by the Row parameter. /// /// /// 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 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 GetIpForwardTable2 function can be called to enumerate the IP route entries on a local computer. /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getipforwardentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API // GetIpForwardEntry2( PMIB_IPFORWARD_ROW2 Row ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "53d5009a-d205-40ce-88e5-fe37e72b5a50")] public static extern Win32Error GetIpForwardEntry2(ref MIB_IPFORWARD_ROW2 Row); /// /// The GetIpForwardTable2 function retrieves the IP route entries 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 IP routing 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 IP routing /// 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 IP routing /// table containing only IPv6 entries. /// /// /// /// /// /// A pointer to a MIB_IPFORWARD_TABLE2 structure that contains a table of IP route entries on 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_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 IP route entries as specified in the Family parameter were found. /// /// /// 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 GetIpForwardTable2 function 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. /// /// /// The IP route entries are returned in a MIB_IPFORWARD_TABLE2 structure in the buffer pointed to by the Table parameter. The /// MIB_IPFORWARD_TABLE2 structure contains an IP route entry count and an array of MIB_IPFORWARD_ROW2 structures for each IP /// route 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_IPFORWARD_TABLE2 structure pointed to by the Table parameter may contain padding for alignment between /// the NumEntries member and the first MIB_IPFORWARD_ROW2 array entry in the Table member of the /// MIB_IPFORWARD_TABLE2 structure. Padding for alignment may also be present between the MIB_IPFORWARD_ROW2 array /// entries. Any access to a MIB_IPFORWARD_ROW2 array entry should assume padding may exist. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getipforwardtable2 _NETIOAPI_SUCCESS_ NETIOAPI_API // GetIpForwardTable2( ADDRESS_FAMILY Family, PMIB_IPFORWARD_TABLE2 *Table ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "14412ef1-d970-419d-abfa-389f6ceb638d")] public static extern Win32Error GetIpForwardTable2(ADDRESS_FAMILY Family, out MIB_IPFORWARD_TABLE2 Table); /// /// The GetIpInterfaceEntry function retrieves IP information for the specified interface on the local computer. /// /// /// /// A pointer to a MIB_IPINTERFACE_ROW structure that, on successful return, receives information for an interface on the local /// computer. On input, the InterfaceLuid or InterfaceIndex member of the MIB_IPINTERFACE_ROW 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_IPINTERFACE_ROW 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 /// Family member of the MIB_IPINTERFACE_ROW pointed to by the Row parameter was not specified as AF_INET or AF_INET6, or both the /// InterfaceLuid or InterfaceIndex members of the MIB_IPINTERFACE_ROW 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_IPINTERFACE_ROW structure pointed to by the Row parameter does not match the IP address family specified in the Family member /// in the MIB_IPINTERFACE_ROW structure. /// /// /// /// Other /// Use the FormatMessage function to obtain the message string for the returned error. /// /// /// /// /// The GetIpInterfaceEntry function is defined on Windows Vista and later. /// /// On input, the Family member in the MIB_IPINTERFACE_ROW structure pointed to by the Row parameter must be initialized to /// either AF_INET or AF_INET6. In addition on input, at least one of the following members in the /// MIB_IPINTERFACE_ROW structure pointed to the Row parameter must be initialized: the InterfaceLuid or InterfaceIndex. /// /// /// On output, the InterfaceLuid member of the MIB_IPINTERFACE_ROW structure pointed to by the Row parameter is filled in if /// the InterfaceIndex was specified. The other members of MIB_IPINTERFACE_ROW structure pointed to by the Row /// parameter are also filled in. /// /// /// The InitializeIpInterfaceEntry function must be used to initialize the fields of a MIB_IPINTERFACE_ROW structure entry with /// default values. An application can then change the fields in the MIB_IPINTERFACE_ROW entry it wishes to modify, and then /// call the SetIpInterfaceEntry function. /// /// /// Unprivileged simultaneous access to multiple networks of different security requirements creates a security hole and allows an /// unprivileged application to accidentally relay data between the two networks. A typical example is simultaneous access to a /// virtual private network (VPN) and the Internet. Windows Server 2003 and Windows XP use a weak host model, where RAS prevents such /// simultaneous access by increasing the route metric of all default routes over other interfaces. Thus all traffic is routed /// through the VPN interface, disrupting other network connectivity. /// /// /// On Windows Vista and later, a strong host model is used by default. If a source IP address is specified in the route lookup using /// GetBestRoute2 or GetBestRoute, the route lookup is restricted to the interface of the source IP address. The route metric /// modification by RAS has no effect as the list of potential routes does not even have the route for the VPN interface thereby /// allowing traffic to the Internet. The DisableDefaultRoutes member of the MIB_IPINTERFACE_ROW can be used to disable using /// the default route on an interface. This member can be used as a security measure by VPN clients to restrict split tunneling when /// split tunneling is not required by the VPN client. A VPN client can call the SetIpInterfaceEntry function to set the /// DisableDefaultRoutes member to TRUE when required. A VPN client can query the current state of the /// DisableDefaultRoutes member by calling the GetIpInterfaceEntry function. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getipinterfaceentry _NETIOAPI_SUCCESS_ NETIOAPI_API // GetIpInterfaceEntry( PMIB_IPINTERFACE_ROW Row ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "604e33fd-ab12-4861-a083-544045f46ef4")] public static extern Win32Error GetIpInterfaceEntry(ref MIB_IPINTERFACE_ROW Row); /// /// The GetIpInterfaceTable function retrieves the IP interface entries on the local computer. /// /// /// The address family of IP interfaces 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 Windows Vista and later as well as on the Windows SDK, 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, the GetIpInterfaceTable function returns the IP interface /// table containing both IPv4 and IPv6 entries. /// /// /// /// AF_INET 2 /// The Internet Protocol version 4 (IPv4) address family. /// /// /// AF_INET6 23 /// The Internet Protocol version 6 (IPv6) address family. /// /// /// /// /// A pointer to a buffer that receives the table of IP interface entries in a MIB_IPINTERFACE_TABLE 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 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 IP interface entries as specified in the Family parameter were found. /// /// /// ERROR_NOT_SUPPORTED /// /// The function is not supported. This error is returned when the IP transport specified in the Address parameter is not configured /// on the local computer. This error is also returned on versions of Windows where this function is not supported. /// /// /// /// Other /// Use the FormatMessage function to obtain the message string for the returned error. /// /// /// /// /// The GetIpInterfaceTable function is defined on Windows Vista and later. /// /// The GetIpInterfaceTable function enumerates the IP interfaces on a local system and returns this information in an /// MIB_IPINTERFACE_TABLE structure. /// /// /// IP interface entries are returned in a MIB_IPINTERFACE_TABLE structure in the buffer pointed to by the Table parameter. The /// MIB_IPINTERFACE_TABLE structure contains an IP interface entry count and an array of MIB_IPINTERFACE_ROW structures for /// each IP interface 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 or AF_INET6. /// /// Note that the returned MIB_IPINTERFACE_TABLE structure pointed to by the Table parameter may contain padding for alignment /// between the NumEntries member and the first MIB_IPINTERFACE_ROW array entry in the Table member of the /// MIB_IPINTERFACE_TABLE structure. Padding for alignment may also be present between the MIB_IPINTERFACE_ROW array /// entries. Any access to a MIB_IPINTERFACE_ROW array entry should assume padding may exist. /// /// Examples /// /// The following example retrieves the IP interface table, then prints the values of a few members of the IP interface entries in /// the table. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getipinterfacetable _NETIOAPI_SUCCESS_ NETIOAPI_API // GetIpInterfaceTable( ADDRESS_FAMILY Family, PMIB_IPINTERFACE_TABLE *Table ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "09f2bbff-3281-41ae-878f-61c5afa20ec5")] public static extern Win32Error GetIpInterfaceTable(ADDRESS_FAMILY Family, out MIB_IPINTERFACE_TABLE Table); /// /// 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); /// /// Unlike this returns structure with zero copy. // 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, EntryPoint = "GetIpNetTable2")] [PInvokeData("netioapi.h", MSDNShortId = "6c45d735-9a07-41ca-8d8a-919f32c98a3c")] public static extern Win32Error GetIpNetTable2_Unmanaged(ADDRESS_FAMILY Family, out MIB_IPNET_TABLE2_Unmanaged Table); /// /// /// The GetIpNetworkConnectionBandwidthEstimates function retrieves historical bandwidth estimates for a network connection on /// the specified interface. /// /// /// /// The local index value for the network interface. /// /// 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 address family. Possible values for the address family are listed in the Ws2def.h header file. Note that the values for the /// AF_ address family and PF_ protocol family constants are identical (for example, AF_INET and PF_INET), so either /// constant can be used. /// /// 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 or AF_INET6, which are the Internet address family formats for IPv4 and IPv6. /// /// /// /// Value /// Meaning /// /// /// AF_INET 2 /// The Internet Protocol version 4 (IPv4) address family. /// /// /// AF_INET6 23 /// The Internet Protocol version 6 (IPv6) address family. /// /// /// /// /// /// A pointer to a buffer that returns the historical bandwidth estimates maintained for the point of attachment to which the /// interface is currently connected. /// /// /// /// 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 interface index specified by the InterfaceIndex /// 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 BandwidthEstimates /// parameter or the AddressFamily parameter was not specified as AF_INET or AF_INET6. /// /// /// /// ERROR_NOT_FOUND /// /// Element not found. This error is returned if the network interface specified by the InterfaceIndex parameter does not match the /// IP address family specified in the AddressFamily parameter. /// /// /// /// Other /// Use the FormatMessage function to obtain the message string for the returned error. /// /// /// /// /// The GetIpNetworkConnectionBandwidthEstimates function is defined on Windows 8 and later. /// /// On input, the AddressFamily parameter must be initialized to either AF_INET or AF_INET6. In addition on input, the /// InterfaceIndex parameter must be initialized with the specified interface index. /// /// /// On output, the MIB_IP_NETWORK_CONNECTION_BANDWIDTH_ESTIMATES structure pointed to by the BandwidthEstimates parameter is filled /// in if the AddressFamily and InterfaceIndex parameters were specified. /// /// /// The GetIpNetworkConnectionBandwidthEstimates function returns historical estimates of available bandwidth at the point of /// attachment (the first hop) for use by an application. The estimates are intended as a guide to tune performance parameters and /// the application should maintain thresholds and differentiate behavior for low and high bandwidth situations. /// /// /// It is possible that the true available bandwidth changes over time as more bandwidth is consumed by devices competing on the same /// network. So applications should be prepared to handle cases where the available bandwidth drops below historical limits reported /// by the GetIpNetworkConnectionBandwidthEstimates function. /// /// /// It is possible that the TCP/IP stack has not built up any estimates for the given interface, in a particular or both directions. /// In this case the estimate returned will be zero. The application should be prepared to handle such cases by picking reasonable /// defaults and fine tuning if required. /// /// /// The Netioapi.h header file is automatically included by 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/nf-netioapi-getipnetworkconnectionbandwidthestimates // _NETIOAPI_SUCCESS_ NETIOAPI_API GetIpNetworkConnectionBandwidthEstimates( NET_IFINDEX InterfaceIndex, ADDRESS_FAMILY // AddressFamily, PMIB_IP_NETWORK_CONNECTION_BANDWIDTH_ESTIMATES BandwidthEstimates ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "FE60AF0D-15B0-4223-8AE1-3E65483A1C5F")] public static extern Win32Error GetIpNetworkConnectionBandwidthEstimates(uint InterfaceIndex, ADDRESS_FAMILY AddressFamily, out MIB_IP_NETWORK_CONNECTION_BANDWIDTH_ESTIMATES BandwidthEstimates); /// /// The GetIpPathEntry function retrieves information for a IP path entry on the local computer. /// /// /// /// A pointer to a MIB_IPPATH_ROW structure entry for a IP path entry. On successful return, this structure will be updated with the /// properties for IP path 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_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_IPPATH_ROW pointed to by the Row parameter is not a value on the local machine. /// /// /// /// ERROR_INVALID_PARAMETER /// /// A parameter is incorrect. This error is returned if a NULL pointer is passed in the Row parameter, the si_family member in the /// Destination member of the MIB_IPPATH_ROW pointed to by the Row parameter is not set to AF_INET or AF_INET6, or both the /// InterfaceLuid or InterfaceIndex members of the MIB_IPPATH_ROW pointed to by the Row parameter are unspecified. This error is also /// returned if the si_family member in the Source member of the MIB_IPPATH_ROW pointed to by the Row parameter did not match the /// destination IP address family and the si_family for the source IP address is not specified as AF_UNSPEC. /// /// /// /// ERROR_NOT_FOUND /// /// Element not found. This error is returned if the network interface specified by the InterfaceLuid or InterfaceIndex member of the /// MIB_IPPATH_ROW structure pointed to by the Row parameter does not match the IP address and address family specified in the /// Destination member in the MIB_IPPATH_ROW 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 is specified /// in the Source and Destination members of the MIB_IPPATH_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 is specified in the Source and Destination members. /// /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The GetIpPathEntry function is defined on Windows Vista and later. /// The GetIpPathEntry function is used to retrieve a MIB_IPPATH_ROW structure entry. /// /// On input, the Destination member in the MIB_IPPATH_ROW structure pointed to by the Row parameter must be initialized to a /// valid IPv4 or IPv6 address and family. The address family specified in Source member in the MIB_IPPATH_ROW /// structure must also either match the destination IP address family specified in the Destination member or the address /// family in the Source member must be specified as AF_UNSPEC. In addition , at least one of the following members in /// the MIB_IPPATH_ROW structure pointed to the Row parameter must be initialized: the InterfaceLuid or InterfaceIndex. /// /// /// On output when the call is successful, GetIpPathEntry retrieves the other properties for the IP path entry and fills out /// the MIB_IPPATH_ROW structure pointed to by the Row parameter. /// /// The GetIpPathTable function can be called to enumerate the IP path entries on a local computer. /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getippathentry _NETIOAPI_SUCCESS_ NETIOAPI_API // GetIpPathEntry( PMIB_IPPATH_ROW Row ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "8ad43a1d-428a-41cc-bba8-5eec7f87c11f")] public static extern Win32Error GetIpPathEntry(ref MIB_IPPATH_ROW Row); /// /// The GetIpPathTable function retrieves the IP path 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 IP path 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 IP path 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 IP path table /// containing only IPv6 entries. /// /// /// /// /// /// A pointer to a MIB_IPPATH_TABLE structure that contains a table of IP path entries on 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_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 IP path entries as specified in the Family parameter were found. /// /// /// 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 GetIpPathTable function is defined on Windows Vista and later. /// /// The GetIpPathTable function enumerates the IP path entries on a local system and returns this information in a /// MIB_IPPATH_TABLE structure. /// /// /// The IP path entries are returned in a MIB_IPPATH_TABLE structure in the buffer pointed to by the Table parameter. The /// MIB_IPPATH_TABLE structure contains an IP path entry count and an array of MIB_IPPATH_ROW structures for each IP path /// 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_IPPATH_TABLE structure pointed to by the Table parameter may contain padding for alignment between the /// NumEntries member and the first MIB_IPPATH_ROW array entry in the Table member of the MIB_IPPATH_TABLE /// structure. Padding for alignment may also be present between the MIB_IPPATH_ROW array entries. Any access to a /// MIB_IPPATH_ROW array entry should assume padding may exist. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getippathtable _NETIOAPI_SUCCESS_ NETIOAPI_API // GetIpPathTable( ADDRESS_FAMILY Family, PMIB_IPPATH_TABLE *Table ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "e03816a4-0b86-4e0b-a45e-8148c8ba5472")] public static extern Win32Error GetIpPathTable(ADDRESS_FAMILY Family, out MIB_IPPATH_TABLE Table); /// /// /// The GetMulticastIpAddressEntry function retrieves information for an existing multicast IP address entry on the local computer. /// /// /// /// /// A pointer to a MIB_MULTICASTIPADDRESS_ROW structure entry for a multicast IP address entry. On successful return, this structure /// will be updated with the properties for an existing multicast 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_MULTICASTIPADDRESS_ROW pointed to by the Row parameter is not a value on /// the local machine. /// /// /// /// ERROR_INVALID_PARAMETER /// /// A parameter is incorrect. This error is returned if a NULL pointer is passed in the Row parameter, the Address member of the /// MIB_MULTICASTIPADDRESS_ROW pointed to by the Row parameter is not set to a valid multicast IPv4 or IPv6 address, or both the /// InterfaceLuid or InterfaceIndex members of the MIB_MULTICASTIPADDRESS_ROW pointed to by the Row parameter are 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_MULTICASTIPADDRESS_ROW structure pointed to by the Row parameter does not match the IP address and address family specified /// in the Address member in the MIB_MULTICASTIPADDRESS_ROW 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 is specified /// in the Address member MIB_MULTICASTIPADDRESS_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 is specified in the Address member. /// /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The GetMulticastIpAddressEntry function is defined on Windows Vista and later. /// The GetMulticastIpAddressEntry function is used to retrieve an existing MIB_MULTICASTIPADDRESS_ROW structure entry. /// /// On input, the Address member in the MIB_MULTICASTIPADDRESS_ROW structure pointed to by the Row parameter must be /// initialized to a valid multicast IPv4 or IPv6 address and family. In addition, at least one of the following members in the /// MIB_MULTICASTIPADDRESS_ROW structure pointed to the Row parameter must be initialized: the InterfaceLuid or InterfaceIndex. /// /// /// On output when the call is successful, GetMulticastIpAddressEntry retrieves the other properties for the multicast IP /// address and fills out the MIB_MULTICASTIPADDRESS_ROW structure pointed to by the Row parameter. /// /// The GetMulticastIpAddressTable function can be called to enumerate the multicast IP address entries on a local computer. /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getmulticastipaddressentry _NETIOAPI_SUCCESS_ // NETIOAPI_API GetMulticastIpAddressEntry( PMIB_MULTICASTIPADDRESS_ROW Row ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "dc6401b6-7692-44a5-b2f0-4e729b996765")] public static extern Win32Error GetMulticastIpAddressEntry(ref MIB_MULTICASTIPADDRESS_ROW Row); /// /// The GetMulticastIpAddressTable function retrieves the multicast IP address 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 multicast 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 multicast 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 multicast IP /// address table containing only IPv6 entries. /// /// /// /// /// /// /// A pointer to a MIB_MULTICASTIPADDRESS_TABLE structure that contains a table of anycast IP address entries on 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_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 anycast IP address entries as specified in the Family parameter were found. /// /// /// 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 GetMulticastIpAddressTable function is defined on Windows Vista and later. /// /// The GetMulticastIpAddressTable function enumerates the multicast IP addresses on a local system and returns this /// information in a MIB_MULTICASTIPADDRESS_TABLE structure. /// /// /// The multicast IP address entries are returned in a MIB_MULTICASTIPADDRESS_TABLE structure in the buffer pointed to by the Table /// parameter. The MIB_MULTICASTIPADDRESS_TABLE structure contains a multicast IP address entry count and an array of /// MIB_MULTICASTIPADDRESS_ROW structures for each multicast 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_MULTICASTIPADDRESS_TABLE structure pointed to by the Table parameter may contain padding for alignment /// between the NumEntries member and the first MIB_MULTICASTIPADDRESS_ROW array entry in the Table member of the /// MIB_MULTICASTIPADDRESS_TABLE structure. Padding for alignment may also be present between the /// MIB_MULTICASTIPADDRESS_ROW array entries. Any access to a MIB_MULTICASTIPADDRESS_ROW array entry should assume /// padding may exist. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getmulticastipaddresstable _NETIOAPI_SUCCESS_ // NETIOAPI_API GetMulticastIpAddressTable( ADDRESS_FAMILY Family, PMIB_MULTICASTIPADDRESS_TABLE *Table ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "0958e92e-12ed-42e0-aa04-b8c4544f6642")] public static extern Win32Error GetMulticastIpAddressTable(ADDRESS_FAMILY Family, out MIB_MULTICASTIPADDRESS_TABLE Table); /// Retrieves the aggregate level and cost of network connectivity that an application or service is likely to experience. /// /// A pointer to a value of type NL_NETWORK_CONNECTIVITY_HINT. The function sets this value to the aggregate connectivity level and /// cost hints. /// /// /// In user mode, returns NO_ERROR on success, and an error code on failure. In kernel mode, returns STATUS_SUCCESS on /// success, and an error code on failure. /// // https://docs.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-getnetworkconnectivityhint // IPHLPAPI_DLL_LINKAGE _NETIOAPI_SUCCESS_ NETIOAPI_API GetNetworkConnectivityHint( NL_NETWORK_CONNECTIVITY_HINT *ConnectivityHint ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "NF:netioapi.GetNetworkConnectivityHint")] public static extern Win32Error GetNetworkConnectivityHint(out NL_NETWORK_CONNECTIVITY_HINT ConnectivityHint); /// Retrieves the level and cost of network connectivity for the specified interface. /// /// A value of type NET_IFINDEX representing the index of the interface for which to retrieve connectivity information. /// /// /// A pointer to a value of type NL_NETWORK_CONNECTIVITY_HINT. The function sets this value to the connectivity level and cost hints /// for the specified interface. /// /// /// In user mode, returns NO_ERROR on success, and an error code on failure. In kernel mode, returns STATUS_SUCCESS on /// success, and an error code on failure. /// // https://docs.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-getnetworkconnectivityhintforinterface // IPHLPAPI_DLL_LINKAGE _NETIOAPI_SUCCESS_ NETIOAPI_API GetNetworkConnectivityHintForInterface( NET_IFINDEX InterfaceIndex, NL_NETWORK_CONNECTIVITY_HINT *ConnectivityHint ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "NF:netioapi.GetNetworkConnectivityHintForInterface")] public static extern Win32Error GetNetworkConnectivityHintForInterface(uint InterfaceIndex, out NL_NETWORK_CONNECTIVITY_HINT ConnectivityHint); /// /// The GetTeredoPort function retrieves the dynamic UDP port number used by the Teredo client on the local computer. /// /// /// /// A pointer to the UDP port number. On successful return, this parameter will be filled with the port number used by the Teredo client. /// /// /// /// 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 Port parameter. /// /// /// ERROR_NOT_READY /// The device is not ready. This error is returned if the Teredo client is not started on the local computer. /// /// /// 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 GetTeredoPort function is defined on Windows Vista and later. /// /// The GetTeredoPort function retrieves the current UDP port number used by the Teredo client for the Teredo service port. /// The Teredo port is dynamic and can change any time the Teredo client is restarted on the local computer. An application can /// register to be notified when the Teredo service port changes by calling the NotifyTeredoPortChange function. /// /// /// The Teredo client also uses static UDP port 3544 for listening to multicast traffic sent on multicast IPv4 address 224.0.0.253 as /// defined in RFC 4380. For more information, see http://www.ietf.org/rfc/rfc4380.txt. /// /// /// The GetTeredoPort function is used primarily by firewall applications in order to configure the appropriate exceptions to /// allow incoming and outgoing Teredo traffic. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getteredoport _NETIOAPI_SUCCESS_ NETIOAPI_API // GetTeredoPort( USHORT *Port ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "59d3764d-e560-4474-a73e-ab50bbddbf07")] public static extern Win32Error GetTeredoPort(out ushort Port); /// /// /// The GetUnicastIpAddressEntry function retrieves information for an existing unicast IP address entry on the local computer. /// /// /// /// /// A pointer to a MIB_UNICASTIPADDRESS_ROW structure entry for a unicast IP address entry. On successful return, this structure will /// be updated with the properties for an existing unicast 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_UNICASTIPADDRESS_ROW pointed to by the Row parameter is not a value on the /// local machine. /// /// /// /// ERROR_INVALID_PARAMETER /// /// A parameter is incorrect. 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 is 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 are 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_UNICASTIPADDRESS_ROW structure pointed to by the Row parameter does not match the IP address specified in the Address member /// in the MIB_UNICASTIPADDRESS_ROW 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 is specified /// in the Address member of the MIB_UNICASTIPADDRESS_ROW 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 is specified in the Address member. /// /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The GetUnicastIpAddressEntry function is defined on Windows Vista and later. /// /// The GetUnicastIpAddressEntry function is normally used to retrieve an existing MIB_UNICASTIPADDRESS_ROW structure entry to /// be modified. An application can then change the members in the MIB_UNICASTIPADDRESS_ROW entry it wishes to modify, and /// then call the SetUnicastIpAddressEntry function. /// /// /// On input, 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: the InterfaceLuid or InterfaceIndex. /// /// /// On output when the call is successful, GetUnicastIpAddressEntry retrieves the other properties for the unicast IP address /// and fills out the MIB_UNICASTIPADDRESS_ROW structure pointed to by the Row parameter. /// /// The GetUnicastIpAddressTable function can be called to enumerate the unicast IP address entries on a local computer. /// Examples /// /// The following example retrieves a unicast IP address entry specified on the command line and prints some values from the /// retrieved MIB_UNICASTIPADDRESS_ROW structure. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getunicastipaddressentry _NETIOAPI_SUCCESS_ NETIOAPI_API // GetUnicastIpAddressEntry( PMIB_UNICASTIPADDRESS_ROW Row ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "d5475c09-05dd-41d7-80ff-63c52d78468c")] public static extern Win32Error GetUnicastIpAddressEntry(ref MIB_UNICASTIPADDRESS_ROW Row); /// /// The GetUnicastIpAddressTable function retrieves the unicast IP address 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 unicast 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 unicast 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 unicast IP /// address table containing only IPv6 entries. /// /// /// /// /// /// A pointer to a MIB_UNICASTIPADDRESS_TABLE structure that contains a table of unicast IP address entries on 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_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 /// Element not found. This error is returned if no unicast IP address entries as specified in the Family parameter were found. /// /// /// 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 GetUnicastIpAddressTable function is defined on Windows Vista and later. /// /// The GetUnicastIpAddressTable function enumerates the unicast IP addresses on a local system and returns this information /// in an MIB_UNICASTIPADDRESS_TABLE structure. /// /// /// The unicast IP address entries are returned in a MIB_UNICASTIPADDRESS_TABLE structure in the buffer pointed to by the Table /// parameter. The MIB_UNICASTIPADDRESS_TABLE structure contains a unicast IP address entry count and an array of /// MIB_UNICASTIPADDRESS_ROW structures for each unicast 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_UNICASTIPADDRESS_TABLE structure pointed to by the Table parameter may contain padding for alignment /// between the NumEntries member and the first MIB_UNICASTIPADDRESS_ROW array entry in the Table member of the /// MIB_UNICASTIPADDRESS_TABLE structure. Padding for alignment may also be present between the /// MIB_UNICASTIPADDRESS_ROW array entries. Any access to a MIB_UNICASTIPADDRESS_ROW array entry should assume padding /// may exist. /// /// 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/nf-netioapi-getunicastipaddresstable _NETIOAPI_SUCCESS_ NETIOAPI_API // GetUnicastIpAddressTable( ADDRESS_FAMILY Family, PMIB_UNICASTIPADDRESS_TABLE *Table ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "bdafc4a4-5f3c-4dd5-ba9b-4f6045a82652")] public static extern Win32Error GetUnicastIpAddressTable(ADDRESS_FAMILY Family, out MIB_UNICASTIPADDRESS_TABLE Table); /// /// The if_indextoname function converts the local index for a network interface to the ANSI interface name. /// /// /// The local index 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 this parameter must be equal to or greater than IF_NAMESIZE. /// /// /// /// /// On success, if_indextoname returns a pointer to NULL-terminated ANSI string containing the interface name. On /// failure, a NULL pointer is returned. /// /// /// /// The if_indextoname function is available on Windows Vista and later. /// /// The if_indextoname function maps an interface index into its corresponding name. This function is designed as part of /// basic socket extensions for IPv6 as described by the IETF in RFC 2553. For more information, see http://www.ietf.org/rfc/rfc2553.txt. /// /// /// The if_indextoname function is implemented for portability of applications with Unix environments, but the /// ConvertInterface functions are preferred. The if_indextoname function can be replaced by a call to the /// ConvertInterfaceIndexToLuid function to convert an interface index to a NET_LUID followed by a call to the /// ConvertInterfaceLuidToNameA to convert the NET_LUID to the ANSI interface name. /// /// If the if_indextoname fails and returns a NULL pointer, it is not possible to determine an error code. /// /// The length, in bytes, of the buffer pointed to by the InterfaceName parameter must be equal or greater than IF_NAMESIZE, a /// value declared in the Netioapi.h header file equal to NDIS_IF_MAX_STRING_SIZE. 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-if_indextoname NETIOAPI_API_ if_indextoname( NET_IFINDEX // InterfaceIndex, PCHAR InterfaceName ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "0da31819-3ee7-4474-9e68-f5a18d4a135a")] public static extern IntPtr if_indextoname(uint InterfaceIndex, [MarshalAs(UnmanagedType.LPStr)] StringBuilder InterfaceName); /// /// The if_nametoindex function converts the ANSI interface name for a network interface to the local index for the interface. /// /// A pointer to a NULL-terminated ANSI string containing the interface name. /// On success, if_nametoindex returns the local interface index. On failure, zero is returned. // NET_IFINDEX WINAPI if_nametoindex( _In_ PCSTR InterfaceName); https://msdn.microsoft.com/en-us/library/windows/desktop/bb408409(v=vs.85).aspx [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("Netioapi.h", MSDNShortId = "bb408409")] public static extern uint if_nametoindex([In, MarshalAs(UnmanagedType.LPStr)] string InterfaceName); /// /// /// The InitializeIpForwardEntry function initializes a MIB_IPFORWARD_ROW2 structure with default values for an IP /// route entry on the local computer. /// /// /// /// /// On entry, a pointer to a MIB_IPFORWARD_ROW2 structure entry for an IP route entry. On return, the MIB_IPFORWARD_ROW2 /// structure pointed to by this parameter is initialized with default values for an IP route entry. /// /// /// /// This function does not return a value. /// /// /// The InitializeIpForwardEntry function is defined on Windows Vista and later. /// /// The InitializeIpForwardEntry function must be used to initialize the members of a MIB_IPFORWARD_ROW2 structure entry with /// default values for an IP route entry for later use with the CreateIpForwardEntry2 function. /// /// On input, InitializeIpForwardEntry must be passed a new MIB_IPFORWARD_ROW2 structure to initialize. /// /// On output, the ValidLifetime and PreferredLifetime members of the MIB_IPFORWARD_ROW2 structure pointed to by Row /// parameter will be initialized to infinite and the Loopback, AutoconfigureAddress, Publish, and /// Immortal members will be initialized to TRUE. In addition, the SitePrefixLength, Metric, and /// Protocol members are set to an illegal value and other fields are initialized to zero. /// /// /// After calling InitializeIpForwardEntry, an application can then change the members in the MIB_IPFORWARD_ROW2 entry it /// wishes to modify, and then call the CreateIpForwardEntry2 to add the new IP route entry to the local computer. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-initializeipforwardentry VOID NETIOAPI_API_ // InitializeIpForwardEntry( PMIB_IPFORWARD_ROW2 Row ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "1968c4e5-4b28-4387-a918-3326bc80bb3e")] public static extern void InitializeIpForwardEntry(out MIB_IPFORWARD_ROW2 Row); /// /// The InitializeIpInterfaceEntry function initializes the members of an MIB_IPINTERFACE_ROW structure entry with /// default values. /// /// /// A pointer to a MIB_IPINTERFACE_ROW structure to initialize. On successful return, the fields in this parameter are /// initialized with default information for an interface on the local computer. /// /// /// InitializeIpInterfaceEntry returns STATUS_SUCCESS if the function succeeds. /// If the function fails, InitializeIpInterfaceEntry returns one of the following error codes: /// /// /// /// Return code /// Description /// /// /// STATUS_INVALID_PARAMETER /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter /// /// /// Other /// Use the FormatMessage function to obtain the message string for the returned error. /// /// /// /// // VOID NETIOAPI_API_ InitializeIpInterfaceEntry( _Inout_ PMIB_IPINTERFACE_ROW Row); https://msdn.microsoft.com/en-us/library/windows/hardware/ff554883(v=vs.85).aspx [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("Netioapi.h", MSDNShortId = "ff554883")] public static extern void InitializeIpInterfaceEntry(out MIB_IPINTERFACE_ROW Row); /// /// /// The InitializeUnicastIpAddressEntry function initializes a MIB_UNICASTIPADDRESS_ROW structure with default values /// for a unicast IP address entry on the local computer. /// /// /// /// /// On entry, a pointer to a MIB_UNICASTIPADDRESS_ROW structure entry for a unicast IP address entry. On return, the /// MIB_UNICASTIPADDRESS_ROW structure pointed to by this parameter is initialized with default values for a unicast IP address. /// /// /// /// This function does not return a value. /// /// /// The InitializeUnicastIpAddressEntry function is defined on Windows Vista and later. /// /// The InitializeUnicastIpAddressEntry function must be used to initialize the members of a MIB_UNICASTIPADDRESS_ROW /// structure entry with default values for a unicast IP address for later use with the CreateUnicastIpAddressEntry function. /// /// On input, InitializeUnicastIpAddressEntry must be passed a new MIB_UNICASTIPADDRESS_ROW structure to initialize. /// /// On output, the PrefixOrigin member of the MIB_UNICASTIPADDRESS_ROW structure pointed to by Row parameter the will be /// initialized to IpPrefixOriginUnchanged, the SuffixOrigin member will be initialized to /// IpSuffixOriginUnchanged, and the OnLinkPrefixLength member will be initialized to an illegal value. In addition, /// the PreferredLifetime and ValidLifetime members are set to infinite, the SkipAsSource member is set to /// FALSE, and other fields are initialized to zero. /// /// /// After calling InitializeUnicastIpAddressEntry, an application can then change the members in the MIB_UNICASTIPADDRESS_ROW /// entry it wishes to modify, and then call the CreateUnicastIpAddressEntry to add the new unicast IP address to the local computer. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-initializeunicastipaddressentry VOID NETIOAPI_API_ // InitializeUnicastIpAddressEntry( PMIB_UNICASTIPADDRESS_ROW Row ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "8cbdd972-060a-4e18-9490-450df21936ea")] public static extern void InitializeUnicastIpAddressEntry(out MIB_UNICASTIPADDRESS_ROW Row); /// /// /// The NotifyIpInterfaceChange function registers to be notified for changes to all IP interfaces, IPv4 interfaces, or IPv6 /// interfaces on a local computer. /// /// /// /// The address family on which to register for change notifications. /// /// 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 registers for both IPv4 and IPv6 change notifications. /// /// /// /// AF_INET 2 /// /// The Internet Protocol version 4 (IPv4) address family. When this parameter is specified, this function register for only IPv4 /// change notifications. /// /// /// /// AF_INET6 23 /// /// The Internet Protocol version 6 (IPv6) address family. When this parameter is specified, this function registers for only IPv6 /// change notifications. /// /// /// /// /// /// /// A pointer to the function to call when a change occurs. This function will be invoked when an interface notification is received. /// /// /// /// A user context passed to the callback function specified in the Callback parameter when an interface notification is received. /// /// /// /// A value that indicates whether the callback should be invoked immediately after registration for change notification completes. /// This initial notification does not indicate a change occurred to an IP interface. The purpose of this parameter to provide /// confirmation that the callback is registered. /// /// /// /// /// A pointer used to return a handle that can be later used to deregister the change notification. On success, a notification handle /// is returned in this parameter. If an error occurs, NULL is returned. /// /// /// /// 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_HANDLE /// An internal error occurred where an invalid handle was encountered. /// /// /// ERROR_INVALID_PARAMETER /// /// An invalid parameter was passed to the function. This error is returned if the Family parameter was not either AF_INET, AF_INET6, /// or AF_UNSPEC. /// /// /// /// ERROR_NOT_ENOUGH_MEMORY /// There was insufficient memory. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The NotifyIpInterfaceChange function is defined on Windows Vista and later. /// The Family parameter must be set to either AF_INET, AF_INET6, or AF_UNSPEC. /// /// The invocation of the callback function specified in the Callback parameter is serialized. The callback function should be /// defined as a function of type VOID. The parameters passed to the callback function include the following: /// /// /// /// Parameter /// Description /// /// /// IN PVOID CallerContext /// The CallerContext parameter passed to the NotifyIpInterfaceChange function when registering for notifications. /// /// /// IN PMIB_IPINTERFACE_ROW Row OPTIONAL /// /// A pointer to the MIB_IPINTERFACE_ROW entry for the interface that was changed. This parameter is a NULL pointer when the /// MIB_NOTIFICATION_TYPE value passed in the NotificationType parameter to the callback function is set to MibInitialNotification. /// This can only occur if the InitialNotification parameter passed to NotifyIpInterfaceChange was set to TRUE when registering for notifications. /// /// /// /// IN MIB_NOTIFICATION_TYPE NotificationType /// /// The notification type. This member can be one of the values from the MIB_NOTIFICATION_TYPE enumeration type defined in the /// Netioapi.h header file. /// /// /// /// /// The callback function specified in the Callback parameter must be implemented in the same process as the application calling the /// NotifyIpInterfaceChange function. If the callback function is in a separate DLL, then the DLL should be loaded before /// calling the NotifyIpInterfaceChange function to register for change notifications. /// /// /// When the callback function is received when a change occurs and the Row parameter is not NULL, the pointer to the /// MIB_IPINTERFACE_ROW structure passed in the Row parameter contains incomplete data. The information returned in the /// MIB_IPINTERFACE_ROW structure is only enough information that an application can call the GetIpInterfaceEntry function to /// query complete information on the IP interface that changed. When the callback function is received, an application should /// allocate a MIB_IPINTERFACE_ROW structure and initialize it with the Family, InterfaceLuid and /// InterfaceIndex members in the MIB_IPINTERFACE_ROW structure pointed to by the Row parameter received. A pointer to /// this newly initialized MIB_IPINTERFACE_ROW structure should be passed to the GetIpInterfaceEntry function to /// retrieve complete information on the IP interface that was changed. /// /// /// The memory pointed to by the Row parameter used in the callback indications is managed by the operating system. An application /// that receives a notification should never attempt to free the memory pointed to by the Row parameter. /// /// /// To deregister for change notifications, call the CancelMibChangeNotify2 function passing the NotificationHandle parameter /// returned by NotifyIpInterfaceChange. /// /// /// An application cannot make a call to the CancelMibChangeNotify2 function from the context of the thread which is currently /// executing the notification callback function for the same NotificationHandle parameter. Otherwise, the thread executing that /// callback will result in deadlock. So the CancelMibChangeNotify2 function must not be called directly as part of the /// notification callback routine. In a more general situation, a thread that executes the CancelMibChangeNotify2 function /// cannot own a resource on which the thread that executes a notification callback operation would wait because it would result in a /// similar deadlock. The CancelMibChangeNotify2 function should be called from a different thread, on which the thread that /// receives the notification callback doesn’t have dependencies on. /// /// /// Once the NotifyIpInterfaceChange function is called to register for change notifications, these notifications will /// continue to be sent until the application deregisters for change notifications or the application terminates. If the application /// terminates, the system will automatically deregister any registration for change notifications. It is still recommended that an /// application explicitly deregister for change notifications before it terminates. /// /// Any registration for change notifications does not persist across a system shut down or reboot. /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-notifyipinterfacechange _NETIOAPI_SUCCESS_ NETIOAPI_API // NotifyIpInterfaceChange( ADDRESS_FAMILY Family, PIPINTERFACE_CHANGE_CALLBACK Callback, PVOID CallerContext, BOOLEAN // InitialNotification, HANDLE *NotificationHandle ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "745128cf-7737-4f95-9712-26e0f6ae39b4")] public static extern Win32Error NotifyIpInterfaceChange(ADDRESS_FAMILY Family, PIPINTERFACE_CHANGE_CALLBACK Callback, [Optional] IntPtr CallerContext, [MarshalAs(UnmanagedType.U1)] bool InitialNotification, out IntPtr NotificationHandle); /// /// Registers an application-defined callback function, to be called when the aggregate network connectivity level and cost hints change. /// /// /// A function pointer of type PNETWORK_CONNECTIVITY_HINT_CHANGE_CALLBACK, which points to your application-defined callback /// function. The callback function will be invoked when a network connectivity level or cost change occurs. /// /// The user-specific caller context. This context will be supplied to the callback function. /// /// if an initialization notification should be provided, otherwise . /// /// /// A pointer to a HANDLE. The function sets the value to a handle to the notification registration. /// /// None // https://docs.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-notifynetworkconnectivityhintchange // IPHLPAPI_DLL_LINKAGE _NETIOAPI_SUCCESS_ NETIOAPI_API NotifyNetworkConnectivityHintChange( PNETWORK_CONNECTIVITY_HINT_CHANGE_CALLBACK Callback, PVOID CallerContext, BOOLEAN InitialNotification, PHANDLE NotificationHandle ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "NF:netioapi.NotifyNetworkConnectivityHintChange")] public static extern Win32Error NotifyNetworkConnectivityHintChange(PNETWORK_CONNECTIVITY_HINT_CHANGE_CALLBACK Callback, [In, Optional] IntPtr CallerContext, [MarshalAs(UnmanagedType.U1)] bool InitialNotification, out IntPtr NotificationHandle); /// /// The NotifyRouteChange2 function registers to be notified for changes to IP route entries on a local computer. /// /// /// The address family on which to register for change notifications. /// /// 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_INET /// Register for only IPv4 route change notifications. /// /// /// AF_INET6 /// Register for only IPv6 route change notifications. /// /// /// AF_UNSPEC /// Register for both IPv4 and IPv6 route change notifications. /// /// /// /// /// /// A pointer to the function to call when a change occurs. This function will be invoked when an IP route notification is received. /// /// /// /// A user context passed to the callback function specified in the Callback parameter when an interface notification is received. /// /// /// /// A value that indicates whether the callback should be invoked immediately after registration for change notification completes. /// This initial notification does not indicate a change occurred to an IP route entry. The purpose of this parameter to provide /// confirmation that the callback is registered. /// /// /// /// /// A pointer used to return a handle that can be later used to deregister the change notification. On success, a notification handle /// is returned in this parameter. If an error occurs, NULL is returned. /// /// /// /// 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_HANDLE /// An internal error occurred where an invalid handle was encountered. /// /// /// ERROR_INVALID_PARAMETER /// /// An invalid parameter was passed to the function. This error is returned if the Family parameter was not either AF_INET, AF_INET6, /// or AF_UNSPEC. /// /// /// /// ERROR_NOT_ENOUGH_MEMORY /// There was insufficient memory. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The NotifyRouteChange2 function is defined on Windows Vista and later. /// The Family parameter must be set to either AF_INET, AF_INET6, or AF_UNSPEC. /// /// The invocation of the callback function specified in the Callback parameter is serialized. The callback function should be /// defined as a function of type VOID. The parameters passed to the callback function include the following: /// /// /// /// Parameter /// Description /// /// /// IN PVOID CallerContext /// The CallerContext parameter passed to the NotifyRouteChange2 function when registering for notifications. /// /// /// IN PMIB_IPFORWARD_ROW2 Row OPTIONAL /// /// A pointer to the MIB_IPFORWARD_ROW2 entry for the IP route entry that was changed. This parameter is a NULL pointer when the /// MIB_NOTIFICATION_TYPE value passed in the NotificationType parameter to the callback function is set to MibInitialNotification. /// This can only occur if the InitialNotification parameter passed to NotifyRouteChange2 was set to TRUE when registering for notifications. /// /// /// /// IN MIB_NOTIFICATION_TYPE NotificationType /// /// The notification type. This member can be one of the values from the MIB_NOTIFICATION_TYPE enumeration type defined in the /// Netioapi.h header file. /// /// /// /// /// The callback function specified in the Callback parameter must be implemented in the same process as the application calling the /// NotifyRouteChange2 function. If the callback function is in a separate DLL, then the DLL should be loaded before calling /// the NotifyRouteChange2 function to register for change notifications. /// /// /// When the callback function is received when a change occurs and the Row parameter is not NULL, the pointer to the /// MIB_IPFORWARD_ROW2 structure passed in the Row parameter contains incomplete data. The information returned in the /// MIB_IPFORWARD_ROW2 structure is only enough information that an application can call the GetIpForwardEntry2 function to /// query complete information on the IP route that changed. When the callback function is received, an application should allocate a /// MIB_IPFORWARD_ROW2 structure and initialize it with the DestinationPrefix, NextHop, InterfaceLuid and /// InterfaceIndex members in the MIB_IPFORWARD_ROW2 structure pointed to by the Row parameter received. A pointer to /// this newly initialized MIB_IPFORWARD_ROW2 structure should be passed to the GetIpForwardEntry2 function to retrieve /// complete information on the IP route that was changed. /// /// /// The memory pointed to by the Row parameter used in the callback indications is managed by the operating system. An application /// that receives a notification should never attempt to free the memory pointed to by the Row parameter. /// /// /// Once the NotifyRouteChange2 function is called to register for change notifications, these notifications will continue to /// be sent until the application deregisters for change notifications or the application terminates. If the application terminates, /// the system will automatically deregister any registration for change notifications. It is still recommended that an application /// explicitly deregister for change notifications before it terminates. /// /// Any registration for change notifications does not persist if the system is shutdown or rebooted. /// /// To deregister for change notifications, call the CancelMibChangeNotify2 function passing the NotificationHandle parameter /// returned by NotifyRouteChange2. /// /// /// An application cannot make a call to the CancelMibChangeNotify2 function from the context of the thread which is currently /// executing the notification callback function for the same NotificationHandle parameter. Otherwise, the thread executing that /// callback will result in deadlock. So the CancelMibChangeNotify2 function must not be called directly as part of the /// notification callback routine. In a more general situation, a thread that executes the CancelMibChangeNotify2 function /// cannot own a resource on which the thread that executes a notification callback operation would wait because it would result in a /// similar deadlock. The CancelMibChangeNotify2 function should be called from a different thread, on which the thread that /// receives the notification callback doesn’t have dependencies on. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-notifyroutechange2 _NETIOAPI_SUCCESS_ NETIOAPI_API // NotifyRouteChange2( ADDRESS_FAMILY AddressFamily, PIPFORWARD_CHANGE_CALLBACK Callback, PVOID CallerContext, BOOLEAN // InitialNotification, HANDLE *NotificationHandle ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "f104dc0c-b3e0-4f22-ac5f-5dbf967be31b")] public static extern Win32Error NotifyRouteChange2(ADDRESS_FAMILY AddressFamily, PIPFORWARD_CHANGE_CALLBACK Callback, [Optional] IntPtr CallerContext, [MarshalAs(UnmanagedType.U1)] bool InitialNotification, out IntPtr NotificationHandle); /// /// The NotifyStableUnicastIpAddressTable function retrieves the stable unicast IP address table on a 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, the function retrieves the stable unicast 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, the function retrieves the stable /// unicast IP address table containing only IPv4 entries. /// /// /// /// AF_INET6 23 /// /// The Internet Protocol version 6 (IPv6) address family. When this parameter is specified, the function retrieves the stable /// unicast IP address table containing only IPv6 entries. /// /// /// /// /// /// /// A pointer to a MIB_UNICASTIPADDRESS_TABLE structure. When NotifyStableUnicastIpAddressTable is successful, this parameter /// returns the stable unicast IP address table on the local computer. /// /// /// When NotifyStableUnicastIpAddressTable returns ERROR_IO_PENDING indicating that the I/O request is pending, then /// the stable unicast IP address table is returned to the function in the CallerCallback parameter. /// /// /// /// /// A pointer to the function to call with the stable unicast IP address table. This function will be invoked if /// NotifyStableUnicastIpAddressTable returns ERROR_IO_PENDING, indicating that the I/O request is pending. /// /// /// /// /// A user context passed to the callback function specified in the CallerCallback parameter when the stable unicast IP address table /// is available. /// /// /// /// /// A pointer used to return a handle that can be used to cancel the request to retrieve the stable unicast IP address table. This /// parameter is returned if the return value from NotifyStableUnicastIpAddressTable is ERROR_IO_PENDING indicating /// that the I/O request is pending. /// /// /// /// /// If the function succeeds immediately, the return value is NO_ERROR and the stable unicast IP table is returned in the Table parameter. /// /// /// If the I/O request is pending, the function returns ERROR_IO_PENDING and the function pointed to by the CallerCallback /// parameter is called when the I/O request has completed with the stable unicast IP address table. /// /// If the function fails, the return value is one of the following error codes. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_HANDLE /// An internal error occurred where an invalid handle was encountered. /// /// /// ERROR_INVALID_PARAMETER /// /// An invalid parameter was passed to the function. This error is returned if the Table parameter was a NULL pointer, the /// NotificationHandle parameter was a NULL pointer, or the Family parameter was not either AF_INET, AF_INET6, or AF_UNSPEC. /// /// /// /// ERROR_NOT_ENOUGH_MEMORY /// There was insufficient memory. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The NotifyStableUnicastIpAddressTable function is defined on Windows Vista and later. /// /// If the NotifyStableUnicastIpAddressTable function succeeds immediately, the return value is NO_ERROR and the stable /// unicast IP table is returned in the Table parameter. The calling application should free the memory pointed to by the Table /// parameter using the FreeMibTable function when the MIB_UNICASTIPADDRESS_TABLE information is no longer needed. /// /// /// All unicast IP addresses except dial-on-demand addresses are considered stable only if they are in the preferred state. For a /// normal unicast IP address entry, this would correspond to a DadState member of the MIB_UNICASTIPADDRESS_ROW for the IP address /// set to IpDadStatePreferred. Every dial-on-demand address defines its own stability metric. Currently the only /// dial-on-demand address considered by this function is the unicast IP address used by the Teredo client on the local computer. /// /// The Family parameter must be set to either AF_INET, AF_INET6, or AF_UNSPEC. /// /// When NotifyStableUnicastIpAddressTable is successful and returns NO_ERROR, the Table parameter returns the stable unicast /// IP address table on the local computer. /// /// /// When NotifyStableUnicastIpAddressTable returns ERROR_IO_PENDING indicating that the I/O request is pending, then /// the stable unicast IP address table is returned to the function in the CallerCallback parameter. /// /// The NotifyStableUnicastIpAddressTable function is used primarily by applications that use the Teredo client. /// /// If the unicast IP address used by Teredo is available on the local computer but not in the stable (qualified) state, /// NotifyStableUnicastIpAddressTable returns ERROR_IO_PENDING and the stable unicast IP address table is eventually returned /// by calling the function in the CallerCallback parameter. If the Teredo address is not available or is in the stable state and the /// other unicast IP addresses are in a stable state, then the function in the CallerCallback parameter will never be invoked. /// /// /// The callback function specified in the CallerCallback parameter should be defined as a function of type VOID. The /// parameters passed to the callback function include the following: /// /// /// /// Parameter /// Description /// /// /// IN PVOID CallerContext /// The CallerContext parameter passed to the NotifyStableUnicastIpAddressTable function when registering for notifications. /// /// /// IN PMIB_UNICASTIPADDRESS_TABLE AddressTable /// A pointer to a MIB_UNICASTIPADDRESS_TABLE containing the stable unicast IP address table on the local computer. /// /// /// /// The callback function specified in the CallerCallback parameter must be implemented in the same process as the application /// calling the NotifyStableUnicastIpAddressTable function. If the callback function is in a separate DLL, then the DLL should /// be loaded before calling the NotifyStableUnicastIpAddressTable function to register for change notifications. /// /// /// The memory pointed to by the AddressTable parameter used in a callback indication is allocated by the operating system. An /// application that receives a notification should free the memory pointed to by the AddressTable parameter using the FreeMibTable /// function when the MIB_UNICASTIPADDRESS_TABLE information is no longer needed. /// /// /// Once the NotifyStableUnicastIpAddressTable function is called to register for change notifications, these notifications /// will continue to be sent until the application deregisters for change notifications or the application terminates. If the /// application terminates, the system will automatically deregister any registration for change notifications. It is still /// recommended that an application explicitly deregister any change notifications before it terminates. /// /// Any registration for change notifications does not persist if the system is shutdown or rebooted. /// /// To deregister for change notifications, call the CancelMibChangeNotify2 function passing the NotificationHandle parameter /// returned by NotifyStableUnicastIpAddressTable. /// /// /// An application cannot make a call to the CancelMibChangeNotify2 function from the context of the thread which is currently /// executing the notification callback function for the same NotificationHandle parameter. Otherwise, the thread executing that /// callback will result in deadlock. So the CancelMibChangeNotify2 function must not be called directly as part of the /// notification callback routine. In a more general situation, a thread that executes the CancelMibChangeNotify2 function /// cannot own a resource on which the thread that executes a notification callback operation would wait because it would result in a /// similar deadlock. The CancelMibChangeNotify2 function should be called from a different thread, on which the thread that /// receives the notification callback doesn’t have dependencies on. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-notifystableunicastipaddresstable _NETIOAPI_SUCCESS_ // NETIOAPI_API NotifyStableUnicastIpAddressTable( ADDRESS_FAMILY Family, PMIB_UNICASTIPADDRESS_TABLE *Table, // PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK CallerCallback, PVOID CallerContext, HANDLE *NotificationHandle ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "80d10088-79ef-41fd-add7-994d2a780ddb")] public static extern Win32Error NotifyStableUnicastIpAddressTable(ADDRESS_FAMILY Family, out IntPtr Table, PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK CallerCallback, [Optional] IntPtr CallerContext, out IntPtr NotificationHandle); /// /// /// The NotifyTeredoPortChange function registers to be notified for changes to the UDP port number used by the Teredo client /// for the Teredo service port on a local computer. /// /// /// /// /// A pointer to the function to call when a Teredo client port change occurs. This function will be invoked when a Teredo port /// change notification is received. /// /// /// /// /// A user context passed to the callback function specified in the Callback parameter when a Teredo port change notification is received. /// /// /// /// /// A value that indicates whether the callback should be invoked immediately after registration for change notification completes. /// This initial notification does not indicate a change occurred to the Teredo client port. The purpose of this parameter to provide /// confirmation that the callback is registered. /// /// /// /// /// A pointer used to return a handle that can be later used to deregister the change notification. On success, a notification handle /// is returned in this parameter. If an error occurs, NULL is returned. /// /// /// /// 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_HANDLE /// An internal error occurred where an invalid handle was encountered. /// /// /// ERROR_INVALID_PARAMETER /// An invalid parameter was passed to the function. This error is returned if the Callback parameter is a NULL pointer. /// /// /// ERROR_NOT_ENOUGH_MEMORY /// There was insufficient memory. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The NotifyTeredoPortChange function is defined on Windows Vista and later. /// /// The GetTeredoPort function can be used to retrieve the initial UDP port number used by the Teredo client for the Teredo service port. /// /// /// The Teredo port is dynamic and can change any time the Teredo client is restarted on the local computer. An application can /// register to be notified when the Teredo service port changes by calling the NotifyTeredoPortChange function. /// /// /// The invocation of the callback function specified in the Callback parameter is serialized. The callback function should be /// defined as a function of type VOID. The parameters passed to the callback function include the following: /// /// /// /// Parameter /// Description /// /// /// IN PVOID CallerContext /// The CallerContext parameter passed to the NotifyTeredoPortChange function when registering for notifications. /// /// /// IN USHORT Port /// /// The UDP port number currently used by the Teredo client. This parameter is zero when the MIB_NOTIFICATION_TYPE value passed in /// the NotificationType parameter to the callback function is set to MibInitialNotification. This can only occur if the /// InitialNotification parameter passed to NotifyTeredoPortChange was set to TRUE when registering for notifications. /// /// /// /// IN MIB_NOTIFICATION_TYPE NotificationType /// /// The notification type. This member can be one of the values from the MIB_NOTIFICATION_TYPE enumeration type defined in the /// Netioapi.h header file. /// /// /// /// /// The callback function specified in the Callback parameter must be implemented in the same process as the application calling the /// NotifyTeredoPortChange function. If the callback function is in a separate DLL, then the DLL should be loaded before /// calling the NotifyTeredoPortChange function to register for change notifications. /// /// /// Once the NotifyTeredoPortChange function is called to register for change notifications, these notifications will continue /// to be sent until the application deregisters for change notifications or the application terminates. If the application /// terminates, the system will automatically deregister any registration for change notifications. It is still recommended that an /// application explicitly deregister for change notifications before it terminates. /// /// Any registration for change notifications does not persist across a system shut down or reboot. /// /// To deregister for change notifications, call the CancelMibChangeNotify2 function passing the NotificationHandle parameter /// returned by NotifyTeredoPortChange. /// /// /// An application cannot make a call to the CancelMibChangeNotify2 function from the context of the thread which is currently /// executing the notification callback function for the same NotificationHandle parameter. Otherwise, the thread executing that /// callback will result in deadlock. So the CancelMibChangeNotify2 function must not be called directly as part of the /// notification callback routine. In a more general situation, a thread that executes the CancelMibChangeNotify2 function /// cannot own a resource on which the thread that executes a notification callback operation would wait because it would result in a /// similar deadlock. The CancelMibChangeNotify2 function should be called from a different thread, on which the thread that /// receives the notification callback doesn’t have dependencies on. /// /// /// The Teredo client also uses static UDP port 3544 for listening to multicast traffic sent on multicast IPv4 address 224.0.0.253 as /// defined in RFC 4380. For more information, see http://www.ietf.org/rfc/rfc4380.txt. /// /// /// The NotifyTeredoPortChange function is used primarily by firewall applications in order to configure the appropriate /// exceptions to allow incoming and outgoing Teredo traffic. /// /// The NotifyStableUnicastIpAddressTable function is used primarily by applications that use the Teredo client. /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-notifyteredoportchange _NETIOAPI_SUCCESS_ NETIOAPI_API // NotifyTeredoPortChange( PTEREDO_PORT_CHANGE_CALLBACK Callback, PVOID CallerContext, BOOLEAN InitialNotification, HANDLE // *NotificationHandle ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "c0c23531-7629-41c9-acf2-9d2f5e98e02c")] public static extern Win32Error NotifyTeredoPortChange(PTEREDO_PORT_CHANGE_CALLBACK Callback, [Optional] IntPtr CallerContext, [MarshalAs(UnmanagedType.U1)] bool InitialNotification, out IntPtr NotificationHandle); /// /// /// The NotifyUnicastIpAddressChange function registers to be notified for changes to all unicast IP interfaces, unicast IPv4 /// addresses, or unicast IPv6 addresses on a local computer. /// /// /// /// The address family on which to register for change notifications. /// /// 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_INET /// Register for only unicast IPv4 address change notifications. /// /// /// AF_INET6 /// Register for only unicast IPv6 address change notifications. /// /// /// AF_UNSPEC /// Register for both unicast IPv4 and IPv6 address change notifications. /// /// /// /// /// /// A pointer to the function to call when a change occurs. This function will be invoked when a unicast IP address notification is received. /// /// /// /// A user context passed to the callback function specified in the Callback parameter when an interface notification is received. /// /// /// /// A value that indicates whether the callback should be invoked immediately after registration for change notification completes. /// This initial notification does not indicate a change occurred to a unicast IP address. The purpose of this parameter to provide /// confirmation that the callback is registered. /// /// /// /// /// A pointer used to return a handle that can be later used to deregister the change notification. On success, a notification handle /// is returned in this parameter. If an error occurs, NULL is returned. /// /// /// /// 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_HANDLE /// An internal error occurred where an invalid handle was encountered. /// /// /// ERROR_INVALID_PARAMETER /// /// An invalid parameter was passed to the function. This error is returned if the Family parameter was not either AF_INET, AF_INET6, /// or AF_UNSPEC. /// /// /// /// ERROR_NOT_ENOUGH_MEMORY /// There was insufficient memory. /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The NotifyUnicastIpAddressChange function is defined on Windows Vista and later. /// The Family parameter must be set to either AF_INET, AF_INET6, or AF_UNSPEC. /// /// The invocation of the callback function specified in the Callback parameter is serialized. The callback function should be /// defined as a function of type VOID. The parameters passed to the callback function include the following: /// /// /// /// Parameter /// Description /// /// /// IN PVOID CallerContext /// The CallerContext parameter passed to the NotifyUnicastIpAddressChange function when registering for notifications. /// /// /// IN PMIB_UNICASTIPADDRESS_ROW Row OPTIONAL /// /// A pointer to the MIB_UNICASTIPADDRESS_ROW entry for the unicast IP address that was changed. This parameter is a NULL pointer /// when the MIB_NOTIFICATION_TYPE value passed in the NotificationType parameter to the callback function is set to /// MibInitialNotification. This can only occur if the InitialNotification parameter passed to NotifyUnicastIpAddressChange was set /// to TRUE when registering for notifications. /// /// /// /// IN MIB_NOTIFICATION_TYPE NotificationType /// /// The notification type. This member can be one of the values from the MIB_NOTIFICATION_TYPE enumeration type defined in the /// Netioapi.h header file. /// /// /// /// /// The callback function specified in the Callback parameter must be implemented in the same process as the application calling the /// NotifyUnicastIpAddressChange function. If the callback function is in a separate DLL, then the DLL should be loaded before /// calling the NotifyUnicastIpAddressChange function to register for change notifications. /// /// /// When the callback function is received when a change occurs and the Row parameter is not NULL, the pointer to the /// MIB_UNICASTIPADDRESS_ROW structure passed in the Row parameter contains incomplete data. The information returned in the /// MIB_UNICASTIPADDRESS_ROW structure is only enough information that an application can call the GetUnicastIpAddressEntry /// function to query complete information on the IP address that changed. When the callback function is received, an application /// should allocate a MIB_UNICASTIPADDRESS_ROW structure and initialize it with the Address, InterfaceLuid and /// InterfaceIndex members in the MIB_UNICASTIPADDRESS_ROW structure pointed to by the Row parameter received. A /// pointer to this newly initialized MIB_UNICASTIPADDRESS_ROW structure should be passed to the /// GetUnicastIpAddressEntry function to retrieve complete information on the unicast IP address that was changed. /// /// /// The memory pointed to by the Row parameter used in the callback indications is managed by the operating system. An application /// that receives a notification should never attempt to free the memory pointed to by the Row parameter. /// /// /// Once the NotifyUnicastIpAddressChange function is called to register for change notifications, these notifications will /// continue to be sent until the application deregisters for change notifications or the application terminates. If the application /// terminates, the system will automatically deregister any registration for change notifications. It is still recommended that an /// application explicitly deregister for change notifications before it terminates. /// /// Any registration for change notifications does not persist if the system is shutdown or rebooted. /// /// To deregister for change notifications, call the CancelMibChangeNotify2 function passing the NotificationHandle parameter /// returned by NotifyUnicastIpAddressChange. /// /// /// An application cannot make a call to the CancelMibChangeNotify2 function from the context of the thread which is currently /// executing the notification callback function for the same NotificationHandle parameter. Otherwise, the thread executing that /// callback will result in deadlock. So the CancelMibChangeNotify2 function must not be called directly as part of the /// notification callback routine. In a more general situation, a thread that executes the CancelMibChangeNotify2 function /// cannot own a resource on which the thread that executes a notification callback operation would wait because it would result in a /// similar deadlock. The CancelMibChangeNotify2 function should be called from a different thread, on which the thread that /// receives the notification callback doesn’t have dependencies on. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-notifyunicastipaddresschange _NETIOAPI_SUCCESS_ // NETIOAPI_API NotifyUnicastIpAddressChange( ADDRESS_FAMILY Family, PUNICAST_IPADDRESS_CHANGE_CALLBACK Callback, PVOID // CallerContext, BOOLEAN InitialNotification, HANDLE *NotificationHandle ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "56945aa2-ca1e-44b3-9765-d862978a9dbe")] public static extern Win32Error NotifyUnicastIpAddressChange(ADDRESS_FAMILY Family, PUNICAST_IPADDRESS_CHANGE_CALLBACK Callback, [Optional] IntPtr CallerContext, [MarshalAs(UnmanagedType.U1)] bool InitialNotification, out IntPtr NotificationHandle); /// /// 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); /// /// 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, in SOCKADDR_INET SourceAddress); /// /// Reserved for future use. Do not use this function. /// /// /// Reserved. /// /// /// None /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-setcurrentthreadcompartmentid _NETIOAPI_SUCCESS_ // NETIOAPI_API SetCurrentThreadCompartmentId( NET_IF_COMPARTMENT_ID CompartmentId ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "15c634b5-c621-430d-99d7-c55ad8b6864e")] public static extern Win32Error SetCurrentThreadCompartmentId(uint CompartmentId); /// /// The SetIpForwardEntry2 function sets the properties of an IP route entry on the local computer. /// /// /// /// A pointer to a MIB_IPFORWARD_ROW2 structure entry for an IP route entry. The DestinationPrefix member of the /// MIB_IPFORWARD_ROW2 must be set to a valid IP destination prefix, the NextHop member of the /// MIB_IPFORWARD_ROW2 must be set to a valid IP address family and IP address, and the InterfaceLuid or the /// InterfaceIndex member of the MIB_IPFORWARD_ROW2 must be specified. /// /// /// /// 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 Route parameter, the /// DestinationPrefix member of the MIB_IPFORWARD_ROW2 pointed to by the Route parameter was not specified, the NextHop member of the /// MIB_IPFORWARD_ROW2 pointed to by the Route parameter was not specified, or both the InterfaceLuid or InterfaceIndex members of /// the MIB_IPFORWARD_ROW2 pointed to by the Route 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 Route parameter could not be found. /// /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The SetIpForwardEntry2 function is defined on Windows Vista and later. /// The SetIpForwardEntry2 function is used to set the properties for an existing IP route entry on a local computer. /// /// The DestinationPrefix member in the MIB_IPFORWARD_ROW2 structure pointed to by the Route parameter must be initialized to /// a valid IP address prefix and family. The NextHop member in the MIB_IPFORWARD_ROW2 structure pointed to by the /// Route parameter must be initialized to a valid IP address and family. In addition, at least one of the following members in the /// MIB_IPFORWARD_ROW2 structure pointed to the Route 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 Route 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 /// SetIpForwardEntry2 function is called. These members are set by the network stack and cannot be changed using the /// SetIpForwardEntry2 function. /// /// /// The SetIpForwardEntry2 function will fail if the DestinationPrefix and NextHop members of the /// MIB_IPFORWARD_ROW2 pointed to by the Route parameter do not match an IP route entry on the interface specified. /// /// /// The SetIpForwardEntry2 function can only be called by a user logged on as a member of the Administrators group. If /// SetIpForwardEntry2 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 SetIpForwardEntry2 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-setipforwardentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API // SetIpForwardEntry2( CONST MIB_IPFORWARD_ROW2 *Route ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "e11aab0b-6d6c-4e90-a60a-f7d68c09751b")] public static extern Win32Error SetIpForwardEntry2(in MIB_IPFORWARD_ROW2 Route); /// /// The SetIpInterfaceEntry function sets the properties of an IP interface on the local computer. /// /// /// /// A pointer to a MIB_IPINTERFACE_ROW structure entry for an interface. On input, the Family member of the /// MIB_IPINTERFACE_ROW must be set to AF_INET6 or AF_INET and the InterfaceLuid or the /// InterfaceIndex member of the MIB_IPINTERFACE_ROW must be specified. On a successful return, the /// InterfaceLuid member of the MIB_IPINTERFACE_ROW is filled in if InterfaceIndex member of the /// MIB_IPINTERFACE_ROW entry was specified. /// /// /// /// 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_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_IPINTERFACE_ROW 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 /// Family member of the MIB_IPINTERFACE_ROW pointed to by the Row parameter was not specified as AF_INET or AF_INET6, or both the /// InterfaceLuid or InterfaceIndex members of the MIB_IPINTERFACE_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_IPINTERFACE_ROW pointed to by the Row parameter does not match the IP address family specified /// in the Family member in the MIB_IPINTERFACE_ROW structure. /// /// /// /// Other /// Use FormatMessage to obtain the message string for the returned error. /// /// /// /// /// The SetIpInterfaceEntry function is defined on Windows Vista and later. /// The SetIpInterfaceEntry function can is used to modify an existing IP interface entry. /// /// On input, the Family member in the MIB_IPINTERFACE_ROW structure pointed to by the Row parameter must be initialized to /// either AF_INET or AF_INET6. In addition on input, at least one of the following members in the /// MIB_IPINTERFACE_ROW structure pointed to the Row parameter must be initialized: the InterfaceLuid or InterfaceIndex. /// /// /// On output, the InterfaceLuid member of the MIB_IPINTERFACE_ROW structure pointed to by the Row parameter is filled in if /// the InterfaceIndex was specified. /// /// /// The MaxReassemblySize, MinRouterAdvertisementInterval, MaxRouterAdvertisementInterval, Connected, /// SupportsWakeUpPatterns, SupportsNeighborDiscovery, SupportsRouterDiscovery, ReachableTime, /// TransmitOffload, and ReceiveOffload members of the MIB_IPINTERFACE_ROW structure pointed to by the Row are ignored /// when the SetIpInterfaceEntry function is called. These members are set by the network stack and cannot be changed using /// the SetIpInterfaceEntry function. /// /// /// An application would typically call the GetIpInterfaceTable function to retrieve the IP interface entries on the local computer /// or call the GetIpInterfaceEntry function to retrieve just the IP interface entry to modify. The MIB_IPINTERFACE_ROW structure for /// the specific IP interface entry could then be modified and a pointer to this structure passed to the SetIpInterfaceEntry /// function in the Row parameter. However for IPv4, an application must not try to modify the SitePrefixLength member of the /// MIB_IPINTERFACE_ROW structure. For IPv4, the SitePrefixLength member must be set to 0. /// /// /// Another possible method to modify an existing IP interface entry is to use InitializeIpInterfaceEntry function to initialize the /// fields of a MIB_IPINTERFACE_ROW structure entry with default values. Then set the Family member and either the /// InterfaceIndex or InterfaceLuid members in the MIB_IPINTERFACE_ROW structure pointed to by the Row parameter /// to match the IP interface to change. An application can then change the fields in the MIB_IPINTERFACE_ROW entry it wishes /// to modify, and then call the SetIpInterfaceEntry function. However for IPv4, an application must not try to modify the /// SitePrefixLength member of the MIB_IPINTERFACE_ROW structure. For IPv4, the SitePrefixLength member must be /// set to 0. Caution must be used with this approach because the only way to determine all of the fields being changed would be to /// compare the fields in the MIB_IPINTERFACE_ROW of the specific IP interface entry with fields set by the /// InitializeIpInterfaceEntry function when a MIB_IPINTERFACE_ROW is initialized to default values. /// /// /// Unprivileged simultaneous access to multiple networks of different security requirements creates a security hole and allows an /// unprivileged application to accidentally relay data between the two networks. A typical example is simultaneous access to a /// virtual private network (VPN) and the Internet. Windows Server 2003 and Windows XP use a weak host model, where RAS prevents such /// simultaneous access by increasing the route metric of all default routes over other interfaces. Thus all traffic is routed /// through the VPN interface, disrupting other network connectivity. /// /// /// On Windows Vista and later, a strong host model is used by default. If a source IP address is specified in the route lookup using /// GetBestRoute2 or GetBestRoute, the route lookup is restricted to the interface of the source IP address. The route metric /// modification by RAS has no effect as the list of potential routes does not even have the route for the VPN interface thereby /// allowing traffic to the Internet. The DisableDefaultRoutes member of the MIB_IPINTERFACE_ROW can be used to disable using /// the default route on an interface. This member can be used as a security measure by VPN clients to restrict split tunneling when /// split tunneling is not required by the VPN client. A VPN client can call the SetIpInterfaceEntry function to set the /// DisableDefaultRoutes member to TRUE when required. A VPN client can query the current state of the /// DisableDefaultRoutes member by calling the GetIpInterfaceEntry function. /// /// The /// /// The SetIpInterfaceEntry function can only be called by a user logged on as a member of the Administrators group. If /// SetIpInterfaceEntry 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-setipinterfaceentry _NETIOAPI_SUCCESS_ NETIOAPI_API // SetIpInterfaceEntry( PMIB_IPINTERFACE_ROW Row ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "8e6d2c14-29c3-47a7-9eb8-0989df9da68c")] public static extern Win32Error SetIpInterfaceEntry(in MIB_IPINTERFACE_ROW Row); /// /// 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(in MIB_IPNET_ROW2 Row); /// /// Reserved for future use. Do not use this function. /// /// /// Reserved. /// /// /// Reserved. /// /// /// Reserved. /// /// /// None /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-setnetworkinformation _NETIOAPI_SUCCESS_ NETIOAPI_API // SetNetworkInformation( CONST NET_IF_NETWORK_GUID *NetworkGuid, NET_IF_COMPARTMENT_ID CompartmentId, CONST WCHAR *NetworkName ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "e196e978-2eb7-4b22-af3b-e14736c5ac94")] public static extern Win32Error SetNetworkInformation(in Guid NetworkGuid, uint CompartmentId, [MarshalAs(UnmanagedType.LPWStr)] string NetworkName); /// /// Reserved for future use. Do not use this function. /// /// /// Reserved. /// /// /// Reserved. /// /// /// None /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-setsessioncompartmentid _NETIOAPI_SUCCESS_ NETIOAPI_API // SetSessionCompartmentId( ULONG SessionId, NET_IF_COMPARTMENT_ID CompartmentId ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "d8192a40-0122-44cd-87a8-3999204322b4")] public static extern Win32Error SetSessionCompartmentId(uint SessionId, uint CompartmentId); /// /// The SetUnicastIpAddressEntry function sets the properties of an existing unicast IP address entry on the local computer. /// /// /// A pointer to a MIB_UNICASTIPADDRESS_ROW structure entry for an existing 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 or 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 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 an unicast IPv4 address or 128 for an 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 MIB_UNICASTIPADDRESS_ROW 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 SetUnicastIpAddressEntry function is defined on Windows Vista and later. /// /// The GetUnicastIpAddressEntry function is normally used to retrieve an existing MIB_UNICASTIPADDRESS_ROW structure entry to be /// modified. An application can then change the members in the MIB_UNICASTIPADDRESS_ROW entry it wishes to modify, and then /// call the SetUnicastIpAddressEntry function. /// /// /// An application may call the InitializeUnicastIpAddressEntry function to initialize the members of a MIB_UNICASTIPADDRESS_ROW /// structure entry with default values before making changes. However, the application would normally save either the /// InterfaceLuid or InterfaceIndex member before calling InitializeUnicastIpAddressEntry and restore one of /// these members after the call. /// /// /// 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 and family. In addition, at least one of the following members in the /// MIB_UNICASTIPADDRESS_ROW structure pointed to the Row parameter must be initialized: the InterfaceLuid or InterfaceIndex. /// /// /// If the OnLinkPrefixLength member of the MIB_UNICASTIPADDRESS_ROW pointed to by the Row parameter is set to 255, then /// SetUnicastIpAddressEntry will set the unicast IP address properties so that the OnLinkPrefixLength member is 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 SetUnicastIpAddressEntry. /// /// /// The DadState, ScopeId, and CreationTimeStamp members of the MIB_UNICASTIPADDRESS_ROW structure pointed to by /// the Row are ignored when the SetUnicastIpAddressEntry function is called. These members are set by the network stack and cannot /// be changed using the SetUnicastIpAddressEntry function. The ScopeId member is automatically determined by the /// interface on which the address was added. /// /// /// The SetUnicastIpAddressEntry function can only be called by a user logged on as a member of the Administrators group. If /// SetUnicastIpAddressEntry 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 SetUnicastIpAddressEntry 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-setunicastipaddressentry _NETIOAPI_SUCCESS_ NETIOAPI_API // SetUnicastIpAddressEntry( CONST MIB_UNICASTIPADDRESS_ROW *Row ); [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] [PInvokeData("netioapi.h", MSDNShortId = "906a3895-2e42-4bed-90a3-7c10487d76cb")] public static extern Win32Error SetUnicastIpAddressEntry(in MIB_UNICASTIPADDRESS_ROW Row); /// /// The IP_ADDRESS_PREFIX structure stores an IP address prefix. /// /// /// The IP_ADDRESS_PREFIX structure is defined on Windows Vista and later. /// /// The IP_ADDRESS_PREFIX structure is the data type of the DestinationPrefix member in the MIB_IPFORWARD_ROW2 /// structure. A number of functions use the MIB_IPFORWARD_ROW2 structure including CreateIpForwardEntry2, /// DeleteIpForwardEntry2, GetBestRoute2, GetIpForwardEntry2, GetIpForwardTable2, InitializeIpForwardEntry, NotifyRouteChange2, and SetIpForwardEntry2. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/ns-netioapi-_ip_address_prefix typedef struct _IP_ADDRESS_PREFIX { // SOCKADDR_INET Prefix; UINT8 PrefixLength; } IP_ADDRESS_PREFIX, *PIP_ADDRESS_PREFIX; [PInvokeData("netioapi.h", MSDNShortId = "3a6598d8-77e4-46f7-9397-124157508207")] [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 32)] public struct IP_ADDRESS_PREFIX : IEquatable { /// /// The prefix or network part of IP the address represented as an IP address. /// The SOCKADDR_INET union is defined in the Ws2ipdef.h header. /// public SOCKADDR_INET Prefix; /// /// 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 PrefixLength; /// Initializes a new instance of the struct. /// The prefix or network part of IP the address represented as an IP address. /// The length, in bits, of the prefix or network part of the IP address. public IP_ADDRESS_PREFIX(SOCKADDR_INET prefix, byte prefixLength) { Prefix = prefix; PrefixLength = prefixLength; } /// Determines whether the specified value is equal to this instance. /// The value to compare with this instance. /// if the specified value is equal to this instance; otherwise, . public bool Equals(IP_ADDRESS_PREFIX other) => Prefix.Equals(other.Prefix) && PrefixLength == other.PrefixLength; } /// /// 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, Pack = 8)] public struct MIB_ANYCASTIPADDRESS_ROW : IEquatable { /// 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; /// Initializes a new instance of the struct. /// The ipv4 address. /// The interface luid. public MIB_ANYCASTIPADDRESS_ROW(SOCKADDR_IN ipv4, NET_LUID interfaceLuid) : this() { Address.Ipv4 = ipv4; InterfaceLuid = interfaceLuid; } /// Initializes a new instance of the struct. /// The ipv4 address. /// Index of the interface. public MIB_ANYCASTIPADDRESS_ROW(SOCKADDR_IN ipv4, uint interfaceIndex) : this() { Address.Ipv4 = ipv4; InterfaceIndex = interfaceIndex; } /// Initializes a new instance of the struct. /// The ipv6 address. /// The interface luid. public MIB_ANYCASTIPADDRESS_ROW(SOCKADDR_IN6 ipv6, NET_LUID interfaceLuid) : this() { Address.Ipv6 = ipv6; InterfaceLuid = interfaceLuid; } /// Initializes a new instance of the struct. /// The ipv6 address. /// Index of the interface. public MIB_ANYCASTIPADDRESS_ROW(SOCKADDR_IN6 ipv6, uint interfaceIndex) : this() { Address.Ipv6 = ipv6; InterfaceIndex = interfaceIndex; } /// Determines whether the specified value is equal to this instance. /// The value to compare with this instance. /// if the specified value is equal to this instance; otherwise, . public bool Equals(MIB_ANYCASTIPADDRESS_ROW other) => Address.Equals(other.Address) && (InterfaceLuid.Value == other.InterfaceLuid.Value || InterfaceIndex == other.InterfaceIndex); } /// /// 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_IFSTACK_ROW structure represents the relationship between two network interfaces. // typedef struct _MIB_IFSTACK_ROW { NET_IFINDEX HigherLayerInterfaceIndex; NET_IFINDEX LowerLayerInterfaceIndex;} MIB_IFSTACK_ROW, // *PMIB_IFSTACK_ROW; https://msdn.microsoft.com/en-us/library/windows/hardware/ff559207(v=vs.85).aspx [PInvokeData("Netioapi.h", MSDNShortId = "ff559207")] [StructLayout(LayoutKind.Sequential)] public struct MIB_IFSTACK_ROW { /// The network interface index for the interface that is higher in the interface stack table. public uint HigherLayerInterfaceIndex; /// The network interface index for the interface that is lower in the interface stack table. public uint LowerLayerInterfaceIndex; } /// The MIB_INVERTEDIFSTACK_ROW structure represents the relationship between two network interfaces. // typedef struct _MIB_INVERTEDIFSTACK_ROW { NET_IFINDEX LowerLayerInterfaceIndex; NET_IFINDEX HigherLayerInterfaceIndex;} // MIB_INVERTEDIFSTACK_ROW, *PMIB_INVERTEDIFSTACK_ROW; https://msdn.microsoft.com/en-us/library/windows/hardware/ff559234(v=vs.85).aspx [PInvokeData("Netioapi.h", MSDNShortId = "ff559234")] [StructLayout(LayoutKind.Sequential)] public struct MIB_INVERTEDIFSTACK_ROW { /// The network interface index for the interface that is lower in the interface stack table. public uint LowerLayerInterfaceIndex; /// The network interface index for the interface that is higher in the interface stack table. public uint HigherLayerInterfaceIndex; } /// /// /// The MIB_IP_NETWORK_CONNECTION_BANDWIDTH_ESTIMATES structure contains read-only information for the bandwidth estimates /// computed by the TCP/IP stack for a network connection. /// /// /// /// /// The MIB_IP_NETWORK_CONNECTION_BANDWIDTH_ESTIMATES structure provides bandwidth estimates computed by the TCP/IP stack for /// a network connection. These bandwidth estimates are for the point of attachment of the host system to the underlying IP network. /// /// /// The MIB_IP_NETWORK_CONNECTION_BANDWIDTH_ESTIMATES structure is used with the GetIpNetworkConnectionBandwidthEstimates /// function to return bandwidth estimates obtained for the point of attachment to the IP network. It is possible to have asymmetric /// deployments and network conditions where the estimates observed inbound and outbound differ from each other. /// /// /// The MIB_IP_NETWORK_CONNECTION_BANDWIDTH_ESTIMATES structure is defined in the Netioapi.h header file which 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_ip_network_connection_bandwidth_estimates typedef // struct _MIB_IP_NETWORK_CONNECTION_BANDWIDTH_ESTIMATES { NL_BANDWIDTH_INFORMATION InboundBandwidthInformation; // NL_BANDWIDTH_INFORMATION OutboundBandwidthInformation; } MIB_IP_NETWORK_CONNECTION_BANDWIDTH_ESTIMATES, *PMIB_IP_NETWORK_CONNECTION_BANDWIDTH_ESTIMATES; [PInvokeData("netioapi.h", MSDNShortId = "E3109F71-E103-4586-9274-B83C4DC22382")] [StructLayout(LayoutKind.Sequential)] public struct MIB_IP_NETWORK_CONNECTION_BANDWIDTH_ESTIMATES { /// /// Bandwidth estimates for the data being received by the host from the IP network. /// public NL_BANDWIDTH_INFORMATION InboundBandwidthInformation; /// /// Bandwidth estimates for the data being sent from the host to the IP network. /// public NL_BANDWIDTH_INFORMATION OutboundBandwidthInformation; } /// /// 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 = 8)] public struct MIB_IPFORWARD_ROW2 : IEquatable { /// /// 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 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_IPFORWARD_PROTO Protocol; /// /// Type: BOOLEAN /// A value that specifies if the route is a loopback route (the gateway is on the local host). /// [MarshalAs(UnmanagedType.U1)] public bool Loopback; /// /// Type: BOOLEAN /// A value that specifies if the IP address is auto-configured. /// [MarshalAs(UnmanagedType.U1)] public bool AutoconfigureAddress; /// /// Type: BOOLEAN /// A value that specifies if the route is published. /// [MarshalAs(UnmanagedType.U1)] public bool Publish; /// /// Type: BOOLEAN /// A value that specifies if the route is immortal. /// [MarshalAs(UnmanagedType.U1)] public bool 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; /// Initializes a new instance of the struct. /// The destination prefix. /// The next hop. /// The interface luid. public MIB_IPFORWARD_ROW2(IP_ADDRESS_PREFIX destinationPrefix, SOCKADDR_INET nextHop, NET_LUID interfaceLuid) : this() { InitializeIpForwardEntry(out this); DestinationPrefix = destinationPrefix; NextHop = nextHop; InterfaceLuid = interfaceLuid; } /// Initializes a new instance of the struct. /// The destination prefix. /// The next hop. /// Index of the interface. public MIB_IPFORWARD_ROW2(IP_ADDRESS_PREFIX destinationPrefix, SOCKADDR_INET nextHop, uint interfaceIndex) : this() { InitializeIpForwardEntry(out this); DestinationPrefix = destinationPrefix; NextHop = nextHop; InterfaceIndex = interfaceIndex; } /// Determines whether the specified value is equal to this instance. /// The value to compare with this instance. /// if the specified value is equal to this instance; otherwise, . public bool Equals(MIB_IPFORWARD_ROW2 other) => DestinationPrefix.Equals(other.DestinationPrefix) && NextHop.Equals(other.NextHop) && (InterfaceLuid.Value == other.InterfaceLuid.Value || InterfaceIndex == other.InterfaceIndex); } /// /// The MIB_IPINTERFACE_ROW structure stores interface management information for a particular IP address family on a network interface. /// // typedef struct _MIB_IPINTERFACE_ROW { ADDRESS_FAMILY Family; NET_LUID InterfaceLuid; NET_IFINDEX InterfaceIndex; ULONG // MaxReassemblySize; ULONG64 InterfaceIdentifier; ULONG MinRouterAdvertisementInterval; ULONG MaxRouterAdvertisementInterval; // BOOLEAN AdvertisingEnabled; BOOLEAN ForwardingEnabled; BOOLEAN WeakHostSend; BOOLEAN WeakHostReceive; BOOLEAN UseAutomaticMetric; // BOOLEAN UseNeighborUnreachabilityDetection; BOOLEAN ManagedAddressConfigurationSupported; BOOLEAN // OtherStatefulConfigurationSupported; BOOLEAN AdvertiseDefaultRoute; NL_ROUTER_DISCOVERY_BEHAVIOR RouterDiscoveryBehavior; ULONG // DadTransmits; ULONG BaseReachableTime; ULONG RetransmitTime; ULONG PathMtuDiscoveryTimeout; NL_LINK_LOCAL_ADDRESS_BEHAVIOR // LinkLocalAddressBehavior; ULONG LinkLocalAddressTimeout; ULONG ZoneIndices[ScopeLevelCount]; ULONG SitePrefixLength; ULONG Metric; // ULONG NlMtu; BOOLEAN Connected; BOOLEAN SupportsWakeUpPatterns; BOOLEAN SupportsNeighborDiscovery; BOOLEAN // SupportsRouterDiscovery; ULONG ReachableTime; NL_INTERFACE_OFFLOAD_ROD TransmitOffload; NL_INTERFACE_OFFLOAD_ROD ReceiveOffload; // BOOLEAN DisableDefaultRoutes;} MIB_IPINTERFACE_ROW, *PMIB_IPINTERFACE_ROW; https://msdn.microsoft.com/en-us/library/windows/hardware/ff559254(v=vs.85).aspx [PInvokeData("Netioapi.h", MSDNShortId = "ff559254")] [StructLayout(LayoutKind.Sequential)]//, Pack = 8)] public struct MIB_IPINTERFACE_ROW : IEquatable { //[MarshalAs(UnmanagedType.ByValArray, SizeConst = 168)] public byte[] bytes; /// /// /// The address family. 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 you can use /// either constant. /// /// /// On Windows Vista and later versions of the Windows operating systems, possible values for this member are defined in the /// Ws2def.h header file. Note that the Ws2def.h header file is automatically included in Netioapi.h and you should never use /// Ws2def.h directly. /// /// The following values are currently supported: /// public ADDRESS_FAMILY Family; /// The locally unique identifier (LUID) for the network interface. public NET_LUID InterfaceLuid; /// /// The local index value for the network interface. This index value might change when a network adapter is disabled and then /// enabled, or under other circumstances, and should not be considered persistent. /// public uint InterfaceIndex; /// /// The maximum reassembly size, in bytes, of a fragmented IP packet. This member is currently set to zero and reserved for /// future use. /// public uint MaxReassemblySize; /// Reserved for future use. This member is currently set to zero. public ulong InterfaceIdentifier; /// /// The minimum router advertisement interval, in milliseconds, on this IP interface. This member defaults to 200 for IPv6. This /// member is applicable only if the AdvertisingEnabled member is set to TRUE. /// public uint MinRouterAdvertisementInterval; /// /// The maximum router advertisement interval, in milliseconds, on this IP interface. This member defaults to 600 for IPv6. This /// member is applicable only if the AdvertisingEnabled member is set to TRUE. /// public uint MaxRouterAdvertisementInterval; /// /// A value that indicates if router advertising is enabled on this IP interface. The default for IPv6 is that router /// advertisement is enabled only if the interface is configured to act as a router. The default for IPv4 is that router /// advertisement is disabled. /// [MarshalAs(UnmanagedType.U1)] public bool AdvertisingEnabled; /// A value that indicates if IP forwarding is enabled on this IP interface. [MarshalAs(UnmanagedType.U1)] public bool ForwardingEnabled; /// A value that indicates if weak host send mode is enabled on this IP interface. [MarshalAs(UnmanagedType.U1)] public bool WeakHostSend; /// A value that indicates if weak host receive mode is enabled on this IP interface. [MarshalAs(UnmanagedType.U1)] public bool WeakHostReceive; /// A value that indicates if the IP interface uses automatic metric. [MarshalAs(UnmanagedType.U1)] public bool UseAutomaticMetric; /// A value that indicates if neighbor unreachability detection is enabled on this IP interface. [MarshalAs(UnmanagedType.U1)] public bool UseNeighborUnreachabilityDetection; /// A value that indicates if the IP interface supports managed address configuration by using DHCP. [MarshalAs(UnmanagedType.U1)] public bool ManagedAddressConfigurationSupported; /// A value that indicates if the IP interface supports other stateful configuration (for example, route configuration). [MarshalAs(UnmanagedType.U1)] public bool OtherStatefulConfigurationSupported; /// /// A value that indicates if the IP interface advertises the default route. This member is applicable only if the /// AdvertisingEnabled member is set to TRUE. /// [MarshalAs(UnmanagedType.U1)] public bool AdvertiseDefaultRoute; /// An NL_ROUTER_DISCOVERY_BEHAVIOR router discovery behavior type. public NL_ROUTER_DISCOVERY_BEHAVIOR RouterDiscoveryBehavior; /// /// The number of consecutive messages that are sent while the driver performs duplicate address detection on a tentative IP /// unicast address. A value of zero indicates that duplicate address detection is not performed on tentative IP addresses. A /// value of one indicates a single transmission with no follow up retransmissions. For IPv4, the default value for this member /// is 3. For IPv6, the default value for this member is 1. For IPv6, these messages are sent as IPv6 Neighbor Solicitation (NS) /// requests. This member is defined as DupAddrDetectTransmits in RFC 2462. For more information, see IPv6 "Stateless Address Auto-configuration". /// public uint DadTransmits; /// /// The base for random reachable time, in milliseconds. The member is described in RFC 2461. For more information, see "Neighbor /// Discovery for IP Version 6 (IPv6)". /// public uint BaseReachableTime; /// /// The IPv6 Neighbor Solicitation (NS) time-out, in milliseconds. The member is described in RFC 2461. For more information, see /// "Neighbor Discovery for IP Version 6 (IPv6)". /// public uint RetransmitTime; /// The path MTU discovery time-out, in milliseconds. public uint PathMtuDiscoveryTimeout; /// A NL_LINK_LOCAL_ADDRESS_BEHAVIOR link local address behavior type. public NL_LINK_LOCAL_ADDRESS_BEHAVIOR LinkLocalAddressBehavior; /// The link local IP address time-out, in milliseconds. public uint LinkLocalAddressTimeout; /// An array that specifies the zone part of scope IDs. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public uint[] ZoneIndices; /// /// The site prefix length, in bits, of the IP interface address. The length, in bits, of the site prefix or network part of the /// IP interface address. For an IPv4 address, any value that is greater than 32 is an illegal value. For an IPv6 address, any /// value that is greater than 128 is an illegal value. A value of 255 is typically used to represent an illegal value. /// public uint SitePrefixLength; /// /// The interface metric. Note that the actual route metric that is used to compute the route preference is the summation of the /// route metric offset that is specified in the Metric member of the MIB_IPFORWARD_ROW2 structure and the /// interface metric that is specified in this member. /// public uint Metric; /// The network layer MTU size, in bytes. public uint NlMtu; /// A value that indicates if the interface is connected to a network access point. [MarshalAs(UnmanagedType.U1)] public bool Connected; /// A value that specifies if the network interface supports Wake on LAN. [MarshalAs(UnmanagedType.U1)] public bool SupportsWakeUpPatterns; /// A value that specifies if the IP interface support neighbor discovery. [MarshalAs(UnmanagedType.U1)] public bool SupportsNeighborDiscovery; /// A value that specifies if the IP interface support neighbor discovery. [MarshalAs(UnmanagedType.U1)] public bool SupportsRouterDiscovery; /// /// The base for random reachable time, in milliseconds. The member is described in RFC 2461. For more information, see Neighbor /// Discovery for IP Version 6 (IPv6). /// public uint ReachableTime; /// /// A set of flags that indicate the transmit offload capabilities for the IP interface. The NL_INTERFACE_OFFLOAD_ROD structure /// is defined in the Nldef.h header file. /// public NL_INTERFACE_OFFLOAD_ROD TransmitOffload; /// /// A set of flags that indicate the receive offload capabilities for the IP interface. The NL_INTERFACE_OFFLOAD_ROD structure is /// defined in the Nldef.h header file. /// public NL_INTERFACE_OFFLOAD_ROD ReceiveOffload; /// /// A value that indicates if using default route on the interface should be disabled. VPN clients can use this member to /// restrict split tunneling. /// [MarshalAs(UnmanagedType.U1)] public bool DisableDefaultRoutes; /// /// Initializes a new instance of the struct. /// /// The family. /// The interface luid. public MIB_IPINTERFACE_ROW(ADDRESS_FAMILY family, NET_LUID interfaceLuid) : this() { InitializeIpInterfaceEntry(out this); Family = family; InterfaceLuid = interfaceLuid; } /// /// Initializes a new instance of the struct. /// /// The family. /// Index of the interface. public MIB_IPINTERFACE_ROW(ADDRESS_FAMILY family, uint interfaceIndex) : this() { InitializeIpInterfaceEntry(out this); Family = family; InterfaceIndex = interfaceIndex; } /// Determines whether the specified value is equal to this instance. /// The value to compare with this instance. /// if the specified value is equal to this instance; otherwise, . public bool Equals(MIB_IPINTERFACE_ROW other) => Family.Equals(other.Family) && (InterfaceLuid.Value == other.InterfaceLuid.Value || InterfaceIndex == other.InterfaceIndex); } /// /// 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() => $"{Address}; MAC:{PhysicalAddressToString(PhysicalAddress)}; If:{(InterfaceIndex != 0 ? InterfaceIndex.ToString() : InterfaceLuid.ToString())}"; } /// /// Unlike this structure is zero copy [PInvokeData("netioapi.h", MSDNShortId = "164dbd93-4464-40f9-989a-17597102b1d8")] [StructLayout(LayoutKind.Sequential, Pack = 2)] public unsafe struct MIB_IPNET_ROW2_Unmanaged { /// /// 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. /// public fixed byte PhysicalAddress[IF_MAX_PHYS_ADDRESS_LENGTH]; /// /// 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_Unmanaged(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_Unmanaged(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_Unmanaged(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_Unmanaged(SOCKADDR_IN6 ipV6, uint ifIdx, byte[] macAddr = null) : this(ipV6, macAddr) => InterfaceIndex = ifIdx; private MIB_IPNET_ROW2_Unmanaged(SOCKADDR_IN ipV4, byte[] macAddr) : this() { Address.Ipv4 = ipV4; SetMac(macAddr); } private MIB_IPNET_ROW2_Unmanaged(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; fixed (byte* physicalAddress = PhysicalAddress) { Marshal.Copy(macAddr, 0, (IntPtr)physicalAddress, 6); } } /// public override string ToString() { fixed (byte* physicalAddress = PhysicalAddress) { return $"{Address}; MAC:{PhysicalAddressToString(physicalAddress)}; If:{(InterfaceIndex != 0 ? InterfaceIndex.ToString() : InterfaceLuid.ToString())}"; } } } /// /// The MIB_IPPATH_ROW structure stores information about an IP path entry. /// /// /// The MIB_IPPATH_ROW structure is defined on Windows Vista and later. /// /// The GetIpPathTable function enumerates the IP path entries on a local system and returns this information in a MIB_IPPATH_TABLE /// structure as an array of MIB_IPPATH_ROW entries. /// /// The GetIpPathEntry function retrieves a single IP path entry and returns this information in a MIB_IPPATH_TABLE structure. /// // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/ns-netioapi-_mib_ippath_row typedef struct _MIB_IPPATH_ROW { // SOCKADDR_INET Source; SOCKADDR_INET Destination; NET_LUID InterfaceLuid; NET_IFINDEX InterfaceIndex; SOCKADDR_INET CurrentNextHop; // ULONG PathMtu; ULONG RttMean; ULONG RttDeviation; union { ULONG LastReachable; ULONG LastUnreachable; }; BOOLEAN IsReachable; // ULONG64 LinkTransmitSpeed; ULONG64 LinkReceiveSpeed; } MIB_IPPATH_ROW, *PMIB_IPPATH_ROW; [PInvokeData("netioapi.h", MSDNShortId = "0cfef3cb-bb96-4250-864b-2468a46ba277")] [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct MIB_IPPATH_ROW { /// /// Type: SOCKADDR_INET /// The source IP address for this IP path entry. /// public SOCKADDR_INET Source; /// /// Type: SOCKADDR_INET /// The destination IP address for this IP path entry. /// public SOCKADDR_INET Destination; /// /// Type: NET_LUID /// The locally unique identifier (LUID) for the network interface associated with this IP path entry. /// public NET_LUID InterfaceLuid; /// /// Type: NET_IFINDEX /// /// The local index value for the network interface associated with this IP path 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: SOCKADDR_INET /// The current IP address of the next system or gateway en route. This member can change over the lifetime of a path. /// public SOCKADDR_INET CurrentNextHop; /// /// Type: ULONG /// The maximum transmission unit (MTU) size, in bytes, to the destination IP address for this IP path entry. /// public uint PathMtu; /// /// Type: ULONG /// The estimated mean round-trip time (RTT), in milliseconds, to the destination IP address for this IP path entry. /// public uint RttMean; /// /// Type: ULONG /// /// The estimated mean deviation for the round-trip time (RTT), in milliseconds, to the destination IP address for this IP path entry. /// /// public uint RttDeviation; /// /// Type: ULONG /// /// The time, in milliseconds, that a node assumes that the destination IP address is reachable after having received OR /// unreachable after not having received a reachability confirmation. /// /// public uint LastReachableOrUnreachable; /// /// Type: BOOLEAN /// A value that indicates if the destination IP address is reachable for this IP path entry. /// [MarshalAs(UnmanagedType.U1)] public bool IsReachable; /// /// Type: ULONG64 /// The estimated speed in bits per second of the transmit link to the destination IP address for this IP path entry. /// public ulong LinkTransmitSpeed; /// /// Type: ULONG64 /// The estimated speed in bits per second of the receive link from the destination IP address for this IP path entry. /// public ulong LinkReceiveSpeed; } /// The MIB_MULTICASTIPADDRESS_ROW structure stores information about a multicast IP address. // typedef struct _MIB_MULTICASTIPADDRESS_ROW { SOCKADDR_INET Address; NET_IFINDEX InterfaceIndex; NET_LUID InterfaceLuid; SCOPE_ID // ScopeId;} MIB_MULTICASTIPADDRESS_ROW, *PMIB_MULTICASTIPADDRESS_ROW; https://msdn.microsoft.com/en-us/library/windows/hardware/ff559277(v=vs.85).aspx [PInvokeData("Netioapi.h", MSDNShortId = "ff559277")] [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct MIB_MULTICASTIPADDRESS_ROW : IEquatable { /// The multicast IP address. This member can be an IPv6 address or an IPv4 address. public SOCKADDR_INET Address; /// /// The local index value for the network interface that is associated with this IP address. This index value might change when a /// network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent. /// public uint InterfaceIndex; /// The locally unique identifier (LUID) for the network interface that is associated with this IP address. public NET_LUID InterfaceLuid; /// /// The scope ID of the multicast IP address. This member is applicable only to an IPv6 address. Your driver cannot set this /// member. This member is automatically determined by the interface that the address was added on. /// public SCOPE_ID ScopeId; /// /// Initializes a new instance of the struct. /// /// The ipv4. /// The interface luid. public MIB_MULTICASTIPADDRESS_ROW(SOCKADDR_IN ipv4, NET_LUID interfaceLuid) : this() { Address.Ipv4 = ipv4; InterfaceLuid = interfaceLuid; } /// /// Initializes a new instance of the struct. /// /// The ipv4. /// Index of the interface. public MIB_MULTICASTIPADDRESS_ROW(SOCKADDR_IN ipv4, uint interfaceIndex) : this() { Address.Ipv4 = ipv4; InterfaceIndex = interfaceIndex; } /// /// Initializes a new instance of the struct. /// /// The ipv6. /// The interface luid. public MIB_MULTICASTIPADDRESS_ROW(SOCKADDR_IN6 ipv6, NET_LUID interfaceLuid) : this() { Address.Ipv6 = ipv6; InterfaceLuid = interfaceLuid; } /// /// Initializes a new instance of the struct. /// /// The ipv6. /// Index of the interface. public MIB_MULTICASTIPADDRESS_ROW(SOCKADDR_IN6 ipv6, uint interfaceIndex) : this() { Address.Ipv6 = ipv6; InterfaceIndex = interfaceIndex; } /// Determines whether the specified value is equal to this instance. /// The value to compare with this instance. /// if the specified value is equal to this instance; otherwise, . public bool Equals(MIB_MULTICASTIPADDRESS_ROW other) => Address.Equals(other.Address) && (InterfaceLuid.Value == other.InterfaceLuid.Value || InterfaceIndex == other.InterfaceIndex); } /// /// 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, Pack = 8)] public struct MIB_UNICASTIPADDRESS_ROW : IEquatable { /// /// 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; /// /// Initializes a new instance of the struct. /// /// The ipv4. /// The interface luid. public MIB_UNICASTIPADDRESS_ROW(SOCKADDR_IN ipv4, NET_LUID interfaceLuid) : this() { InitializeUnicastIpAddressEntry(out this); Address.Ipv4 = ipv4; InterfaceLuid = interfaceLuid; } /// /// Initializes a new instance of the struct. /// /// The ipv4. /// Index of the interface. public MIB_UNICASTIPADDRESS_ROW(SOCKADDR_IN ipv4, uint interfaceIndex) : this() { InitializeUnicastIpAddressEntry(out this); Address.Ipv4 = ipv4; InterfaceIndex = interfaceIndex; } /// /// Initializes a new instance of the struct. /// /// The ipv6. /// The interface luid. public MIB_UNICASTIPADDRESS_ROW(SOCKADDR_IN6 ipv6, NET_LUID interfaceLuid) : this() { InitializeUnicastIpAddressEntry(out this); Address.Ipv6 = ipv6; InterfaceLuid = interfaceLuid; } /// /// Initializes a new instance of the struct. /// /// The ipv6. /// Index of the interface. public MIB_UNICASTIPADDRESS_ROW(SOCKADDR_IN6 ipv6, uint interfaceIndex) : this() { InitializeUnicastIpAddressEntry(out this); Address.Ipv6 = ipv6; InterfaceIndex = interfaceIndex; } /// Determines whether the specified value is equal to this instance. /// The value to compare with this instance. /// if the specified value is equal to this instance; otherwise, . public bool Equals(MIB_UNICASTIPADDRESS_ROW other) => Address.Equals(other.Address) && (InterfaceLuid.Value == other.InterfaceLuid.Value || InterfaceIndex == other.InterfaceIndex); } /// The MIB_ANYCASTIPADDRESS_TABLE structure contains a table of anycast IP address entries. // typedef struct _MIB_ANYCASTIPADDRESS_TABLE { ULONG NumEntries; MIB_ANYCASTIPADDRESS_ROW Table[ANY_SIZE];} // MIB_ANYCASTIPADDRESS_TABLE, *PMIB_ANYCASTIPADDRESS_TABLE; https://msdn.microsoft.com/en-us/library/windows/hardware/ff559193(v=vs.85).aspx [PInvokeData("Netioapi.h", MSDNShortId = "ff559193")] [CorrespondingType(typeof(MIB_ANYCASTIPADDRESS_ROW)), DefaultProperty(nameof(Table))] public class MIB_ANYCASTIPADDRESS_TABLE : SafeMibEntryBase { } /// 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(Table))] public class MIB_IF_TABLE2 : SafeMibEntryBase { } /// /// The MIB_IFSTACK_TABLE structure contains a table of network interface stack row entries. This table specifies the relationship of /// the network interfaces on an interface stack. /// // typedef struct _MIB_IFSTACK_TABLE { ULONG NumEntries; MIB_IFSTACK_ROW Table[ANY_SIZE];} MIB_IFSTACK_TABLE, *PMIB_IFSTACK_TABLE; https://msdn.microsoft.com/en-us/library/windows/hardware/ff559210(v=vs.85).aspx [CorrespondingType(typeof(MIB_IFSTACK_ROW)), DefaultProperty(nameof(Table))] [PInvokeData("Netioapi.h", MSDNShortId = "ff559210")] public class MIB_IFSTACK_TABLE : SafeMibEntryBase { } /// /// The MIB_INVERTEDIFSTACK_TABLE structure contains a table of inverted network interface stack row entries. This table specifies /// the relationship of the network interfaces on an interface stack in reverse order. /// // typedef struct _MIB_INVERTEDIFSTACK_TABLE { ULONG NumEntries; MIB_INVERTEDIFSTACK_ROW Table[ANY_SIZE];} MIB_INVERTEDIFSTACK_TABLE, // *PMIB_INVERTEDIFSTACK_TABLE; https://msdn.microsoft.com/en-us/library/windows/hardware/ff559240(v=vs.85).aspx [PInvokeData("Netioapi.h", MSDNShortId = "ff559240")] [CorrespondingType(typeof(MIB_INVERTEDIFSTACK_ROW)), DefaultProperty(nameof(Table))] public class MIB_INVERTEDIFSTACK_TABLE : SafeMibEntryBase { } /// The MIB_IPFORWARD_TABLE2 structure contains a table of IP route entries. // typedef struct _MIB_IPFORWARD_TABLE2 { ULONG NumEntries; MIB_IPFORWARD_ROW2 Table[ANY_SIZE];} MIB_IPFORWARD_TABLE2, // *PMIB_IPFORWARD_TABLE2; https://msdn.microsoft.com/en-us/library/windows/hardware/ff559252(v=vs.85).aspx [PInvokeData("Netioapi.h", MSDNShortId = "ff559252")] [CorrespondingType(typeof(MIB_IPFORWARD_ROW2)), DefaultProperty(nameof(Table))] public class MIB_IPFORWARD_TABLE2 : SafeMibEntryBase { } /// The MIB_IPINTERFACE_TABLE structure contains a table of IP interface entries. // typedef struct _MIB_IPINTERFACE_TABLE { ULONG NumEntries; MIB_IPINTERFACE_ROW Table[ANY_SIZE];} MIB_IPINTERFACE_TABLE, // *PMIB_IPINTERFACE_TABLE; https://msdn.microsoft.com/en-us/library/windows/hardware/ff559260(v=vs.85).aspx [PInvokeData("Netioapi.h", MSDNShortId = "ff559260")] [CorrespondingType(typeof(MIB_IPINTERFACE_ROW)), DefaultProperty(nameof(Table))] public class MIB_IPINTERFACE_TABLE : SafeMibEntryBase { } /// 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(Table))] public class MIB_IPNET_TABLE2 : SafeMibEntryBase { } /// /// Unlike this provides is zero copy/// [PInvokeData("Netioapi.h", MSDNShortId = "ff559267")] #if ALLOWSPAN [CorrespondingType(typeof(MIB_IPNET_ROW2_Unmanaged)), DefaultProperty(nameof(TableAsSpan))] #else [CorrespondingType(typeof(MIB_IPNET_ROW2_Unmanaged))] #endif public class MIB_IPNET_TABLE2_Unmanaged : SafeUnmanagedMibEntryBase { } /// The MIB_IPPATH_TABLE structure contains a table of IP path entries. // typedef struct _MIB_IPPATH_TABLE { ULONG NumEntries; MIB_IPPATH_ROW Table[ANY_SIZE];} MIB_IPPATH_TABLE, *PMIB_IPPATH_TABLE; https://msdn.microsoft.com/en-us/library/windows/hardware/ff559273(v=vs.85).aspx [PInvokeData("Netioapi.h", MSDNShortId = "ff559273")] [CorrespondingType(typeof(MIB_IPPATH_ROW)), DefaultProperty(nameof(Table))] public class MIB_IPPATH_TABLE : SafeMibEntryBase { } /// /// The MIB_MULTICASTIPADDRESS_TABLE structure contains a table of multicast IP address entries. /// /// /// The MIB_MULTICASTIPADDRESS_TABLE structure is defined on Windows Vista and later. /// /// The GetMulticastIpAddressTable function enumerates the multicast IP addresses on a local system and returns this information in /// an MIB_MULTICASTIPADDRESS_TABLE structure. /// /// /// The MIB_MULTICASTIPADDRESS_TABLE structure may contain padding for alignment between the NumEntries member and the /// first MIB_MULTICASTIPADDRESS_ROW array entry in the Table member. Padding for alignment may also be present between the /// MIB_MULTICASTIPADDRESS_ROW array entries in the Table member. Any access to a MIB_MULTICASTIPADDRESS_ROW /// array entry should assume padding may exist. /// /// /// 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_multicastipaddress_table typedef struct // _MIB_MULTICASTIPADDRESS_TABLE { ULONG NumEntries; MIB_MULTICASTIPADDRESS_ROW Table[ANY_SIZE]; } MIB_MULTICASTIPADDRESS_TABLE, *PMIB_MULTICASTIPADDRESS_TABLE; [PInvokeData("netioapi.h", MSDNShortId = "7ae1ec12-aa67-40ff-9641-410099685234")] [CorrespondingType(typeof(MIB_MULTICASTIPADDRESS_ROW)), DefaultProperty(nameof(Table))] public class MIB_MULTICASTIPADDRESS_TABLE : SafeMibEntryBase { } /// /// The MIB_UNICASTIPADDRESS_TABLE structure contains a table of unicast IP address entries. /// /// /// The MIB_UNICASTIPADDRESS_TABLE structure is defined on Windows Vista and later. /// /// The GetUnicastIpAddressTable function enumerates the unicast IP addresses on a local system and returns this information in an /// MIB_UNICASTIPADDRESS_TABLE structure. /// /// /// The MIB_UNICASTIPADDRESS_TABLE structure may contain padding for alignment between the NumEntries member and the /// first MIB_UNICASTIPADDRESS_ROW array entry in the Table member. Padding for alignment may also be present between the /// MIB_UNICASTIPADDRESS_ROW array entries in the Table member. Any access to a MIB_UNICASTIPADDRESS_ROW array /// entry should assume padding may exist. /// /// 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_table typedef struct // _MIB_UNICASTIPADDRESS_TABLE { ULONG NumEntries; MIB_UNICASTIPADDRESS_ROW Table[ANY_SIZE]; } MIB_UNICASTIPADDRESS_TABLE, *PMIB_UNICASTIPADDRESS_TABLE; [PInvokeData("netioapi.h", MSDNShortId = "b064494c-d0d5-4570-b255-4cc95412fd3a")] [CorrespondingType(typeof(MIB_UNICASTIPADDRESS_ROW)), DefaultProperty(nameof(Table))] public class MIB_UNICASTIPADDRESS_TABLE : SafeMibEntryBase { } /// Base class for all structures that support a variable length array of structures with a count in the first field. /// Type of the structure array. public abstract class SafeMibEntryBase : SafeMibTableHandle, IEnumerable where T : struct { /// Gets the number of interface entries in the array. public virtual uint NumEntries => IsInvalid ? 0 : handle.ToStructure(); /// Gets the array of structures containing interface entries. public virtual T[] Table => ToArray((int)NumEntries, Marshal.SizeOf(typeof(ulong))); #if ALLOWSPAN /// Gets the containing interface entries. public virtual Span TableAsSpan => AsSpan((int)NumEntries, Marshal.SizeOf(typeof(ulong))); #endif /// Gets the enumerator. public IEnumerator GetEnumerator() => ((IEnumerable) Table).GetEnumerator(); /// Gets the enumerator. IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } /// Base class for all structures that support a variable length array of structures with a count in the first field. /// Type of the structure array. public abstract class SafeUnmanagedMibEntryBase : SafeMibTableHandle where T : unmanaged { /// Gets the number of interface entries in the array. public virtual uint NumEntries => IsInvalid ? 0 : handle.ToStructure(); /// Exposes the pointer to the array of structures. public unsafe T* AsUnmanagedArrayPointer() => IsInvalid ? null : handle.AsUnmanagedArrayPointer((int)NumEntries, Marshal.SizeOf(typeof(ulong))); #if !ALLOWSPAN /// Gets the enumerator. public unsafe RefEnumerator GetEnumerator() => new RefEnumerator(AsUnmanagedArrayPointer(), (int)NumEntries); #else /// Gets the enumerator. public Span.Enumerator GetEnumerator() => TableAsSpan.GetEnumerator(); /// Gets the containing interface entries. public virtual Span TableAsSpan => AsSpan((int)NumEntries, Marshal.SizeOf(typeof(ulong))); #endif } /// SafeHandle for all objects that must be freed with FreeMibTable. /// public class SafeMibTableHandle : GenericSafeHandle { /// Initializes a new instance of the class. public SafeMibTableHandle() : this(IntPtr.Zero) { } /// Initializes a new instance of the class. /// The buffer PTR. /// if set to true [own]. public SafeMibTableHandle(IntPtr bufferPtr, bool own = true) : base(bufferPtr, h => { FreeMibTable(h); return true; }, own) { } #if ALLOWSPAN /// Exposes a from the pointer. /// The structure type of the array. /// The number of span elements. /// The number of bytes to skip before processing the array. public Span AsSpan(int length, int prefixBytes = 0) => IsInvalid ? null : handle.AsSpan(length, prefixBytes); #endif /// Extracts the array from the pointer. /// The structure type of the array. /// The number of items. /// The number of bytes to skip before processing the array. public T[] ToArray(int count, int prefixBytes = 0) => IsInvalid ? null : handle.ToArray(count, prefixBytes); } } }