diff --git a/PInvoke/IpHlpApi/IpHlpApi.cs b/PInvoke/IpHlpApi/IpHlpApi.cs index 7283f1c8..3dc2c4d1 100644 --- a/PInvoke/IpHlpApi/IpHlpApi.cs +++ b/PInvoke/IpHlpApi/IpHlpApi.cs @@ -5,6 +5,7 @@ using System.ComponentModel; using System.Runtime.InteropServices; using Vanara.Extensions; using Vanara.InteropServices; + // ReSharper disable FieldCanBeMadeReadOnly.Global // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global @@ -43,29 +44,50 @@ namespace Vanara.PInvoke { /// Do not return unicast addresses. GAA_FLAG_SKIP_UNICAST = 0x0001, + /// Do not return IPv6 anycast addresses. GAA_FLAG_SKIP_ANYCAST = 0x0002, + /// Do not return multicast addresses. GAA_FLAG_SKIP_MULTICAST = 0x0004, + /// Do not return addresses of DNS servers. GAA_FLAG_SKIP_DNS_SERVER = 0x0008, - /// Return a list of IP address prefixes on this adapter. When this flag is set, IP address prefixes are returned for both IPv6 and IPv4 addresses. - /// This flag is supported on Windows XP with SP1 and later. + + /// + /// Return a list of IP address prefixes on this adapter. When this flag is set, IP address prefixes are returned for both IPv6 + /// and IPv4 addresses. + /// This flag is supported on Windows XP with SP1 and later. + /// GAA_FLAG_INCLUDE_PREFIX = 0x0010, + /// Do not return the adapter friendly name. GAA_FLAG_SKIP_FRIENDLY_NAME = 0x0020, - /// Return addresses of Windows Internet Name Service (WINS) servers. - /// This flag is supported on Windows Vista and later. + + /// + /// Return addresses of Windows Internet Name Service (WINS) servers. + /// This flag is supported on Windows Vista and later. + /// GAA_FLAG_INCLUDE_WINS_INFO = 0x0040, - /// Return the addresses of default gateways. - /// This flag is supported on Windows Vista and later. + + /// + /// Return the addresses of default gateways. + /// This flag is supported on Windows Vista and later. + /// GAA_FLAG_INCLUDE_GATEWAYS = 0x0080, - /// Return addresses for all NDIS interfaces. - /// This flag is supported on Windows Vista and later. + + /// + /// Return addresses for all NDIS interfaces. + /// This flag is supported on Windows Vista and later. + /// GAA_FLAG_INCLUDE_ALL_INTERFACES = 0x0100, - /// Return addresses in all routing compartments. - /// This flag is not currently supported and reserved for future use. + + /// + /// Return addresses in all routing compartments. + /// This flag is not currently supported and reserved for future use. + /// GAA_FLAG_INCLUDE_ALL_COMPARTMENTS = 0x0200, + /// Return the adapter addresses sorted in tunnel binding order. This flag is supported on Windows Vista and later. GAA_FLAG_INCLUDE_TUNNEL_BINDINGORDER = 0x0400, } @@ -75,23 +97,31 @@ namespace Vanara.PInvoke { /// The interface is up and operational. The interface is able to pass packets. IfOperStatusUp = 1, + /// The interface is not down and not operational. The interface is unable to pass packets. IfOperStatusDown, + /// The interface is being tested. IfOperStatusTesting, + /// The interface status is unknown. IfOperStatusUnknown, + /// - /// The interface is not in a condition to pass packets. The interface is not up, but is in a pending state, waiting for some external event. This - /// state identifies the situation where the interface is waiting for events to place it in the up state. + /// The interface is not in a condition to pass packets. The interface is not up, but is in a pending state, waiting for some + /// external event. This state identifies the situation where the interface is waiting for events to place it in the up state. /// IfOperStatusDormant, + /// - /// This state is a refinement on the down state which indicates that the interface is down specifically because some component (for example, a - /// hardware component) is not present in the system. + /// This state is a refinement on the down state which indicates that the interface is down specifically because some component + /// (for example, a hardware component) is not present in the system. /// IfOperStatusNotPresent, - /// This state is a refinement on the down state. The interface is operational, but a networking layer below the interface is not operational. + + /// + /// This state is a refinement on the down state. The interface is operational, but a networking layer below the interface is not operational. + /// IfOperStatusLowerLayerDown, } @@ -100,255 +130,378 @@ namespace Vanara.PInvoke { /// Some other type of network interface. IF_TYPE_OTHER = 1, + IF_TYPE_REGULAR_1822 = 2, IF_TYPE_HDH_1822 = 3, IF_TYPE_DDN_X25 = 4, IF_TYPE_RFC877_X25 = 5, + /// An Ethernet network interface. IF_TYPE_ETHERNET_CSMACD = 6, + IF_TYPE_IS088023_CSMACD = 7, IF_TYPE_ISO88024_TOKENBUS = 8, + /// A token ring network interface. IF_TYPE_ISO88025_TOKENRING = 9, + IF_TYPE_ISO88026_MAN = 10, IF_TYPE_STARLAN = 11, IF_TYPE_PROTEON_10MBIT = 12, IF_TYPE_PROTEON_80MBIT = 13, IF_TYPE_HYPERCHANNEL = 14, + /// A Fiber Distributed Data Interface (FDDI) network interface. IF_TYPE_FDDI = 15, + IF_TYPE_LAP_B = 16, IF_TYPE_SDLC = 17, + /// DS1-MIB IF_TYPE_DS1 = 18, + /// Obsolete; see DS1-MIB IF_TYPE_E1 = 19, + IF_TYPE_BASIC_ISDN = 20, IF_TYPE_PRIMARY_ISDN = 21, + /// proprietary serial IF_TYPE_PROP_POINT2POINT_SERIAL = 22, + /// A PPP network interface. IF_TYPE_PPP = 23, + /// A software loopback network interface. IF_TYPE_SOFTWARE_LOOPBACK = 24, + /// CLNP over IP IF_TYPE_EON = 25, + IF_TYPE_ETHERNET_3MBIT = 26, + /// XNS over IP IF_TYPE_NSIP = 27, + /// Generic Slip IF_TYPE_SLIP = 28, + /// ULTRA Technologies IF_TYPE_ULTRA = 29, + /// DS3-MIB IF_TYPE_DS3 = 30, + /// SMDS, coffee IF_TYPE_SIP = 31, + /// DTE only IF_TYPE_FRAMERELAY = 32, + IF_TYPE_RS232 = 33, + /// Parallel port IF_TYPE_PARA = 34, + IF_TYPE_ARCNET = 35, IF_TYPE_ARCNET_PLUS = 36, + /// An ATM network interface. IF_TYPE_ATM = 37, + IF_TYPE_MIO_X25 = 38, + /// SONET or SDH IF_TYPE_SONET = 39, + IF_TYPE_X25_PLE = 40, IF_TYPE_ISO88022_LLC = 41, IF_TYPE_LOCALTALK = 42, IF_TYPE_SMDS_DXI = 43, + /// FRNETSERV-MIB IF_TYPE_FRAMERELAY_SERVICE = 44, + IF_TYPE_V35 = 45, IF_TYPE_HSSI = 46, IF_TYPE_HIPPI = 47, + /// Generic Modem IF_TYPE_MODEM = 48, + /// AAL5 over ATM IF_TYPE_AAL5 = 49, + IF_TYPE_SONET_PATH = 50, IF_TYPE_SONET_VT = 51, + /// SMDS InterCarrier Interface IF_TYPE_SMDS_ICIP = 52, + /// Proprietary virtual/internal IF_TYPE_PROP_VIRTUAL = 53, + /// Proprietary multiplexing IF_TYPE_PROP_MULTIPLEXOR = 54, + /// 100BaseVG IF_TYPE_IEEE80212 = 55, + IF_TYPE_FIBRECHANNEL = 56, IF_TYPE_HIPPIINTERFACE = 57, + /// Obsolete, use 32 or 44 IF_TYPE_FRAMERELAY_INTERCONNECT = 58, + /// ATM Emulated LAN for 802.3 IF_TYPE_AFLANE_8023 = 59, + /// ATM Emulated LAN for 802.5 IF_TYPE_AFLANE_8025 = 60, + /// ATM Emulated circuit IF_TYPE_CCTEMUL = 61, + /// Fast Ethernet (100BaseT) IF_TYPE_FASTETHER = 62, + /// ISDN and X.25 IF_TYPE_ISDN = 63, + /// CCITT V.11/X.21 IF_TYPE_V11 = 64, + /// CCITT V.36 IF_TYPE_V36 = 65, + /// CCITT G703 at 64Kbps IF_TYPE_G703_64K = 66, + /// Obsolete; see DS1-MIB IF_TYPE_G703_2MB = 67, + /// SNA QLLC IF_TYPE_QLLC = 68, + /// Fast Ethernet (100BaseFX) IF_TYPE_FASTETHER_FX = 69, + IF_TYPE_CHANNEL = 70, + /// An IEEE 802.11 wireless network interface. IF_TYPE_IEEE80211 = 71, + /// IBM System 360/370 OEMI Channel IF_TYPE_IBM370PARCHAN = 72, + /// IBM Enterprise Systems Connection IF_TYPE_ESCON = 73, + /// Data Link Switching IF_TYPE_DLSW = 74, + /// ISDN S/T interface IF_TYPE_ISDN_S = 75, + /// ISDN U interface IF_TYPE_ISDN_U = 76, + /// Link Access Protocol D IF_TYPE_LAP_D = 77, + /// IP Switching Objects IF_TYPE_IPSWITCH = 78, + /// Remote Source Route Bridging IF_TYPE_RSRB = 79, + /// ATM Logical Port IF_TYPE_ATM_LOGICAL = 80, + /// Digital Signal Level 0 IF_TYPE_DS0 = 81, + /// Group of ds0s on the same ds1 IF_TYPE_DS0_BUNDLE = 82, + /// Bisynchronous Protocol IF_TYPE_BSC = 83, + /// Asynchronous Protocol IF_TYPE_ASYNC = 84, + /// Combat Net Radio IF_TYPE_CNR = 85, + /// ISO 802.5r DTR IF_TYPE_ISO88025R_DTR = 86, + /// Ext Pos Loc Report Sys IF_TYPE_EPLRS = 87, + /// Appletalk Remote Access Protocol IF_TYPE_ARAP = 88, + /// Proprietary Connectionless Proto IF_TYPE_PROP_CNLS = 89, + /// CCITT-ITU X.29 PAD Protocol IF_TYPE_HOSTPAD = 90, + /// CCITT-ITU X.3 PAD Facility IF_TYPE_TERMPAD = 91, + /// Multiproto Interconnect over FR IF_TYPE_FRAMERELAY_MPI = 92, + /// CCITT-ITU X213 IF_TYPE_X213 = 93, + /// Asymmetric Digital Subscrbr Loop IF_TYPE_ADSL = 94, + /// Rate-Adapt Digital Subscrbr Loop IF_TYPE_RADSL = 95, + /// Symmetric Digital Subscriber Loop IF_TYPE_SDSL = 96, + /// Very H-Speed Digital Subscrb Loop IF_TYPE_VDSL = 97, + /// ISO 802.5 CRFP IF_TYPE_ISO88025_CRFPRINT = 98, + /// Myricom Myrinet IF_TYPE_MYRINET = 99, + /// Voice recEive and transMit IF_TYPE_VOICE_EM = 100, + /// Voice Foreign Exchange Office IF_TYPE_VOICE_FXO = 101, + /// Voice Foreign Exchange Station IF_TYPE_VOICE_FXS = 102, + /// Voice encapsulation IF_TYPE_VOICE_ENCAP = 103, + /// Voice over IP encapsulation IF_TYPE_VOICE_OVERIP = 104, + /// ATM DXI IF_TYPE_ATM_DXI = 105, + /// ATM FUNI IF_TYPE_ATM_FUNI = 106, + /// ATM IMA IF_TYPE_ATM_IMA = 107, + /// PPP Multilink Bundle IF_TYPE_PPPMULTILINKBUNDLE = 108, + /// IBM ipOverCdlc IF_TYPE_IPOVER_CDLC = 109, + /// IBM Common Link Access to Workstn IF_TYPE_IPOVER_CLAW = 110, + /// IBM stackToStack IF_TYPE_STACKTOSTACK = 111, + /// IBM VIPA IF_TYPE_VIRTUALIPADDRESS = 112, + /// IBM multi-proto channel support IF_TYPE_MPC = 113, + /// IBM ipOverAtm IF_TYPE_IPOVER_ATM = 114, + /// ISO 802.5j Fiber Token Ring IF_TYPE_ISO88025_FIBER = 115, + /// IBM twinaxial data link control IF_TYPE_TDLC = 116, + IF_TYPE_GIGABITETHERNET = 117, IF_TYPE_HDLC = 118, IF_TYPE_LAP_F = 119, IF_TYPE_V37 = 120, + /// Multi-Link Protocol IF_TYPE_X25_MLP = 121, + /// X.25 Hunt Group IF_TYPE_X25_HUNTGROUP = 122, + IF_TYPE_TRANSPHDLC = 123, + /// Interleave channel IF_TYPE_INTERLEAVE = 124, + /// Fast channel IF_TYPE_FAST = 125, + /// IP (for APPN HPR in IP networks) IF_TYPE_IP = 126, + /// CATV Mac Layer IF_TYPE_DOCSCABLE_MACLAYER = 127, + /// CATV Downstream interface IF_TYPE_DOCSCABLE_DOWNSTREAM = 128, + /// CATV Upstream interface IF_TYPE_DOCSCABLE_UPSTREAM = 129, + /// Avalon Parallel Processor IF_TYPE_A12MPPSWITCH = 130, + /// A tunnel type encapsulation network interface. IF_TYPE_TUNNEL = 131, // Encapsulation interface - /// Coffee pot + + /// Coffee pot IF_TYPE_COFFEE = 132, + /// Circuit Emulation Service IF_TYPE_CES = 133, + /// ATM Sub Interface IF_TYPE_ATM_SUBINTERFACE = 134, + /// Layer 2 Virtual LAN using 802.1Q IF_TYPE_L2_VLAN = 135, + /// Layer 3 Virtual LAN using IP IF_TYPE_L3_IPVLAN = 136, + /// Layer 3 Virtual LAN using IPX IF_TYPE_L3_IPXVLAN = 137, + /// IP over Power Lines IF_TYPE_DIGITALPOWERLINE = 138, + /// Multimedia Mail over IP IF_TYPE_MEDIAMAILOVERIP = 139, + /// Dynamic syncronous Transfer Mode IF_TYPE_DTM = 140, + /// Data Communications Network IF_TYPE_DCN = 141, + /// IP Forwarding Interface IF_TYPE_IPFORWARD = 142, - /// Multi-rate Symmetric DSL + + /// Multi-rate Symmetric DSL IF_TYPE_MSDSL = 143, + /// An IEEE 1394 (Firewire) high performance serial bus network interface. IF_TYPE_IEEE1394 = 144, // IEEE1394 High Perf Serial Bus + IF_TYPE_IF_GSN = 145, IF_TYPE_DVBRCC_MACLAYER = 146, IF_TYPE_DVBRCC_DOWNSTREAM = 147, @@ -401,14 +554,28 @@ namespace Vanara.PInvoke IF_TYPE_ATM_VCI_ENDPT = 194, IF_TYPE_OPTICAL_CHANNEL = 195, IF_TYPE_OPTICAL_TRANSPORT = 196, - /// A mobile broadband interface for WiMax devices.This interface type is supported on Windows 7, Windows Server 2008 R2, and later. + + /// + /// A mobile broadband interface for WiMax devices. This interface type is supported on Windows 7, Windows + /// Server 2008 R2, and later. + /// IF_TYPE_IEEE80216_WMAN = 237, - /// A mobile broadband interface for GSM-based devices.This interface type is supported on Windows 7, Windows Server 2008 R2, and later. + + /// + /// A mobile broadband interface for GSM-based devices. This interface type is supported on Windows 7, Windows + /// Server 2008 R2, and later. + /// IF_TYPE_WWANPP = 243, - /// A mobile broadband interface for CDMA-based devices.This interface type is supported on Windows 7, Windows Server 2008 R2, and later. + + /// + /// A mobile broadband interface for CDMA-based devices. This interface type is supported on Windows 7, Windows + /// Server 2008 R2, and later. + /// IF_TYPE_WWANPP2 = 244, + /// IEEE 802.15.4 WPAN interface IF_TYPE_IEEE802154 = 259, + IF_TYPE_XBOX_WIRELESS = 281, } @@ -418,19 +585,40 @@ namespace Vanara.PInvoke { /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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 } @@ -501,7 +689,7 @@ namespace Vanara.PInvoke MibIfTableNormalWithoutStatistics } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [Flags] public enum MIB_IPADDRTYPE : ushort { @@ -513,7 +701,7 @@ namespace Vanara.PInvoke MIB_IPADDR_DNS_ELIGIBLE = 0X0100, // Address is published in DNS. } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] public enum MIB_IPFORWARD_TYPE { MIB_IPROUTE_TYPE_OTHER = 1, @@ -521,8 +709,15 @@ namespace Vanara.PInvoke MIB_IPROUTE_TYPE_DIRECT = 3, MIB_IPROUTE_TYPE_INDIRECT = 4, } - - [PInvokeData("Iphlpapi.h")] + + [Flags] + public enum MIB_IPNET_ROW2_FLAGS : uint + { + IsRouther = 1, + IsUnreachable = 2 + } + + [PInvokeData("IpHlpApi.h")] public enum MIB_IPNET_TYPE { MIB_IPNET_TYPE_OTHER = 1, @@ -531,7 +726,7 @@ namespace Vanara.PInvoke MIB_IPNET_TYPE_STATIC = 4, } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] public enum MIB_IPPROTOCOL { MIB_IPPROTO_OTHER = 1, @@ -581,44 +776,83 @@ namespace Vanara.PInvoke { /// Specifies an Ethernet (802.3) network. NdisMedium802_3, - /// Specifies a Token Ring (802.5) network.Not supported in Windows 8 or later. + + /// Specifies a Token Ring (802.5) network. Not supported in Windows 8 or later. NdisMedium802_5, - /// Specifies a Fiber Distributed Data Interface (FDDI) network.Not supported in Windows Vista/Windows Server 2008 or later. + + /// + /// Specifies a Fiber Distributed Data Interface (FDDI) network. Not supported in Windows Vista/Windows Server + /// 2008 or later. + /// NdisMediumFddi, - /// Specifies a wide area network. This type covers various forms of point-to-point and WAN NICs, as well as variant address/header formats that must be negotiated between the protocol driver and the underlying driver after the binding is established. + + /// + /// Specifies a wide area network. This type covers various forms of point-to-point and WAN NICs, as well as variant + /// address/header formats that must be negotiated between the protocol driver and the underlying driver after the binding is established. + /// NdisMediumWan, + /// Specifies a LocalTalk network. NdisMediumLocalTalk, + /// Specifies an Ethernet network for which the drivers use the DIX Ethernet header format. NdisMediumDix, - /// Specifies an ARCNET network.Not supported in Windows Vista/Windows Server 2008 or later. + + /// Specifies an ARCNET network. Not supported in Windows Vista/Windows Server 2008 or later. NdisMediumArcnetRaw, - /// Specifies an ARCNET (878.2) network.Not supported in Windows Vista/Windows Server 2008 or later. + + /// + /// Specifies an ARCNET (878.2) network. Not supported in Windows Vista/Windows Server 2008 or later. + /// NdisMediumArcnet878_2, - /// Specifies an ATM network. Connection-oriented client protocol drivers can bind themselves to an underlying miniport driver that returns this value. Otherwise, legacy protocol drivers bind themselves to the system-supplied LanE intermediate driver, which reports its medium type as either of NdisMedium802_3 or NdisMedium802_5, depending on how the LanE driver is configured by the network administrator. + + /// + /// Specifies an ATM network. Connection-oriented client protocol drivers can bind themselves to an underlying miniport driver + /// that returns this value. Otherwise, legacy protocol drivers bind themselves to the system-supplied LanE intermediate driver, + /// which reports its medium type as either of NdisMedium802_3 or NdisMedium802_5, depending on how the LanE driver is configured + /// by the network administrator. + /// NdisMediumAtm, - /// Specifies a wireless network. NDIS 5.X miniport drivers that support wireless LAN (WLAN) or wireless WAN (WWAN) packets declare their medium as NdisMedium802_3 and emulate Ethernet to higher-level NDIS drivers.Starting with Windows 7, this media type is supported and can be used for Mobile Broadband. + + /// + /// Specifies a wireless network. NDIS 5.X miniport drivers that support wireless LAN (WLAN) or wireless WAN (WWAN) packets + /// declare their medium as NdisMedium802_3 and emulate Ethernet to higher-level NDIS drivers. Starting with + /// Windows 7, this media type is supported and can be used for Mobile Broadband. + /// NdisMediumWirelessWan, + /// Specifies an infrared (IrDA) network. NdisMediumIrda, + /// Specifies a broadcast PC network. NdisMediumBpc, + /// Specifies a wide area network in a connection-oriented environment. NdisMediumCoWan, - /// Specifies an IEEE 1394 (fire wire) network.Not supported in Windows Vista/Windows Server 2008 or later. + + /// + /// Specifies an IEEE 1394 (fire wire) network. Not supported in Windows Vista/Windows Server 2008 or later. + /// NdisMedium1394, + /// Specifies an InfiniBand network. NdisMediumInfiniBand, + /// Specifies a tunnel network. NdisMediumTunnel, + /// Specifies a native IEEE 802.11 network. NdisMediumNative802_11, + /// Specifies an NDIS loopback network. NdisMediumLoopback, + /// Specifies a WiMAX network. NdisMediumWiMAX, + /// Specifies a generic medium that is capable of sending and receiving raw IP packets. NdisMediumIP, + /// A maximum value for testing purposes. NdisMediumMax, } @@ -627,44 +861,75 @@ namespace Vanara.PInvoke [PInvokeData("ntddndis.h")] public enum NDIS_PHYSICAL_MEDIUM { - /// The physical medium is none of the below values. For example, a one-way satellite feed is an unspecified physical medium. + /// + /// The physical medium is none of the below values. For example, a one-way satellite feed is an unspecified physical medium. + /// NdisPhysicalMediumUnspecified = 0, + /// Packets are transferred over a wireless LAN network through a miniport driver that conforms to the 802.11 interface. NdisPhysicalMediumWirelessLan = 1, + /// Packets are transferred over a DOCSIS-based cable network. NdisPhysicalMediumCableModem = 2, + /// Packets are transferred over standard phone lines. This includes HomePNA media, for example. NdisPhysicalMediumPhoneLine = 3, + /// Packets are transferred over wiring that is connected to a power distribution system. NdisPhysicalMediumPowerLine = 4, - /// Packets are transferred over a Digital Subscriber Line (DSL) network. This includes ADSL, UADSL (G.Lite), and SDSL, for example. + + /// + /// Packets are transferred over a Digital Subscriber Line (DSL) network. This includes ADSL, UADSL (G.Lite), and SDSL, for example. + /// NdisPhysicalMediumDSL = 5, + /// Packets are transferred over a Fibre Channel interconnect. NdisPhysicalMediumFibreChannel = 6, + /// Packets are transferred over an IEEE 1394 bus. NdisPhysicalMedium1394 = 7, - /// Packets are transferred over a Wireless WAN link. This includes mobile broadband devices that support CDPD, CDMA, GSM, and GPRS, for example. + + /// + /// Packets are transferred over a Wireless WAN link. This includes mobile broadband devices that support CDPD, CDMA, GSM, and + /// GPRS, for example. + /// NdisPhysicalMediumWirelessWan = 8, - /// Packets are transferred over a wireless LAN network through a miniport driver that conforms to the Native 802.11 interface.The Native 802.11 interface is supported in NDIS 6.0 and later versions. + + /// + /// Packets are transferred over a wireless LAN network through a miniport driver that conforms to the Native 802.11 interface. + /// The Native 802.11 interface is supported in NDIS 6.0 and later versions. + /// NdisPhysicalMediumNative802_11 = 9, - /// Packets are transferred over a Bluetooth network. Bluetooth is a short-range wireless technology that uses the 2.4 GHz spectrum. + + /// + /// Packets are transferred over a Bluetooth network. Bluetooth is a short-range wireless technology that uses the 2.4 GHz spectrum. + /// NdisPhysicalMediumBluetooth = 10, + /// Packets are transferred over an Infiniband interconnect. NdisPhysicalMediumInfiniband = 11, + /// Packets are transferred over a WiMax network. NdisPhysicalMediumWiMax = 12, + /// Packets are transferred over an ultra wide band network. NdisPhysicalMediumUWB = 13, + /// Packets are transferred over an Ethernet (802.3) network. NdisPhysicalMedium802_3 = 14, + /// Packets are transferred over a Token Ring (802.5) network. NdisPhysicalMedium802_5 = 15, + /// Packets are transferred over an infrared (IrDA) network. NdisPhysicalMediumIrda = 16, + /// Packets are transferred over a wired WAN network. NdisPhysicalMediumWiredWAN = 17, + /// Packets are transferred over a wide area network in a connection-oriented environment. NdisPhysicalMediumWiredCoWan = 18, + /// Packets are transferred over a network that is not described by other possible values. NdisPhysicalMediumOther = 19, } @@ -778,7 +1043,7 @@ namespace Vanara.PInvoke } // https://msdn2.microsoft.com/en-us/library/aa366386.aspx - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] public enum TCP_TABLE_CLASS { [CorrespondingType(typeof(MIB_TCPTABLE), CorrepsondingAction.Get)] @@ -816,28 +1081,46 @@ namespace Vanara.PInvoke } /// - /// The TUNNEL_TYPE enumeration type defines the encapsulation method used by a tunnel, as described by the Internet Assigned Names Authority (IANA). + /// The TUNNEL_TYPE enumeration type defines the encapsulation method used by a tunnel, as described by the Internet Assigned Names + /// Authority (IANA). /// [PInvokeData("ifdef.h")] public enum TUNNEL_TYPE : uint { /// Indicates that a tunnel is not specified. TUNNEL_TYPE_NONE = 0, + /// Indicates that none of the following tunnel types is specified. TUNNEL_TYPE_OTHER = 1, - /// A packet is encapsulated directly within a normal IP header, with no intermediate header, and unicast to the remote tunnel endpoint. + + /// + /// A packet is encapsulated directly within a normal IP header, with no intermediate header, and unicast to the remote tunnel endpoint. + /// TUNNEL_TYPE_DIRECT = 2, - /// An IPv6 packet is encapsulated directly within an IPv4 header, with no intermediate header, and unicast to the destination determined by the 6to4 protocol. + + /// + /// An IPv6 packet is encapsulated directly within an IPv4 header, with no intermediate header, and unicast to the destination + /// determined by the 6to4 protocol. + /// TUNNEL_TYPE_6TO4 = 11, - /// An IPv6 packet is encapsulated directly within an IPv4 header, with no intermediate header, and unicast to the destination determined by the ISATAP protocol. + + /// + /// An IPv6 packet is encapsulated directly within an IPv4 header, with no intermediate header, and unicast to the destination + /// determined by the ISATAP protocol. + /// TUNNEL_TYPE_ISATAP = 13, + /// Teredo encapsulation. TUNNEL_TYPE_TEREDO = 14, - /// Specifies that the tunnel uses IP over Hypertext Transfer Protocol Secure (HTTPS). This tunnel type is supported in Windows 7 and later versions of the Windows operating system. + + /// + /// Specifies that the tunnel uses IP over Hypertext Transfer Protocol Secure (HTTPS). This tunnel type is supported in Windows 7 + /// and later versions of the Windows operating system. + /// TUNNEL_TYPE_IPHTTPS = 15 } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] public enum UDP_TABLE_CLASS { [CorrespondingType(typeof(MIB_UDPTABLE), CorrepsondingAction.Get)] @@ -852,776 +1135,4682 @@ namespace Vanara.PInvoke UDP_TABLE_OWNER_MODULE, } - /// The AddIPAddress function adds the specified IPv4 address to the specified adapter. - /// The IPv4 address to add to the adapter, in the form of an IPAddr structure. - /// - /// The subnet mask for the IPv4 address specified in the Address parameter. The IPMask parameter uses the same format as an IPAddr structure. + /// + /// The AddIPAddress function adds the specified IPv4 address to the specified adapter. + /// + /// + /// The IPv4 address to add to the adapter, in the form of an IPAddr structure. + /// + /// + /// + /// The subnet mask for the IPv4 address specified in the Address parameter. The IPMask parameter uses the same format as an + /// IPAddr structure. + /// + /// + /// + /// The index of the adapter on which to add the IPv4 address. /// - /// The index of the adapter on which to add the IPv4 address. /// - /// A pointer to a ULONG variable. On successful return, this parameter points to the Net Table Entry (NTE) context for the IPv4 address that was added. - /// The caller can later use this context in a call to the DeleteIPAddress function. + /// + /// A pointer to a ULONG variable. On successful return, this parameter points to the Net Table Entry (NTE) context for the + /// IPv4 address that was added. The caller can later use this context in a call to the DeleteIPAddress function. + /// /// /// - /// A pointer to a ULONG variable. On successful return, this parameter points to the NTE instance for the IPv4 address that was added. + /// + /// A pointer to a ULONG variable. On successful return, this parameter points to the NTE instance for the IPv4 address that + /// was added. + /// /// - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// 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_DEV_NOT_EXIST + /// The adapter specified by the IfIndex parameter does not exist. + /// + /// + /// ERROR_DUP_DOMAINNAME + /// The IPv4 address to add that is specified in the Address parameter already exists. + /// + /// + /// ERROR_GEN_FAILURE + /// + /// A general failure. This error is returned for some values specified in the Address parameter, such as an IPv4 address normally + /// considered to be a broadcast addresses. + /// + /// + /// + /// ERROR_INVALID_HANDLE + /// The user attempting to make the function call is not an administrator. + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// One or more of the parameters is invalid. This error is returned if the NTEContext or NTEInstance parameters are NULL. This error + /// is also returned when the IP address specified in the Address parameter is inconsistent with the interface index specified in the + /// IfIndex parameter (for example, a loopback address on a non-loopback interface). + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// The function call is not supported on the version of Windows on which it was run. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The AddIPAddress function is used to add a new IPv4 address entry on a local computer. The IPv4 address added by the + /// AddIPAddress function is not persistent. The IPv4 address exists only as long as the adapter object exists. Restarting the + /// computer destroys the IPv4 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 commands can also be used to create a persistent IPv4 address. + /// + /// For more information, please see the documentation on Netsh.exe in the Windows Sockets documentation. + /// + /// On Windows Server 2003, Windows XP, and Windows 2000, if the IPv4 address in the Address parameter already exists on the network, + /// the AddIPAddress function returns NO_ERROR and the IPv4 address added is 0.0.0.0. + /// + /// + /// On Windows Vista and later, if the IPv4 address passed in the Address parameter already exists on the network, the + /// AddIPAddress function returns NO_ERROR and the duplicate IPv4 address is added with the IP_DAD_STATE member + /// in the IP_ADAPTER_UNICAST_ADDRESS structure set to IpDadStateDuplicate. + /// + /// + /// An IPv4 address that is added using the AddIPAddress function can later be deleted by calling the DeleteIPAddress function + /// passing the NTEContext parameter returned by the AddIPAddress function. + /// + /// + /// For information about the IPAddr and IPMask data types, see Windows Data Types. To convert an IPv4 address between + /// dotted decimal notation and IPAddr format, use the inet_addr and inet_ntoa functions. + /// + /// + /// On Windows Vista and later, the CreateUnicastIpAddressEntry function can be used to add a new unicast IPv4 or IPv6 address entry + /// on a local computer. + /// + /// Examples + /// + /// The following example retrieves the IP address table to determine the interface index for the first adapter, then adds the IP + /// address specified on command line to the first adapter. The IP address that was added is then deleted. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-addipaddress DWORD AddIPAddress( IPAddr Address, IPMask + // IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "669264cd-a43c-4681-9416-2704d4232685")] public static extern Win32Error AddIPAddress(IN_ADDR Address, IN_ADDR IpMask, uint IfIndex, out uint NTEContext, out uint NTEInstance); /// - /// The CancelIPChangeNotify function cancels notification of IPv4 address and route changes previously requested with successful calls to the - /// NotifyAddrChange or NotifyRouteChange functions. + /// + /// The CancelIPChangeNotify function cancels notification of IPv4 address and route changes previously requested with + /// successful calls to the NotifyAddrChange or NotifyRouteChange functions. + /// /// - /// A pointer to the OVERLAPPED structure used in the previous call to NotifyAddrChange or NotifyRouteChange. - /// The CancelIPChangeNotify can return FALSE if no notification request was found or an invalid notifyOverlapped parameter was passed. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// A pointer to the OVERLAPPED structure used in the previous call to NotifyAddrChange or NotifyRouteChange. + /// + /// + /// None + /// + /// + /// + /// The CancelIPChangeNotify function deregisters for a change notification previously requested for IPv4 address or route + /// changes on a local computer. These requests to register for notification are made by calling the NotifyAddrChange or + /// NotifyRouteChange functions. + /// + /// + /// The OVERLAPPED structure used in the previous call to one of these notification functions is passed to + /// CancelIPChangeNotify function in the notifyOverlapped parameter to deregister for notifications. + /// + /// + /// The CancelIPChangeNotify can return FALSE if no notification request was found or an invalid notifyOverlapped + /// parameter was passed. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-cancelipchangenotify BOOL CancelIPChangeNotify( + // LPOVERLAPPED notifyOverlapped ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "10795401-003f-45ce-80f1-ccc31659298a")] [return: MarshalAs(UnmanagedType.Bool)] public static extern unsafe bool CancelIPChangeNotify(System.Threading.NativeOverlapped* notifyOverlapped); - /// The CreateIpNetEntry function creates an Address Resolution Protocol (ARP) entry in the ARP table on the local computer. + /// + /// + /// The CreateIpNetEntry function creates an Address Resolution Protocol (ARP) entry in the ARP table on the local computer. + /// + /// /// - /// A pointer to a MIB_IPNETROW structure that specifies information for the new entry. The caller must specify values for all members of this structure. + /// + /// A pointer to a MIB_IPNETROW structure that specifies information for the new entry. The caller must specify values for all + /// members of this structure. + /// /// - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// The function returns NO_ERROR (zero) if the function is successful. + /// 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 on Windows Vista and Windows Server 2008 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 input parameter is invalid, no action was taken. This error is returned if the pArpEntry parameter is NULL, the dwPhysAddrLen + /// member of MIB_IPNETROW is set to zero or a value greater than 8, the >dwAddr member of the MIB_IPNETROW structure is invalid, + /// or one of the other members of the MIB_IPNETROW structure is invalid. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// The IPv4 transport is not configured on the local computer. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// To modify an existing ARP entry, use the SetIpNetEntry function. To retrieve the ARP table, call the GetIpNetTable function. To + /// delete an existing ARP entry, call the DeleteIpNetEntry. + /// + /// + /// On Windows Vista and later, the CreateIpNetEntry function can only be called by a user logged on as a member of the + /// Administrators group. If CreateIpNetEntry 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 CreateIpNetEntry function can also fail because of user account control (UAC) on Windows Vista 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. + /// + /// + /// Note On Windows NT 4.0 and Windows 2000 and later, this function executes a privileged operation. For this function to + /// execute successfully, the caller must be logged on as a member of the Administrators group or the NetworkConfigurationOperators group. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-createipnetentry DWORD CreateIpNetEntry( PMIB_IPNETROW + // pArpEntry ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "607f9aad-2046-4ab2-9a62-4092f87ffa66")] public static extern Win32Error CreateIpNetEntry(ref MIB_IPNETROW pArpEntry); - - /// The CreateIpNetEntry2 function creates a new neighbor IP address entry on the local computer. - /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + + /// + /// The CreateIpNetEntry2 function creates a new neighbor IP address entry on the local computer. + /// + /// + /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_ACCESS_DENIED + /// + /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required + /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in + /// Administrator (RunAs administrator). + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the + /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid unicast, anycast, or multicast IPv4 + /// or IPv6 address, the PhysicalAddress and PhysicalAddressLength members of the MIB_IPNET_ROW2 pointed to by the Row parameter were + /// not set to a valid physical address, or both the InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the + /// Row parameter were unspecified. This error is also returned if a loopback address was passed in the Address member. + /// + /// + /// + /// ERROR_NOT_FOUND + /// + /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or + /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified + /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter. This error is also returned if no IPv6 stack is on + /// the local computer and an IPv6 address was specified in the Address member. + /// + /// + /// + /// ERROR_OBJECT_ALREADY_EXISTS + /// + /// The object already exists. This error is returned if the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter is + /// a duplicate of an existing neighbor IP address on the interface specified by the InterfaceLuid or InterfaceIndex member of the MIB_IPNET_ROW2. + /// + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// The CreateIpNetEntry2 function is defined on Windows Vista and later. + /// The CreateIpNetEntry2 function is used to add a new neighbor IP address entry on a local computer. + /// + /// The Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid unicast, + /// anycast, or multicast IPv4 or IPv6 address and family. The PhysicalAddress and PhysicalAddressLength members in the + /// MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid physical address. In addition, at + /// least one of the following members in the MIB_IPNET_ROW2 structure pointed to the Row parameter must be initialized to the + /// interface: the InterfaceLuid or InterfaceIndex. + /// + /// + /// The CreateIpNetEntry2 function will fail if the IP address passed in the Address member of the MIB_IPNET_ROW2 + /// pointed to by the Row parameter is a duplicate of an existing neighbor IP address on the interface. + /// + /// + /// The CreateIpNetEntry2 function can only be called by a user logged on as a member of the Administrators group. If + /// CreateIpNetEntry2 is called by a user that is not a member of the Administrators group, the function call will fail and + /// ERROR_ACCESS_DENIED is returned. This function can also fail because of user account control (UAC) on Windows Vista and + /// later. If an application that contains this function is executed by a user logged on as a member of the Administrators group + /// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a + /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a + /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced + /// shell as the built-in Administrator (RunAs administrator) for this function to succeed. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-createipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API + // CreateIpNetEntry2( CONST MIB_IPNET_ROW2 *Row ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "ca92b9f8-ec3c-4889-b649-f606c3920f92")] public static extern Win32Error CreateIpNetEntry2(ref MIB_IPNET_ROW2 Row); - - /// The DeleteIPAddress function deletes an IP address previously added using AddIPAddress. - /// The Net Table Entry (NTE) context for the IP address. This context was returned by the previous call to AddIPAddress. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + + /// + /// The DeleteIPAddress function deletes an IP address previously added using AddIPAddress. + /// + /// + /// The Net Table Entry (NTE) context for the IP address. This context was returned by the previous call to AddIPAddress. + /// + /// + /// The function returns NO_ERROR (zero) if the function is successful. + /// 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 on Windows Vista and Windows Server 2008 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 input parameter is invalid, no action was taken. + /// + /// + /// ERROR_NOT_SUPPORTED + /// The IPv4 transport is not configured on the local computer. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// On Windows Vista and later, the DeleteIPAddress function can only be called by a user logged on as a member of the + /// Administrators group. If DeleteIPAddress 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 Windows Vista and later + /// 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. + /// + /// + /// Note On Windows NT 4.0 and Windows 2000 and later, this function executes a privileged operation. For this function to + /// execute successfully, the caller must be logged on as a member of the Administrators group or the NetworkConfigurationOperators group. + /// + /// Examples + /// + /// The following example retrieves the IP address table, then adds the IP address 192.168.0.27 to the first adapter. The IP address + /// that was added is then deleted. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-deleteipaddress DWORD DeleteIPAddress( ULONG NTEContext ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "d7ed986d-d62e-4723-ab74-85c3edfdf4ff")] public static extern Win32Error DeleteIPAddress(uint NTEContext); - /// The DeleteIpNetEntry function deletes an ARP entry from the ARP table on the local computer. - /// A pointer to a MIB_IPNETROW structure. The information in this structure specifies the entry to delete. The caller must specify values for at least the dwIndex and dwAddr members of this structure. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// The DeleteIpNetEntry function deletes an ARP entry from the ARP table on the local computer. + /// + /// + /// + /// A pointer to a MIB_IPNETROW structure. The information in this structure specifies the entry to delete. The caller must specify + /// values for at least the dwIndex and dwAddr members of this structure. + /// + /// + /// + /// The function returns NO_ERROR (zero) if the function is successful. + /// 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 on Windows Vista and Windows Server 2008 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 input parameter is invalid, no action was taken. This error is returned if the pArpEntry parameter is NULL or a member in the + /// MIB_IPNETROW structure pointed to by the pArpEntry parameter is invalid. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// The IPv4 transport is not configured on the local computer. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// To retrieve the ARP table, call the GetIpNetTable function. + /// + /// On Windows Vista and later, the DeleteIpNetEntry function can only be called by a user logged on as a member of the + /// Administrators group. If DeleteIpNetEntry 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 DeleteIpNetEntry 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. + /// + /// + /// Note On Windows NT 4.0 and Windows 2000 and later, this function executes a privileged operation. For this function to + /// execute successfully, the caller must be logged on as a member of the Administrators group or the NetworkConfigurationOperators group. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-deleteipnetentry DWORD DeleteIpNetEntry( PMIB_IPNETROW + // pArpEntry ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "0d338676-b66f-410c-8022-5576096954b4")] public static extern Win32Error DeleteIpNetEntry(ref MIB_IPNETROW pArpEntry); - /// The DeleteIpNetEntry2 function deletes a neighbor IP address entry on the local computer. - /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this entry will be deleted. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// The DeleteIpNetEntry2 function deletes a neighbor IP address entry on the local computer. + /// + /// + /// + /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this entry will be deleted. + /// + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_ACCESS_DENIED + /// + /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required + /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in + /// Administrator (RunAs administrator). + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the + /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid neighbor IPv4 or IPv6 address, or + /// both the InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the Row parameter were unspecified. + /// + /// + /// + /// ERROR_NOT_FOUND + /// + /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or + /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified + /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter. This error is also returned if no IPv6 stack is on + /// the local computer and an IPv6 address was specified in the Address member. + /// + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// The DeleteIpNetEntry2 function is defined on Windows Vista and later. + /// The DeleteIpNetEntry2 function is used to delete a MIB_IPNET_ROW2 structure entry. + /// + /// On input, the Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a + /// valid neighbor IPv4 or IPv6 address and family. In addition, at least one of the following members in the MIB_IPNET_ROW2 + /// structure pointed to the Row parameter must be initialized: the InterfaceLuid or InterfaceIndex. + /// + /// On output when the call is successful, DeleteIpNetEntry2 deletes the neighbor IP address. + /// The GetIpNetTable2 function can be called to enumerate the neighbor IP address entries on a local computer. + /// + /// The DeleteIpNetEntry2 function can only be called by a user logged on as a member of the Administrators group. If + /// DeleteIpNetEntry2 is called by a user that is not a member of the Administrators group, the function call will fail and + /// ERROR_ACCESS_DENIED is returned. This function can also fail because of user account control (UAC) on Windows Vista and + /// later. If an application that contains this function is executed by a user logged on as a member of the Administrators group + /// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a + /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a + /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced + /// shell as the built-in Administrator (RunAs administrator) for this function to succeed. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-deleteipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API + // DeleteIpNetEntry2( CONST MIB_IPNET_ROW2 *Row ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "85bace04-6c95-4cf2-a212-764de292aed6")] public static extern Win32Error DeleteIpNetEntry2(ref MIB_IPNET_ROW2 Row); /// - /// The EnableRouter function turns on IPv4 forwarding on the local computer. EnableRouter also increments a reference count that tracks the number of - /// requests to enable IPv4 forwarding. + /// + /// The EnableRouter function turns on IPv4 forwarding on the local computer. EnableRouter also increments a reference + /// count that tracks the number of requests to enable IPv4 forwarding. + /// /// - /// A pointer to a handle. This parameter is currently unused. - /// - /// A pointer to an OVERLAPPED structure. Except for the hEvent member, all members of this structure should be set to zero. The hEvent member should - /// contain a handle to a valid event object. Use the CreateEvent function to create this event object. + /// + /// A pointer to a handle. This parameter is currently unused. /// - /// If the EnableRouter function succeeds, the return value is ERROR_IO_PENDING. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] - public static extern unsafe Win32Error EnableRouter(IntPtr pHandle, System.Threading.NativeOverlapped* pOverlapped); + /// + /// + /// A pointer to an OVERLAPPED structure. Except for the hEvent member, all members of this structure should be set to zero. + /// The hEvent member should contain a handle to a valid event object. Use the CreateEvent function to create this event object. + /// + /// + /// + /// If the EnableRouter function succeeds, the return value is ERROR_IO_PENDING. + /// If the function fails, use FormatMessage to obtain the message string for the returned error. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_PARAMETER + /// One of the parameters is invalid. This error is returned if the pOverlapped parameter is NULL. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The EnableRouter function is specific to IPv4 forwarding. If the process that calls EnableRouter terminates without + /// calling UnenableRouter, the system decrements the reference count that tracks the number of requests to enable IPv4 forwarding as + /// though the process had called UnenableRouter. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-enablerouter DWORD EnableRouter( HANDLE *pHandle, + // OVERLAPPED *pOverlapped ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "779f5840-d58d-4194-baa7-2c6a7aeb7d79")] + public static extern unsafe Win32Error EnableRouter(ref IntPtr pHandle, System.Threading.NativeOverlapped* pOverlapped); - /// The FlushIpNetTable2 function flushes the IP neighbor table on the local computer. - /// The address family to flush. - /// 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 an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// The FlushIpNetTable2 function flushes the IP neighbor table on the local computer. + /// + /// + /// The address family to flush. + /// + /// Possible values for the address family are listed in the Winsock2.h header file. Note that the values for the AF_ address family + /// and PF_ protocol family constants are identical (for example, AF_INET and PF_INET), so either constant can be used. + /// + /// + /// On the Windows SDK released for Windows Vista and later, the organization of header files has changed and possible values for + /// this member are defined in the Ws2def.h header file. Note that the Ws2def.h header file is automatically included in Winsock2.h, + /// and should never be used directly. + /// + /// The values currently supported are AF_INET, AF_INET6, and AF_UNSPEC. + /// + /// + /// Value + /// Meaning + /// + /// + /// AF_UNSPEC 0 + /// + /// The address family is unspecified. When this parameter is specified, this function flushes the neighbor IP address table + /// containing both IPv4 and IPv6 entries. + /// + /// + /// + /// AF_INET 2 + /// + /// The Internet Protocol version 4 (IPv4) address family. When this parameter is specified, this function flushes the neighbor IP + /// address table containing only IPv4 entries. + /// + /// + /// + /// AF_INET6 23 + /// + /// The Internet Protocol version 6 (IPv6) address family. When this parameter is specified, this function flushes the neighbor IP + /// address table containing only IPv6 entries. + /// + /// + /// + /// + /// + /// + /// The interface index. If the index is specified, flush the neighbor IP address entries on a specific interface, otherwise flush + /// the neighbor IP address entries on all the interfaces. To ignore the interface, set this parameter to zero. + /// + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_ACCESS_DENIED + /// + /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required + /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in + /// Administrator (RunAs administrator). + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if the Family parameter was not specified as AF_INET, + /// AF_INET6, or AF_UNSPEC. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and AF_INET was specified in the + /// Family parameter. This error is also returned if no IPv6 stack is on the local computer and AF_INET6 was specified in the Family + /// parameter. This error is also returned on versions of Windows where this function is not supported. + /// + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// The FlushIpNetTable2 function is defined on Windows Vista and later. + /// + /// The FlushIpNetTable2 function flushes or deletes the neighbor IP addresses on a local system. The Family parameter can be + /// used to limit neighbor IP addresses to delete to a particular IP address family. If neighbor IP addresses for both IPv4 and IPv6 + /// should be deleted, set the Family parameter to AF_UNSPEC. The InterfaceIndex parameter can be used to limit neighbor IP + /// addresses to delete to a particular interface. If neighbor IP addresses for all interfaces should be deleted, set the + /// InterfaceIndex parameter to zero. + /// + /// The Family parameter must be initialized to either AF_INET, AF_INET6, or AF_UNSPEC. + /// + /// The FlushIpNetTable2 function can only be called by a user logged on as a member of the Administrators group. If + /// FlushIpNetTable2 is called by a user that is not a member of the Administrators group, the function call will fail and + /// ERROR_ACCESS_DENIED is returned. This function can also fail because of user account control (UAC) on Windows Vista and + /// later. If an application that contains this function is executed by a user logged on as a member of the Administrators group + /// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a + /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a + /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced + /// shell as the built-in Administrator (RunAs administrator) for this function to succeed. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-flushipnettable2 _NETIOAPI_SUCCESS_ NETIOAPI_API + // FlushIpNetTable2( ADDRESS_FAMILY Family, NET_IFINDEX InterfaceIndex ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "6ebfca41-acc3-450c-a3c5-881b8c3fca5e")] public static extern Win32Error FlushIpNetTable2(ADDRESS_FAMILY Family, uint InterfaceIndex); /// - /// The FreeMibTable function frees the buffer allocated by the functions that return tables of network interfaces, addresses, and routes (GetIfTable2 - /// and GetAnycastIpAddressTable, for example). + /// + /// 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. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// A pointer to the buffer to free. + /// + /// + /// This function does not return a value. + /// + /// + /// The FreeMibTable function is defined on Windows Vista and later. + /// + /// The FreeMibTable function is used to free the internal buffers used by various functions to retrieve tables of interfaces, + /// addresses, and routes. When these tables are no longer needed, then FreeMibTable should be called to release the memory + /// used by these tables. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-freemibtable VOID NETIOAPI_API_ FreeMibTable( PVOID + // Memory ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "31c8cdc4-73c7-4e82-8226-c90320046199")] public static extern void FreeMibTable(IntPtr Memory); - /// The GetAdapterIndex function obtains the index of an adapter, given its name. + /// The GetAdapterIndex function obtains the index of an adapter, given its name. /// A pointer to a Unicode string that specifies the name of the adapter. - /// A pointer to a ULONG variable that points to the index of the adapter. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// A pointer to a ULONG variable that points to the index of the adapter. + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, use FormatMessage to obtain the message string for the returned error. + /// + // DWORD GetAdapterIndex( _In_ LPWSTR AdapterName, _Inout_ PULONG IfIndex); https://msdn.microsoft.com/en-us/library/windows/desktop/aa365909(v=vs.85).aspx + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("IpHlpApi.h", MSDNShortId = "aa365909")] + // public static extern uint GetAdapterIndex([In] [MarshalAs(UnmanagedType.LPWStr)] StringBuilder AdapterName, [In, Out] ref uint IfIndex); public static extern Win32Error GetAdapterIndex([MarshalAs(UnmanagedType.LPWStr)] string AdapterName, out uint IfIndex); - /// The GetAdaptersAddresses function retrieves the addresses associated with the adapters on the local computer. - /// The address family of the addresses to retrieve. - /// The type of addresses to retrieve. If this parameter is zero, then unicast, anycast, and multicast IP addresses will be returned. - /// - /// This parameter is not currently used, but is reserved for future system use. The calling application should pass NULL for this parameter. + /// + /// The GetAdaptersAddresses function retrieves the addresses associated with the adapters on the local computer. + /// + /// + /// The address family of the addresses to retrieve. This parameter must be one of the following values. + /// + /// + /// Value + /// Meaning + /// + /// + /// AF_UNSPEC 0 + /// Return both IPv4 and IPv6 addresses associated with adapters with IPv4 or IPv6 enabled. + /// + /// + /// AF_INET 2 + /// Return only IPv4 addresses associated with adapters with IPv4 enabled. + /// + /// + /// AF_INET6 23 + /// Return only IPv6 addresses associated with adapters with IPv6 enabled. + /// + /// /// - /// A pointer to a buffer that contains a linked list of IP_ADAPTER_ADDRESSES structures on successful return. - /// A pointer to a variable that specifies the size of the buffer pointed to by AdapterAddresses. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// + /// The type of addresses to retrieve. The possible values are defined in the Iptypes.h header file. Note that the Iptypes.h header + /// file is automatically included in IpHlpApi.h, and should never be used directly. + /// + /// + /// This parameter is a combination of the following values. If this parameter is zero, then unicast, anycast, and multicast IP + /// addresses will be returned. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// GAA_FLAG_SKIP_UNICAST 0x0001 + /// Do not return unicast addresses. + /// + /// + /// GAA_FLAG_SKIP_ANYCAST 0x0002 + /// Do not return IPv6 anycast addresses. + /// + /// + /// GAA_FLAG_SKIP_MULTICAST 0x0004 + /// Do not return multicast addresses. + /// + /// + /// GAA_FLAG_SKIP_DNS_SERVER 0x0008 + /// Do not return addresses of DNS servers. + /// + /// + /// GAA_FLAG_INCLUDE_PREFIX 0x0010 + /// + /// Return a list of IP address prefixes on this adapter. When this flag is set, IP address prefixes are returned for both IPv6 and + /// IPv4 addresses. This flag is supported on Windows XP with SP1 and later. + /// + /// + /// + /// GAA_FLAG_SKIP_FRIENDLY_NAME 0x0020 + /// Do not return the adapter friendly name. + /// + /// + /// GAA_FLAG_INCLUDE_WINS_INFO 0x0040 + /// Return addresses of Windows Internet Name Service (WINS) servers. This flag is supported on Windows Vista and later. + /// + /// + /// GAA_FLAG_INCLUDE_GATEWAYS 0x0080 + /// Return the addresses of default gateways. This flag is supported on Windows Vista and later. + /// + /// + /// GAA_FLAG_INCLUDE_ALL_INTERFACES 0x0100 + /// Return addresses for all NDIS interfaces. This flag is supported on Windows Vista and later. + /// + /// + /// GAA_FLAG_INCLUDE_ALL_COMPARTMENTS 0x0200 + /// Return addresses in all routing compartments. This flag is not currently supported and reserved for future use. + /// + /// + /// GAA_FLAG_INCLUDE_TUNNEL_BINDINGORDER 0x0400 + /// Return the adapter addresses sorted in tunnel binding order. This flag is supported on Windows Vista and later. + /// + /// + /// + /// + /// + /// This parameter is not currently used, but is reserved for future system use. The calling application should pass NULL for + /// this parameter. + /// + /// + /// + /// A pointer to a buffer that contains a linked list of IP_ADAPTER_ADDRESSES structures on successful return. + /// + /// + /// A pointer to a variable that specifies the size of the buffer pointed to by AdapterAddresses. + /// + /// + /// If the function succeeds, the return value is ERROR_SUCCESS (defined to the same value as NO_ERROR). + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_ADDRESS_NOT_ASSOCIATED + /// An address has not yet been associated with the network endpoint. DHCP lease information was available. + /// + /// + /// ERROR_BUFFER_OVERFLOW + /// + /// The buffer size indicated by the SizePointer parameter is too small to hold the adapter information or the AdapterAddresses + /// parameter is NULL. The SizePointer parameter returned points to the required size of the buffer to hold the adapter information. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// One of the parameters is invalid. This error is returned for any of the following conditions: the SizePointer parameter is NULL, + /// the Address parameter is not AF_INET, AF_INET6, or AF_UNSPEC, or the address information for the parameters requested is greater + /// than ULONG_MAX. + /// + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// Insufficient memory resources are available to complete the operation. + /// + /// + /// ERROR_NO_DATA + /// No addresses were found for the requested parameters. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// The GetAdaptersAddresses function can retrieve information for IPv4 and IPv6 addresses. + /// + /// Addresses are returned as a linked list of IP_ADAPTER_ADDRESSES structures in the buffer pointed to by the AdapterAddresses + /// parameter. The application that calls the GetAdaptersAddresses function must allocate the amount of memory needed to + /// return the IP_ADAPTER_ADDRESSES structures pointed to by the AdapterAddresses parameter. When these returned structures + /// are no longer required, the application should free the memory allocated. This can be accomplished by calling the HeapAlloc + /// function to allocate memory and later calling the HeapFree function to free the allocated memory, as shown in the example code. + /// Other memory allocation and free functions can be used as long as the same family of functions are used for both the allocation + /// and the free function. + /// + /// + /// GetAdaptersAddresses is implemented only as a synchronous function call. The GetAdaptersAddresses function requires + /// a significant amount of network resources and time to complete since all of the low-level network interface tables must be traversed. + /// + /// + /// One method that can be used to determine the memory needed to return the IP_ADAPTER_ADDRESSES structures pointed to by the + /// AdapterAddresses parameter is to pass too small a buffer size as indicated in the SizePointer parameter in the first call to the + /// GetAdaptersAddresses function, so the function will fail with ERROR_BUFFER_OVERFLOW. When the return value is + /// ERROR_BUFFER_OVERFLOW, the SizePointer parameter returned points to the required size of the buffer to hold the adapter + /// information. Note that it is possible for the buffer size required for the IP_ADAPTER_ADDRESSES structures pointed to by + /// the AdapterAddresses parameter to change between subsequent calls to the GetAdaptersAddresses function if an adapter + /// address is added or removed. However, this method of using the GetAdaptersAddresses function is strongly discouraged. This + /// method requires calling the GetAdaptersAddresses function multiple times. + /// + /// + /// The recommended method of calling the GetAdaptersAddresses function is to pre-allocate a 15KB working buffer pointed to by + /// the AdapterAddresses parameter. On typical computers, this dramatically reduces the chances that the GetAdaptersAddresses + /// function returns ERROR_BUFFER_OVERFLOW, which would require calling GetAdaptersAddresses function multiple times. + /// The example code illustrates this method of use. + /// + /// + /// In versions prior to Windows 10, the order in which adapters appear in the list returned by this function can be controlled from + /// the Network Connections folder: select the Advanced Settings menu item from the Advanced menu. Starting with Windows 10, the + /// order in which adapters appear in the list is determined by the IPv4 or IPv6 route metric. + /// + /// + /// If the GAA_FLAG_INCLUDE_ALL_INTERFACES is set, then all NDIS adapters will be retrieved even those addresses associated with + /// adapters not bound to an address family specified in the Family parameter. When this flag is not set, then only the addresses + /// that are bound to an adapter enabled for the address family specified in the Family parameter are returned. + /// + /// + /// The size of the IP_ADAPTER_ADDRESSESstructure was changed on Windows XP with Service Pack 1 (SP1) and later. Several additional + /// members were added to this structure. The size of the IP_ADAPTER_ADDRESSES structure was also changed on Windows Vista and + /// later. A number of additional members were added to this structure. The size of the IP_ADAPTER_ADDRESSES structure also + /// changed on Windows Vista with Service Pack 1 (SP1)and later and onWindows Server 2008 and later. One additional member was added + /// to this structure. The Length member of the IP_ADAPTER_ADDRESSES structure returned in the linked list of + /// structures in the buffer pointed to by the AdapterAddresses parameter should be used to determine which version of the + /// IP_ADAPTER_ADDRESSES structure is being used. + /// + /// + /// The GetIpAddrTable function retrieves the interface–to–IPv4 address mapping table on a local computer and returns this + /// information in an MIB_IPADDRTABLE structure. + /// + /// + /// On the Platform Software Development Kit (SDK) released for Windows Server 2003 and earlier, the return value for the + /// GetAdaptersAddresses function was defined as a DWORD, rather than a ULONG. + /// + /// + /// The SOCKET_ADDRESS structure is used in the IP_ADAPTER_ADDRESSES structure pointed to by the AdapterAddresses parameter. On the + /// Microsoft Windows Software Development Kit (SDK) released for Windows Vista and later, the organization of header files has + /// changed and the SOCKET_ADDRESS structure is defined in the Ws2def.h header file which is automatically included by the + /// Winsock2.h header file. On the Platform SDK released for Windows Server 2003 and Windows XP, the SOCKET_ADDRESS structure + /// is declared in the Winsock2.h header file. In order to use the IP_ADAPTER_ADDRESSES structure, the Winsock2.h header file + /// must be included before the IpHlpApi.h header file. + /// + /// Examples + /// + /// This example retrieves the IP_ADAPTER_ADDRESSES structure for the adapters associated with the system and prints some members for + /// each adapter interface. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getadaptersaddresses ULONG GetAdaptersAddresses( ULONG + // Family, ULONG Flags, PVOID Reserved, PIP_ADAPTER_ADDRESSES AdapterAddresses, PULONG SizePointer ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "7b34138f-7263-4b73-95df-9e854fd81135")] public static extern Win32Error GetAdaptersAddresses(uint Family, GetAdaptersAddressesFlags Flags, IntPtr Reserved, IntPtr pAdapterAddresses, ref uint pOutBufLen); - /// The GetAdaptersAddresses function retrieves the addresses associated with the adapters on the local computer. - /// The type of addresses to retrieve. If this parameter is zero, then unicast, anycast, and multicast IP addresses will be returned. + /// The GetAdaptersAddresses function retrieves the addresses associated with the adapters on the local computer. + /// + /// The type of addresses to retrieve. If this parameter is zero, then unicast, anycast, and multicast IP addresses will be returned. + /// /// The address family of the addresses to retrieve. /// A list of IP_ADAPTER_ADDRESSES structures on successful return. public static IEnumerable GetAdaptersAddresses(GetAdaptersAddressesFlags Flags = 0, ADDRESS_FAMILY Family = ADDRESS_FAMILY.AF_UNSPEC) { uint len = 0; - var e = GetAdaptersAddresses((uint)Family, Flags, IntPtr.Zero, IntPtr.Zero, ref len); - if (e != Win32Error.ERROR_BUFFER_OVERFLOW) e.ThrowIfFailed(); - var mem = new SafeCoTaskMemHandle((int)len); + Win32Error e = GetAdaptersAddresses((uint)Family, Flags, IntPtr.Zero, IntPtr.Zero, ref len); + if (e != Win32Error.ERROR_BUFFER_OVERFLOW) + { + e.ThrowIfFailed(); + } + + SafeCoTaskMemHandle mem = new SafeCoTaskMemHandle((int)len); GetAdaptersAddresses((uint)Family, Flags, IntPtr.Zero, (IntPtr)mem, ref len).ThrowIfFailed(); return mem.DangerousGetHandle().LinkedListToIEnum(t => t.Next); } - /// The GetAdaptersInfo function retrieves adapter information for the local computer. - /// A pointer to a buffer that receives a linked list of IP_ADAPTER_INFO structures. - /// - /// A pointer to a ULONG variable that specifies the size of the buffer pointed to by the pAdapterInfo parameter. If this size is insufficient to hold - /// the adapter information, GetAdaptersInfo fills in this variable with the required size, and returns an error code of ERROR_BUFFER_OVERFLOW. + /// + /// The GetAdaptersInfo function retrieves adapter information for the local computer. + /// On Windows XP and later: Use the GetAdaptersAddresses function instead of GetAdaptersInfo. + /// + /// + /// A pointer to a buffer that receives a linked list of IP_ADAPTER_INFO structures. /// - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// + /// A pointer to a ULONG variable that specifies the size of the buffer pointed to by the pAdapterInfo parameter. If this size + /// is insufficient to hold the adapter information, GetAdaptersInfo fills in this variable with the required size, and + /// returns an error code of ERROR_BUFFER_OVERFLOW. + /// + /// + /// + /// If the function succeeds, the return value is ERROR_SUCCESS (defined to the same value as NO_ERROR). + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_BUFFER_OVERFLOW + /// + /// The buffer to receive the adapter information is too small. This value is returned if the buffer size indicated by the pOutBufLen + /// parameter is too small to hold the adapter information or the pAdapterInfo parameter was a NULL pointer. When this error code is + /// returned, the pOutBufLen parameter points to the required buffer size. + /// + /// + /// + /// ERROR_INVALID_DATA + /// Invalid adapter information was retrieved. + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// One of the parameters is invalid. This error is returned if the pOutBufLen parameter is a NULL pointer, or the calling process + /// does not have read/write access to the memory pointed to by pOutBufLen or the calling process does not have write access to the + /// memory pointed to by the pAdapterInfo parameter. + /// + /// + /// + /// ERROR_NO_DATA + /// No adapter information exists for the local computer. + /// + /// + /// ERROR_NOT_SUPPORTED + /// The GetAdaptersInfo function is not supported by the operating system running on the local computer. + /// + /// + /// Other + /// If the function fails, use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// The GetAdaptersInfo function can retrieve information only for IPv4 addresses. + /// + /// In versions prior to Windows 10, the order in which adapters appear in the list returned by this function can be controlled from + /// the Network Connections folder: select the Advanced Settings menu item from the Advanced menu. Starting with Windows 10, the + /// order is unspecified. + /// + /// + /// The GetAdaptersInfo and GetInterfaceInfo functions do not return information about the IPv4 loopback interface. + /// Information on the loopback interface is returned by the GetIpAddrTable function. + /// + /// + /// On Windows XP and later: The list of adapters returned by GetAdaptersInfo includes unidirectional adapters. To + /// generate a list of adapters that can both send and receive data, call GetUniDirectionalAdapterInfo, and exclude the returned + /// adapters from the list returned by GetAdaptersInfo. + /// + /// Examples + /// This example retrieves the adapter information and prints various properties of each adapter. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getadaptersinfo ULONG GetAdaptersInfo( PIP_ADAPTER_INFO + // AdapterInfo, PULONG SizePointer ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "8cdecc84-6566-438b-86d0-3c55490a9a59")] [Obsolete("On Windows XP and later: Use the GetAdaptersAddresses function instead of GetAdaptersInfo.")] public static extern Win32Error GetAdaptersInfo(IntPtr pAdapterInfo, ref uint pBufOutLen); - /// The GetBestInterface function retrieves the index of the interface that has the best route to the specified IPv4 address. - /// The destination IPv4 address for which to retrieve the interface that has the best route, in the form of an IPAddr structure. - /// - /// A pointer to a DWORD variable that receives the index of the interface that has the best route to the IPv4 address specified by dwDestAddr. + /// + /// + /// The GetBestInterface function retrieves the index of the interface that has the best route to the specified IPv4 address. + /// + /// + /// + /// The destination IPv4 address for which to retrieve the interface that has the best route, in the form of an IPAddr structure. /// - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// + /// A pointer to a DWORD variable that receives the index of the interface that has the best route to the IPv4 address + /// specified by dwDestAddr. + /// + /// + /// + /// 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_CAN_NOT_COMPLETE + /// The operation could not be completed. + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the pdwBestIfIndex + /// parameter or if the pdwBestIfIndex points to memory that cannot be written. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// The request is not supported. This error is returned if no IPv4 stack is on the local computer. + /// + /// + /// Other + /// Use the FormatMessage function to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The GetBestInterface function only works with IPv4 addresses. For use with IPv6 addresses, the GetBestInterfaceEx must be used. + /// + /// + /// For information about the IPAddr data type, see Windows Data Types. To convert an IP address between dotted decimal + /// notation and IPAddr format, use the inet_addr and inet_ntoa functions. + /// + /// + /// On Windows Vista and later, the pdwBestIfIndex parameter is treated internally by IP Helper as a pointer to a NET_IFINDEX datatype. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getbestinterface DWORD GetBestInterface( IPAddr + // dwDestAddr, PDWORD pdwBestIfIndex ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "9171cdf7-4057-4a8d-a34c-1b7b1f94bcb1")] public static extern Win32Error GetBestInterface(IN_ADDR dwDestAddr, out uint pdwBestIfIndex); - /// The GetBestInterfaceEx function retrieves the index of the interface that has the best route to the specified IPv4 or IPv6 address. - /// The destination IPv6 or IPv4 address for which to retrieve the interface with the best route, in the form of a byte array. - /// A pointer to the index of the interface with the best route to the IPv6 or IPv4 address specified by pDestAddr. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// + /// The GetBestInterfaceEx function retrieves the index of the interface that has the best route to the specified IPv4 or IPv6 address. + /// + /// + /// + /// + /// The destination IPv6 or IPv4 address for which to retrieve the interface with the best route, in the form of a sockaddr structure. + /// + /// + /// + /// A pointer to the index of the interface with the best route to the IPv6 or IPv4 address specified by pDestAddr. + /// + /// + /// 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_CAN_NOT_COMPLETE + /// The operation could not be completed. + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the pdwBestIfIndex + /// parameter or if the pDestAddr or pdwBestIfIndex parameters point to memory that cannot be accessed. This error can also be + /// returned if the pdwBestIfIndex parameter points to memory that can't be written to. + /// + /// + /// + /// 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 pDestAddr parameter or no IPv6 stack is on the local computer and an IPv6 address was specified in the pDestAddr parameter. + /// + /// + /// + /// Other + /// Use the FormatMessage function to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The GetBestInterfaceEx function differs from the GetBestInterface function in that it can be used with either IPv4 or IPv6 addresses. + /// + /// + /// The Family member of the sockaddr structure pointed to by the pDestAddr parameter must be set to one of the following + /// values: AF_INET or AF_INET6. + /// + /// + /// On Windows Vista and later, the pdwBestIfIndex parameter is treated internally by IP Helper as a pointer to a NET_IFINDEX datatype. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getbestinterfaceex DWORD GetBestInterfaceEx( sockaddr + // *pDestAddr, PDWORD pdwBestIfIndex ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "cfd1108e-d7a0-4fe5-be3f-299189089d37")] public static extern Win32Error GetBestInterfaceEx(SOCKADDR pDestAddr, out uint pdwBestIfIndex); - /// The GetBestRoute function retrieves the best route to the specified destination IP address. - /// Destination IP address for which to obtain the best route. - /// Source IP address. This IP address corresponds to an interface on the local computer. If multiple best routes to the destination address exist, the function selects the route that uses this interface. - /// Pointer to a MIB_IPFORWARDROW structure containing the best route for the IP address specified by dwDestAddr. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// The GetBestRoute function retrieves the best route to the specified destination IP address. + /// + /// + /// Destination IP address for which to obtain the best route. + /// + /// + /// + /// Source IP address. This IP address corresponds to an interface on the local computer. If multiple best routes to the destination + /// address exist, the function selects the route that uses this interface. + /// + /// This parameter is optional. The caller may specify zero for this parameter. + /// + /// + /// Pointer to a MIB_IPFORWARDROW structure containing the best route for the IP address specified by dwDestAddr. + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, use FormatMessage to obtain the message string for the returned error. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getbestroute DWORD GetBestRoute( DWORD dwDestAddr, DWORD + // dwSourceAddr, PMIB_IPFORWARDROW pBestRoute ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "5e507d14-f603-467d-9c37-bb048658d0b1")] public static extern Win32Error GetBestRoute(IN_ADDR dwDestAddr, [Optional] IN_ADDR dwSourceAddr, out MIB_IPFORWARDROW pBestRoute); - /// The GetBestRoute2 function retrieves the IP route entry on the local computer for the best route to the specified destination IP address. - /// The locally unique identifier (LUID) to specify the network interface associated with an IP route entry. - /// The local index value to specify the network interface associated with an IP route entry. This index value may change when a network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent. - /// The source IP address. This parameter may be omitted and passed as a NULL pointer. - /// The destination IP address. - /// A set of options that affect how IP addresses are sorted. This parameter is not currently used. - /// A pointer to the MIB_IPFORWARD_ROW2 for the best route from the source IP address to the destination IP address. - /// A pointer to the best source IP address. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// + /// The GetBestRoute2 function retrieves the IP route entry on the local computer for the best route to the specified + /// destination IP address. + /// + /// + /// + /// The locally unique identifier (LUID) to specify the network interface associated with an IP route entry. + /// + /// + /// + /// The local index value to specify the network interface associated with an IP route entry. This index value may change when a + /// network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent. + /// + /// + /// + /// The source IP address. This parameter may be omitted and passed as a NULL pointer. + /// + /// + /// The destination IP address. + /// + /// + /// A set of options that affect how IP addresses are sorted. This parameter is not currently used. + /// + /// + /// A pointer to the MIB_IPFORWARD_ROW2 for the best route from the source IP address to the destination IP address. + /// + /// + /// A pointer to the best source IP address. + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the DestinationAddress, + /// BestSourceAddress, or the BestRoute parameter. This error is also returned if the DestinationAddress parameter does not specify + /// an IPv4 or IPv6 address and family. + /// + /// + /// + /// ERROR_FILE_NOT_FOUND + /// + /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or + /// InterfaceIndex parameter could not be found. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address and family was + /// specified in the DestinationAddress parameter. This error is also returned if no IPv6 stack is on the local computer and an IPv6 + /// address and family was specified in the DestinationAddress parameter. + /// + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// The GetBestRoute2 function is defined on Windows Vista and later. + /// + /// The GetBestRoute2 function is used to retrieve a MIB_IPFORWARD_ROW2 structure entry for the best route from a source IP + /// address to a destination IP address. + /// + /// + /// On input, the DestinationAddress parameter must be initialized to a valid IPv4 or IPv6 address and family. On input, the + /// SourceAddress parameter may be initialized to the preferred IPv4 or IPv6 address and family. In addition, at least one of the + /// following parameters must be initialized: the InterfaceLuid or InterfaceIndex. + /// + /// + /// On output when the call is successful, GetBestRoute2 retrieves and MIB_IPFORWARD_ROW2 structure for the best route from + /// the source IP address the destination IP address. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getbestroute2 _NETIOAPI_SUCCESS_ NETIOAPI_API + // GetBestRoute2( NET_LUID *InterfaceLuid, NET_IFINDEX InterfaceIndex, CONST SOCKADDR_INET *SourceAddress, CONST SOCKADDR_INET + // *DestinationAddress, ULONG AddressSortOptions, PMIB_IPFORWARD_ROW2 BestRoute, SOCKADDR_INET *BestSourceAddress ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "7bc16824-c98f-4cd5-a589-e198b48b637c")] public static extern Win32Error GetBestRoute2(ref NET_LUID InterfaceLuid, uint InterfaceIndex, ref SOCKADDR_INET SourceAddress, ref SOCKADDR_INET DestinationAddress, uint AddressSortOptions, out MIB_IPFORWARD_ROW2 BestRoute, out SOCKADDR_INET BestSourceAddress); - /// The GetBestRoute2 function retrieves the IP route entry on the local computer for the best route to the specified destination IP address. - /// The locally unique identifier (LUID) to specify the network interface associated with an IP route entry. - /// The local index value to specify the network interface associated with an IP route entry. This index value may change when a network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent. - /// The source IP address. This parameter may be omitted and passed as a NULL pointer. - /// The destination IP address. - /// A set of options that affect how IP addresses are sorted. This parameter is not currently used. - /// A pointer to the MIB_IPFORWARD_ROW2 for the best route from the source IP address to the destination IP address. - /// A pointer to the best source IP address. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// + /// The GetBestRoute2 function retrieves the IP route entry on the local computer for the best route to the specified + /// destination IP address. + /// + /// + /// + /// The locally unique identifier (LUID) to specify the network interface associated with an IP route entry. + /// + /// + /// + /// The local index value to specify the network interface associated with an IP route entry. This index value may change when a + /// network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent. + /// + /// + /// + /// The source IP address. This parameter may be omitted and passed as a NULL pointer. + /// + /// + /// The destination IP address. + /// + /// + /// A set of options that affect how IP addresses are sorted. This parameter is not currently used. + /// + /// + /// A pointer to the MIB_IPFORWARD_ROW2 for the best route from the source IP address to the destination IP address. + /// + /// + /// A pointer to the best source IP address. + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the DestinationAddress, + /// BestSourceAddress, or the BestRoute parameter. This error is also returned if the DestinationAddress parameter does not specify + /// an IPv4 or IPv6 address and family. + /// + /// + /// + /// ERROR_FILE_NOT_FOUND + /// + /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or + /// InterfaceIndex parameter could not be found. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address and family was + /// specified in the DestinationAddress parameter. This error is also returned if no IPv6 stack is on the local computer and an IPv6 + /// address and family was specified in the DestinationAddress parameter. + /// + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// The GetBestRoute2 function is defined on Windows Vista and later. + /// + /// The GetBestRoute2 function is used to retrieve a MIB_IPFORWARD_ROW2 structure entry for the best route from a source IP + /// address to a destination IP address. + /// + /// + /// On input, the DestinationAddress parameter must be initialized to a valid IPv4 or IPv6 address and family. On input, the + /// SourceAddress parameter may be initialized to the preferred IPv4 or IPv6 address and family. In addition, at least one of the + /// following parameters must be initialized: the InterfaceLuid or InterfaceIndex. + /// + /// + /// On output when the call is successful, GetBestRoute2 retrieves and MIB_IPFORWARD_ROW2 structure for the best route from + /// the source IP address the destination IP address. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getbestroute2 _NETIOAPI_SUCCESS_ NETIOAPI_API + // GetBestRoute2( NET_LUID *InterfaceLuid, NET_IFINDEX InterfaceIndex, CONST SOCKADDR_INET *SourceAddress, CONST SOCKADDR_INET + // *DestinationAddress, ULONG AddressSortOptions, PMIB_IPFORWARD_ROW2 BestRoute, SOCKADDR_INET *BestSourceAddress ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "7bc16824-c98f-4cd5-a589-e198b48b637c")] public static extern Win32Error GetBestRoute2(IntPtr InterfaceLuid, uint InterfaceIndex, ref SOCKADDR_INET SourceAddress, ref SOCKADDR_INET DestinationAddress, uint AddressSortOptions, out MIB_IPFORWARD_ROW2 BestRoute, out SOCKADDR_INET BestSourceAddress); - /// The GetBestRoute2 function retrieves the IP route entry on the local computer for the best route to the specified destination IP address. - /// The locally unique identifier (LUID) to specify the network interface associated with an IP route entry. - /// The local index value to specify the network interface associated with an IP route entry. This index value may change when a network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent. - /// The source IP address. This parameter may be omitted and passed as a NULL pointer. - /// The destination IP address. - /// A set of options that affect how IP addresses are sorted. This parameter is not currently used. - /// A pointer to the MIB_IPFORWARD_ROW2 for the best route from the source IP address to the destination IP address. - /// A pointer to the best source IP address. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// + /// The GetBestRoute2 function retrieves the IP route entry on the local computer for the best route to the specified + /// destination IP address. + /// + /// + /// + /// The locally unique identifier (LUID) to specify the network interface associated with an IP route entry. + /// + /// + /// + /// The local index value to specify the network interface associated with an IP route entry. This index value may change when a + /// network adapter is disabled and then enabled, or under other circumstances, and should not be considered persistent. + /// + /// + /// + /// The source IP address. This parameter may be omitted and passed as a NULL pointer. + /// + /// + /// The destination IP address. + /// + /// + /// A set of options that affect how IP addresses are sorted. This parameter is not currently used. + /// + /// + /// A pointer to the MIB_IPFORWARD_ROW2 for the best route from the source IP address to the destination IP address. + /// + /// + /// A pointer to the best source IP address. + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the DestinationAddress, + /// BestSourceAddress, or the BestRoute parameter. This error is also returned if the DestinationAddress parameter does not specify + /// an IPv4 or IPv6 address and family. + /// + /// + /// + /// ERROR_FILE_NOT_FOUND + /// + /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or + /// InterfaceIndex parameter could not be found. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address and family was + /// specified in the DestinationAddress parameter. This error is also returned if no IPv6 stack is on the local computer and an IPv6 + /// address and family was specified in the DestinationAddress parameter. + /// + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// The GetBestRoute2 function is defined on Windows Vista and later. + /// + /// The GetBestRoute2 function is used to retrieve a MIB_IPFORWARD_ROW2 structure entry for the best route from a source IP + /// address to a destination IP address. + /// + /// + /// On input, the DestinationAddress parameter must be initialized to a valid IPv4 or IPv6 address and family. On input, the + /// SourceAddress parameter may be initialized to the preferred IPv4 or IPv6 address and family. In addition, at least one of the + /// following parameters must be initialized: the InterfaceLuid or InterfaceIndex. + /// + /// + /// On output when the call is successful, GetBestRoute2 retrieves and MIB_IPFORWARD_ROW2 structure for the best route from + /// the source IP address the destination IP address. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getbestroute2 _NETIOAPI_SUCCESS_ NETIOAPI_API + // GetBestRoute2( NET_LUID *InterfaceLuid, NET_IFINDEX InterfaceIndex, CONST SOCKADDR_INET *SourceAddress, CONST SOCKADDR_INET + // *DestinationAddress, ULONG AddressSortOptions, PMIB_IPFORWARD_ROW2 BestRoute, SOCKADDR_INET *BestSourceAddress ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "7bc16824-c98f-4cd5-a589-e198b48b637c")] public static extern Win32Error GetBestRoute2(IntPtr InterfaceLuid, uint InterfaceIndex, IntPtr SourceAddress, ref SOCKADDR_INET DestinationAddress, uint AddressSortOptions, out MIB_IPFORWARD_ROW2 BestRoute, out SOCKADDR_INET BestSourceAddress); - /// The GetExtendedTcpTable function retrieves a table that contains a list of TCP endpoints available to the application. + /// + /// The GetExtendedTcpTable function retrieves a table that contains a list of TCP endpoints available to the application. + /// /// - /// A pointer to the table structure that contains the filtered TCP endpoints available to the application. For information about how to determine the - /// type of table returned based on specific input parameter combinations, see the Remarks section later in this document. + /// + /// A pointer to the table structure that contains the filtered TCP endpoints available to the application. For information about how + /// to determine the type of table returned based on specific input parameter combinations, see the Remarks section later in this document. + /// /// - /// - /// The estimated size of the structure returned in pTcpTable, in bytes. If this value is set too small, ERROR_INSUFFICIENT_BUFFER is returned by this - /// function, and this field will contain the correct size of the structure. + /// + /// + /// The estimated size of the structure returned in pTcpTable, in bytes. If this value is set too small, + /// ERROR_INSUFFICIENT_BUFFER is returned by this function, and this field will contain the correct size of the structure. + /// /// /// - /// A value that specifies whether the TCP connection table should be sorted. If this parameter is set to TRUE, the TCP endpoints in the table are sorted - /// in ascending order, starting with the lowest local IP address. If this parameter is set to FALSE, the TCP endpoints in the table appear in the order - /// in which they were retrieved. + /// + /// A value that specifies whether the TCP connection table should be sorted. If this parameter is set to TRUE, the TCP + /// endpoints in the table are sorted in ascending order, starting with the lowest local IP address. If this parameter is set to + /// FALSE, the TCP endpoints in the table appear in the order in which they were retrieved. + /// + /// The following values are compared (as listed) when ordering the TCP endpoints: + /// + /// + /// Local IP address + /// + /// + /// Local scope ID (applicable when the ulAf parameter is set to AF_INET6) + /// + /// + /// Local TCP port + /// + /// + /// Remote IP address + /// + /// + /// Remote scope ID (applicable when the ulAf parameter is set to AF_INET6) + /// + /// + /// Remote TCP port + /// + /// + /// + /// + /// The version of IP used by the TCP endpoints. + /// + /// + /// Value + /// Meaning + /// + /// + /// AF_INET + /// IPv4 is used. + /// + /// + /// AF_INET6 + /// IPv6 is used. + /// + /// /// - /// The version of IP used by the TCP endpoints. /// - /// The type of the TCP table structure to retrieve. This parameter can be one of the values from the TCP_TABLE_CLASS enumeration. - /// The TCP_TABLE_CLASS enumeration value is combined with the value of the ulAf parameter to determine the extended TCP information to retrieve. + /// The type of the TCP table structure to retrieve. This parameter can be one of the values from the TCP_TABLE_CLASS enumeration. + /// + /// On the Windows SDK released for Windows Vista and later, the organization of header files has changed and the TCP_TABLE_CLASS + /// enumeration is defined in the Iprtrmib.h header file, not in the IpHlpApi.h header file. + /// + /// + /// The TCP_TABLE_CLASS enumeration value is combined with the value of the ulAf parameter to determine the extended TCP information + /// to retrieve. + /// /// - /// Reserved. This value must be zero. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// Reserved. This value must be zero. + /// + /// + /// If the call is successful, the value NO_ERROR is returned. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INSUFFICIENT_BUFFER + /// + /// An insufficient amount of space was allocated for the table. The size of the table is returned in the pdwSize parameter, and must + /// be used in a subsequent call to this function in order to successfully retrieve the table. This error is also returned if the + /// pTcpTable parameter is NULL. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if the TableClass parameter contains a value that is not + /// defined in the TCP_TABLE_CLASS enumeration. + /// + /// + /// + /// + /// + /// + /// The table type returned by this function depends on the specific combination of the ulAf parameter and the TableClass parameter. + /// + /// + /// When the ulAf parameter is set to AF_INET, the following table indicates the TCP table type to retrieve in the structure + /// pointed to by the pTcpTable parameter for each possible TableClass value. + /// + /// + /// + /// TableClass value + /// pTcpTable structure + /// + /// + /// TCP_TABLE_BASIC_ALL + /// MIB_TCPTABLE + /// + /// + /// TCP_TABLE_BASIC_CONNECTIONS + /// MIB_TCPTABLE + /// + /// + /// TCP_TABLE_BASIC_LISTENER + /// MIB_TCPTABLE + /// + /// + /// TCP_TABLE_OWNER_MODULE_ALL + /// MIB_TCPTABLE_OWNER_MODULE + /// + /// + /// TCP_TABLE_OWNER_MODULE_CONNECTIONS + /// MIB_TCPTABLE_OWNER_MODULE + /// + /// + /// TCP_TABLE_OWNER_MODULE_LISTENER + /// MIB_TCPTABLE_OWNER_MODULE + /// + /// + /// TCP_TABLE_OWNER_PID_ALL + /// MIB_TCPTABLE_OWNER_PID + /// + /// + /// TCP_TABLE_OWNER_PID_CONNECTIONS + /// MIB_TCPTABLE_OWNER_PID + /// + /// + /// TCP_TABLE_OWNER_PID_LISTENER + /// MIB_TCPTABLE_OWNER_PID + /// + /// + /// + /// When the ulAf parameter is set to AF_INET6, the following table indicates the TCP table type to retrieve in the structure + /// pointed to by the pTcpTable parameter for each possible TableClass value. + /// + /// + /// + /// TableClass value + /// pTcpTable structure + /// + /// + /// TCP_TABLE_OWNER_MODULE_ALL + /// MIB_TCP6TABLE_OWNER_MODULE + /// + /// + /// TCP_TABLE_OWNER_MODULE_CONNECTIONS + /// MIB_TCP6TABLE_OWNER_MODULE + /// + /// + /// TCP_TABLE_OWNER_MODULE_LISTENER + /// MIB_TCP6TABLE_OWNER_MODULE + /// + /// + /// TCP_TABLE_OWNER_PID_ALL + /// MIB_TCP6TABLE_OWNER_PID + /// + /// + /// TCP_TABLE_OWNER_PID_CONNECTIONS + /// MIB_TCP6TABLE_OWNER_PID + /// + /// + /// TCP_TABLE_OWNER_PID_LISTENER + /// MIB_TCP6TABLE_OWNER_PID + /// + /// + /// + /// The GetExtendedTcpTable function called with the ulAf parameter set to AF_INET6 and the TableClass set to + /// TCP_TABLE_BASIC_LISTENER, TCP_TABLE_BASIC_CONNECTIONS, or TCP_TABLE_BASIC_ALL is not supported and returns ERROR_NOT_SUPPORTED. + /// + /// + /// On the Windows SDK released for Windows Vistaand later, the organization of header files has changed. The various MIB_TCPTABLE + /// structures are defined in the Tcpmib.h header file, not in the Iprtrmib.h header file. Note that the Tcpmib.h header file is + /// automatically included in Iprtrmib.h, which is automatically included in the IpHlpApi.h header file. The Tcpmib.h and Iprtrmib.h + /// header files should never be used directly. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getextendedtcptable DWORD GetExtendedTcpTable( PVOID + // pTcpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, TCP_TABLE_CLASS TableClass, ULONG Reserved ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "96356a0e-ae0d-4000-9223-a578cbdeaa8b")] public static extern Win32Error GetExtendedTcpTable(IntPtr pTcpTable, ref uint dwOutBufLen, [MarshalAs(UnmanagedType.Bool)] bool bOrder, uint ulAf, TCP_TABLE_CLASS TableClass, uint Reserved = 0); /// The GetExtendedTcpTable function retrieves a table that contains a list of TCP endpoints available to the application. /// The type that is defined as the table associated with the value. /// /// The type of the TCP table structure to retrieve. This parameter can be one of the values from the TCP_TABLE_CLASS enumeration. - /// The TCP_TABLE_CLASS enumeration value is combined with the value of the ulAf parameter to determine the extended TCP information to retrieve. + /// + /// The TCP_TABLE_CLASS enumeration value is combined with the value of the ulAf parameter to determine the extended TCP information + /// to retrieve. + /// /// /// The version of IP used by the TCP endpoints. Valid values are AF_INET and AF_INET6. /// - /// A value that specifies whether the TCP connection table should be sorted. If this parameter is set to TRUE, the TCP endpoints in the table are sorted - /// in ascending order, starting with the lowest local IP address. If this parameter is set to FALSE, the TCP endpoints in the table appear in the order - /// in which they were retrieved. + /// A value that specifies whether the TCP connection table should be sorted. If this parameter is set to TRUE, the TCP endpoints in + /// the table are sorted in ascending order, starting with the lowest local IP address. If this parameter is set to FALSE, the TCP + /// endpoints in the table appear in the order in which they were retrieved. /// /// The table. public static T GetExtendedTcpTable(TCP_TABLE_CLASS TableClass, ADDRESS_FAMILY ulAf = ADDRESS_FAMILY.AF_INET, bool sorted = false) where T : SafeHandle { - if (!CorrespondingTypeAttribute.CanGet(TableClass, typeof(T))) throw new InvalidOperationException("Type mismatch with supplied options."); - if (ulAf == ADDRESS_FAMILY.AF_INET6 && (int)TableClass > 2 && !typeof(T).Name.Contains("6")) throw new InvalidOperationException("Type mismatch with supplied options."); - if (ulAf == ADDRESS_FAMILY.AF_INET && (int)TableClass > 2 && typeof(T).Name.Contains("6")) throw new InvalidOperationException("Type mismatch with supplied options."); + if (!CorrespondingTypeAttribute.CanGet(TableClass, typeof(T))) + { + throw new InvalidOperationException("Type mismatch with supplied options."); + } + + if (ulAf == ADDRESS_FAMILY.AF_INET6 && (int)TableClass > 2 && !typeof(T).Name.Contains("6")) + { + throw new InvalidOperationException("Type mismatch with supplied options."); + } + + if (ulAf == ADDRESS_FAMILY.AF_INET && (int)TableClass > 2 && typeof(T).Name.Contains("6")) + { + throw new InvalidOperationException("Type mismatch with supplied options."); + } + uint len = 0; - var e = GetExtendedTcpTable(IntPtr.Zero, ref len, false, (uint)ulAf, TableClass); - if (e != Win32Error.ERROR_INSUFFICIENT_BUFFER) e.ThrowIfFailed(); - var mem = (T)Activator.CreateInstance(typeof(T), len); + Win32Error e = GetExtendedTcpTable(IntPtr.Zero, ref len, false, (uint)ulAf, TableClass); + if (e != Win32Error.ERROR_INSUFFICIENT_BUFFER) + { + e.ThrowIfFailed(); + } + + T mem = (T)Activator.CreateInstance(typeof(T), len); GetExtendedTcpTable(mem.DangerousGetHandle(), ref len, sorted, (uint)ulAf, TableClass).ThrowIfFailed(); return mem; } - /// The GetExtendedUdpTable function retrieves a table that contains a list of UDP endpoints available to the application. + /// + /// The GetExtendedUdpTable function retrieves a table that contains a list of UDP endpoints available to the application. + /// /// - /// A pointer to the table structure that contains the filtered UDP endpoints available to the application. For information about how to determine the - /// type of table returned based on specific input parameter combinations, see the Remarks section later in this document. + /// + /// A pointer to the table structure that contains the filtered UDP endpoints available to the application. For information about how + /// to determine the type of table returned based on specific input parameter combinations, see the Remarks section later in this document. + /// /// /// - /// The estimated size of the structure returned in pUdpTable, in bytes. If this value is set too small, ERROR_INSUFFICIENT_BUFFER is returned by this - /// function, and this field will contain the correct size of the structure. + /// + /// The estimated size of the structure returned in pUdpTable, in bytes. If this value is set too small, + /// ERROR_INSUFFICIENT_BUFFER is returned by this function, and this field will contain the correct size of the structure. + /// /// /// - /// A value that specifies whether the UDP endpoint table should be sorted. If this parameter is set to TRUE, the UDP endpoints in the table are sorted - /// in ascending order, starting with the lowest local IP address. If this parameter is set to FALSE, the UDP endpoints in the table appear in the order - /// in which they were retrieved. + /// + /// A value that specifies whether the UDP endpoint table should be sorted. If this parameter is set to TRUE, the UDP + /// endpoints in the table are sorted in ascending order, starting with the lowest local IP address. If this parameter is set to + /// FALSE, the UDP endpoints in the table appear in the order in which they were retrieved. + /// + /// The following values are compared as listed when ordering the UDP endpoints: + /// + /// + /// Local IP address + /// + /// + /// Local scope ID (applicable when the ulAf parameter is set to AF_INET6) + /// + /// + /// Local UDP port + /// + /// + /// + /// + /// The version of IP used by the UDP endpoint. + /// + /// + /// Value + /// Meaning + /// + /// + /// AF_INET + /// IPv4 is used. + /// + /// + /// AF_INET6 + /// IPv6 is used. + /// + /// /// - /// The version of IP used by the UDP endpoint. /// - /// The type of the UDP table structure to retrieve. This parameter can be one of the values from the UDP_TABLE_CLASS enumeration. - /// The UDP_TABLE_CLASS enumeration value is combined with the value of the ulAf parameter to determine the extended UDP information to retrieve. + /// The type of the UDP table structure to retrieve. This parameter can be one of the values from the UDP_TABLE_CLASS enumeration. + /// + /// On the Windows SDK released for Windows Vista and later, the organization of header files has changed and the UDP_TABLE_CLASS + /// enumeration is defined in the Iprtrmib.h header file, not in the IpHlpApi.h header file. + /// + /// + /// The UDP_TABLE_CLASS enumeration value is combined with the value of the ulAf parameter to determine the extended UDP information + /// to retrieve. + /// /// - /// Reserved. This value must be zero. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// Reserved. This value must be zero. + /// + /// + /// If the call is successful, the value NO_ERROR is returned. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INSUFFICIENT_BUFFER + /// + /// An insufficient amount of space was allocated for the table. The size of the table is returned in the pdwSize parameter, and must + /// be used in a subsequent call to this function in order to successfully retrieve the table. This error is also returned if the + /// pUdpTable parameter is NULL. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if the TableClass parameter contains a value that is not + /// defined in the UDP_TABLE_CLASS enumeration. + /// + /// + /// + /// + /// + /// + /// The table type returned by this function depends on the specific combination of the ulAf parameter and the TableClass parameter. + /// + /// + /// When the ulAf parameter is set to AF_INET, the following table indicates the UDP table type to retrieve in the structure + /// pointed to by the pUdpTable parameter for each possible TableClass value. + /// + /// + /// + /// TableClass value + /// pUdpTable structure + /// + /// + /// UDP_TABLE_BASIC + /// MIB_UDPTABLE + /// + /// + /// UDP_TABLE_OWNER_MODULE + /// MIB_UDPTABLE_OWNER_MODULE + /// + /// + /// UDP_TABLE_OWNER_PID + /// MIB_UDPTABLE_OWNER_PID + /// + /// + /// + /// When the ulAf parameter is set to AF_INET6, the following table indicates the TCP table type to retrieve in the structure + /// pointed to by the pUdpTable parameter for each possible TableClass value. + /// + /// + /// + /// TableClass value + /// pUdpTable structure + /// + /// + /// UDP_TABLE_BASIC + /// MIB_UDP6TABLE + /// + /// + /// UDP_TABLE_OWNER_MODULE + /// MIB_UDP6TABLE_OWNER_MODULE + /// + /// + /// UDP_TABLE_OWNER_PID + /// MIB_UDP6TABLE_OWNER_PID + /// + /// + /// + /// The GetExtendedUdpTable function when called with the ulAf parameter set to AF_INET6 and the TableClass set to + /// UDP_TABLE_BASIC is only supported on Windows Vista and later. + /// + /// + /// On Windows Server 2003 with Service Pack 1 (SP1) and Windows XP with Service Pack 2 (SP2), the GetExtendedUdpTable + /// function called with the ulAf parameter set to AF_INET6 and the TableClass set to UDP_TABLE_BASIC fails and returns ERROR_NOT_SUPPORTED. + /// + /// + /// On the Windows SDK released for Windows Vistaand later, the organization of header files has changed. The various MIB_UDPTABLE + /// structures are defined in the Udpmib.h header file, not in the Iprtrmib.h header file. Note that the Udpmib.h header file is + /// automatically included in Iprtrmib.h, which is automatically included in the IpHlpApi.h header file. The Udpmib.h and Iprtrmib.h + /// header files should never be used directly. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getextendedudptable DWORD GetExtendedUdpTable( PVOID + // pUdpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, UDP_TABLE_CLASS TableClass, ULONG Reserved ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "c936d5a0-ca5e-487e-b304-bfd81403ab40")] public static extern Win32Error GetExtendedUdpTable(IntPtr pUdpTable, ref uint pdwSize, [MarshalAs(UnmanagedType.Bool)] bool bOrder, uint ulAf, UDP_TABLE_CLASS TableClass, uint Reserved = 0); /// The GetExtendedUdpTable function retrieves a table that contains a list of UDP endpoints available to the application. /// The type that is defined as the table associated with the value. /// /// The type of the UDP table structure to retrieve. This parameter can be one of the values from the UDP_TABLE_CLASS enumeration. - /// The UDP_TABLE_CLASS enumeration value is combined with the value of the ulAf parameter to determine the extended UDP information to retrieve. + /// + /// The UDP_TABLE_CLASS enumeration value is combined with the value of the ulAf parameter to determine the extended UDP information + /// to retrieve. + /// /// /// The version of IP used by the UDP endpoint. /// - /// A value that specifies whether the UDP endpoint table should be sorted. If this parameter is set to TRUE, the UDP endpoints in the table are sorted - /// in ascending order, starting with the lowest local IP address. If this parameter is set to FALSE, the UDP endpoints in the table appear in the order - /// in which they were retrieved. + /// A value that specifies whether the UDP endpoint table should be sorted. If this parameter is set to TRUE, the UDP endpoints in + /// the table are sorted in ascending order, starting with the lowest local IP address. If this parameter is set to FALSE, the UDP + /// endpoints in the table appear in the order in which they were retrieved. /// /// The table. public static T GetExtendedUdpTable(UDP_TABLE_CLASS TableClass, ADDRESS_FAMILY ulAf = ADDRESS_FAMILY.AF_INET, bool sorted = false) where T : SafeHandle { - if (!CorrespondingTypeAttribute.CanGet(TableClass, typeof(T))) throw new InvalidOperationException("Type mismatch with supplied options."); - if (ulAf == ADDRESS_FAMILY.AF_INET6 && !typeof(T).Name.Contains("6")) throw new InvalidOperationException("Type mismatch with supplied options."); - if (ulAf == ADDRESS_FAMILY.AF_INET && typeof(T).Name.Contains("6")) throw new InvalidOperationException("Type mismatch with supplied options."); + if (!CorrespondingTypeAttribute.CanGet(TableClass, typeof(T))) + { + throw new InvalidOperationException("Type mismatch with supplied options."); + } + + if (ulAf == ADDRESS_FAMILY.AF_INET6 && !typeof(T).Name.Contains("6")) + { + throw new InvalidOperationException("Type mismatch with supplied options."); + } + + if (ulAf == ADDRESS_FAMILY.AF_INET && typeof(T).Name.Contains("6")) + { + throw new InvalidOperationException("Type mismatch with supplied options."); + } + uint len = 0; - var e = GetExtendedUdpTable(IntPtr.Zero, ref len, false, (uint)ulAf, TableClass); - if (e != Win32Error.ERROR_INSUFFICIENT_BUFFER) e.ThrowIfFailed(); - var mem = (T)Activator.CreateInstance(typeof(T), len); + Win32Error e = GetExtendedUdpTable(IntPtr.Zero, ref len, false, (uint)ulAf, TableClass); + if (e != Win32Error.ERROR_INSUFFICIENT_BUFFER) + { + e.ThrowIfFailed(); + } + + T mem = (T)Activator.CreateInstance(typeof(T), len); GetExtendedUdpTable(mem.DangerousGetHandle(), ref len, sorted, (uint)ulAf, TableClass).ThrowIfFailed(); return mem; } - /// The GetIfEntry2 function retrieves information for the specified interface on the local computer. - /// A pointer to a MIB_IF_ROW2 structure that, on successful return, receives information for an interface on the local computer. On input, the InterfaceLuid or the InterfaceIndex member of the MIB_IF_ROW2 must be set to the interface for which to retrieve information. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// 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. - /// 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 an error code. - [PInvokeData("Iphlpapi.h", MinClient = PInvokeClient.Windows10)] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// + /// The GetIfEntry2Ex function retrieves the specified level of information for the specified interface on the local computer. + /// + /// + /// + /// + /// The level of interface information to retrieve. This parameter can be one of the values from the MIB_IF_ENTRY_LEVEL + /// enumeration type defined in the Netioapi.h header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// MibIfEntryNormal 0 + /// + /// The values of statistics and state returned in members of the MIB_IF_ROW2 structure pointed to by the Row parameter are returned + /// from the top of the filter stack. + /// + /// + /// + /// MibIfEntryNormalWithoutStatistics 2 + /// + /// The values of state (without statistics) returned in members of the MIB_IF_ROW2 structure pointed to by the Row parameter are + /// returned from the top of the filter stack. + /// + /// + /// + /// + /// + /// + /// A pointer to a MIB_IF_ROW2 structure that, on successful return, receives information for an interface on the local computer. On + /// input, the InterfaceLuid or the InterfaceIndex member of the MIB_IF_ROW2 must be set to the interface for + /// which to retrieve information. + /// + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_FILE_NOT_FOUND + /// + /// The system cannot find the file specified. This error is returned if the network interface LUID or interface index specified by + /// the InterfaceLuid or InterfaceIndex member of the MIB_IF_ROW2 pointed to by the Row parameter was not a value on the local machine. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL parameter is passed in the Row parameter. This + /// error is also returned if the both the InterfaceLuid and InterfaceIndex member of the MIB_IF_ROW2 pointed to by the Row parameter + /// are unspecified. + /// + /// + /// + /// Other + /// Use the FormatMessage function to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The GetIfEntry2Ex function retrieves information for a specified interface on a local system and returns this information + /// in a pointer to a MIB_IF_ROW2 structure. GetIfEntry2Ex is an enhanced version of the GetIfEntry2 function that allows + /// selecting the level of interface information to retrieve. + /// + /// + /// On input, at least one of the following members in the MIB_IF_ROW2 structure passed in the Row parameter must be initialized: + /// InterfaceLuid or InterfaceIndex. + /// + /// On output, the remaining fields of the MIB_IF_ROW2 structure pointed to by the Row parameter are filled in. + /// Note that the Netioapi.h header file is automatically included in IpHlpApi.h header file, and should never be used directly. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getifentry2ex _NETIOAPI_SUCCESS_ NETIOAPI_API + // GetIfEntry2Ex( MIB_IF_ENTRY_LEVEL Level, PMIB_IF_ROW2 Row ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "98C25986-1B38-4878-B578-3D30394F49E4")] public static extern Win32Error GetIfEntry2Ex(MIB_IF_ENTRY_LEVEL Level, ref MIB_IF_ROW2 Row); - /// The GetIfTable function retrieves the MIB-II interface table. - /// A pointer to a buffer that receives the interface table as a MIB_IFTABLE structure. + /// + /// The GetIfTable function retrieves the MIB-II interface table. + /// + /// + /// A pointer to a buffer that receives the interface table as a MIB_IFTABLE structure. + /// /// - /// On input, specifies the size in bytes of the buffer pointed to by the pIfTable parameter. + /// On input, specifies the size in bytes of the buffer pointed to by the pIfTable parameter. /// - /// On output, if the buffer is not large enough to hold the returned interface table, the function sets this parameter equal to the required buffer size - /// in bytes. + /// On output, if the buffer is not large enough to hold the returned interface table, the function sets this parameter equal to the + /// required buffer size in bytes. /// /// /// - /// A Boolean value that specifies whether the returned interface table should be sorted in ascending order by interface index. If this parameter is - /// TRUE, the table is sorted. + /// + /// A Boolean value that specifies whether the returned interface table should be sorted in ascending order by interface index. If + /// this parameter is TRUE, the table is sorted. + /// /// - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// 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_INSUFFICIENT_BUFFER + /// + /// The buffer pointed to by the pIfTable parameter is not large enough. The required size is returned in the DWORD variable pointed + /// to by the pdwSize parameter. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// The pdwSize parameter is NULL, or GetIfTable is unable to write to the memory pointed to by the pdwSize parameter. + /// + /// + /// ERROR_NOT_SUPPORTED + /// This function is not supported on the operating system in use on the local system. + /// + /// + /// Other + /// Use the FormatMessage function to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The GetIfTable function enumerates physical interfaces on a local system and returns this information in a + /// MIB_IFTABLEstructure. The physical interfaces include the software loopback interface. + /// + /// + /// The GetIfTable2 and GetIfTable2Ex functions available on Windows Vista and later are an enhanced version of the GetIfTable + /// function that enumerate both the physical and logical interfaces on a local system. Logical interfaces include various WAN + /// Miniport interfaces used for L2TP, PPTP, PPOE, and other tunnel encapsulations. + /// + /// + /// Interfaces are returned in a MIB_IFTABLE structure in the buffer pointed to by the pIfTable parameter. The MIB_IFTABLE + /// structure contains an interface count and an array of MIB_IFROWstructures for each interface. + /// + /// + /// Note that the returned MIB_IFTABLE structure pointed to by the pIfTable parameter may contain padding for alignment between the + /// dwNumEntries member and the first MIB_IFROW array entry in the table member of the MIB_IFTABLE structure. + /// Padding for alignment may also be present between the MIB_IFROW array entries. Any access to a MIB_IFROW array + /// entry should assume padding may exist. + /// + /// Examples + /// + /// The following example retrieves the interface table and prints the number of entries in the table and some data on each entry. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getiftable DWORD GetIfTable( PMIB_IFTABLE pIfTable, + // PULONG pdwSize, BOOL bOrder ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "6a46c1df-b274-415e-b842-fc1adf6fa206")] public static extern Win32Error GetIfTable(IntPtr pIfTable, ref uint pdwSize, [MarshalAs(UnmanagedType.Bool)] bool bOrder); /// The GetIfTable function retrieves the MIB-II interface table. /// - /// A Boolean value that specifies whether the returned interface table should be sorted in ascending order by interface index. If this parameter is - /// TRUE, the table is sorted. + /// A Boolean value that specifies whether the returned interface table should be sorted in ascending order by interface index. If + /// this parameter is TRUE, the table is sorted. /// /// The MIB-II interface table. public static MIB_IFTABLE GetIfTable(bool sorted = false) { uint len = 0; - var e = GetIfTable(IntPtr.Zero, ref len, false); - if (e != Win32Error.ERROR_INSUFFICIENT_BUFFER) e.ThrowIfFailed(); - var mem = new MIB_IFTABLE(len); + Win32Error e = GetIfTable(IntPtr.Zero, ref len, false); + if (e != Win32Error.ERROR_INSUFFICIENT_BUFFER) + { + e.ThrowIfFailed(); + } + + MIB_IFTABLE mem = new MIB_IFTABLE(len); GetIfTable(mem, ref len, sorted).ThrowIfFailed(); return mem; } - /// The GetIfTable2 function retrieves the MIB-II interface table. - /// A pointer to a buffer that receives the table of interfaces in a MIB_IF_TABLE2 structure. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + + /// + /// The GetIfTable2 function retrieves the MIB-II interface table. + /// + /// + /// A pointer to a buffer that receives the table of interfaces in a MIB_IF_TABLE2 structure. + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// Insufficient memory resources are available to complete the operation. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The GetIfTable2 function enumerates the logical and physical interfaces on a local system and returns this information in + /// a MIB_IF_TABLE2 structure. GetIfTable2 is an enhanced version of the GetIfTable function. + /// + /// + /// A similar GetIfTable2Ex function can be used to specify the level of interfaces to return. Calling the GetIfTable2Ex + /// function with the Level parameter set to MibIfTableNormal retrieves the same results as calling the GetIfTable2 function. + /// + /// + /// Interfaces are returned in a MIB_IF_TABLE2 structure in the buffer pointed to by the Table parameter. The MIB_IF_TABLE2 + /// structure contains an interface count and an array of MIB_IF_ROW2 structures for each interface. Memory is allocated by the + /// GetIfTable2 function for the MIB_IF_TABLE2 structure and the MIB_IF_ROW2 entries in this structure. When + /// these returned structures are no longer required, free the memory by calling the FreeMibTable. + /// + /// + /// Note that the returned MIB_IF_TABLE2 structure pointed to by the Table parameter may contain padding for alignment between the + /// NumEntries member and the first MIB_IF_ROW2 array entry in the Table member of the MIB_IF_TABLE2 structure. + /// Padding for alignment may also be present between the MIB_IF_ROW2 array entries. Any access to a MIB_IF_ROW2 array + /// entry should assume padding may exist. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getiftable2 _NETIOAPI_SUCCESS_ NETIOAPI_API GetIfTable2( + // PMIB_IF_TABLE2 *Table ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "0153c41c-b02b-4832-87b3-88dc3a9f4ff1")] public static extern Win32Error GetIfTable2(out MIB_IF_TABLE2 pIfTable); - /// The GetIfTable2Ex function retrieves the MIB-II interface table. - /// The level of interface information to retrieve. - /// 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 an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// The GetIfTable2Ex function retrieves the MIB-II interface table. + /// + /// + /// + /// The level of interface information to retrieve. This parameter can be one of the values from the MIB_IF_TABLE_LEVEL + /// enumeration type defined in the Netioapi.h header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// MibIfTableNormal + /// + /// The values of statistics and state returned in members of the MIB_IF_ROW2 structure in the MIB_IF_TABLE2 structure pointed to by + /// the Table parameter are returned from the top of the filter stack when this parameter is specified. + /// + /// + /// + /// MibIfTableRaw + /// + /// The values of statistics and state returned in members of the MIB_IF_ROW2 structure in the MIB_IF_TABLE2 structure pointed to by + /// the Table parameter are returned directly for the interface being queried. + /// + /// + /// + /// + /// + /// A pointer to a buffer that receives the table of interfaces in a MIB_IF_TABLE2 structure. + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_PARAMETER + /// An invalid parameter was passed to the function. This error is returned if an illegal value was passed in the Level parameter. + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// Insufficient memory resources are available to complete the operation. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The GetIfTable2Ex function enumerates the logical and physical interfaces on a local system and returns this information + /// in a MIB_IF_TABLE2 structure. GetIfTable2Ex is an enhanced version of the GetIfTable function that allows selecting + /// the level of interface information to retrieve. + /// + /// + /// A similar GetIfTable2 function can also be used to retrieve interfaces. but does not allow specifying the level of interfaces to + /// return. Calling the GetIfTable2Ex function with the Level parameter set to MibIfTableNormal retrieves the same + /// results as calling the GetIfTable2 function. + /// + /// + /// Interfaces are returned in a MIB_IF_TABLE2 structure in the buffer pointed to by the Table parameter. The MIB_IF_TABLE2 + /// structure contains an interface count and an array of MIB_IF_ROW2 structures for each interface. Memory is allocated by the + /// GetIfTable2 function for the MIB_IF_TABLE2 structure and the MIB_IF_ROW2 entries in this structure. When these + /// returned structures are no longer required, free the memory by calling the FreeMibTable. + /// + /// + /// All interfaces including NDIS intermediate driver interfaces and NDIS filter driver interfaces are returned for either of the + /// possible values for the Level parameter. The setting for the Level parameter affects how statistics and state members of the + /// MIB_IF_ROW2 structure in the MIB_IF_TABLE2 structure pointed to by the Table parameter for the interface are returned. For + /// example, a network interface card (NIC) will have a NDIS miniport driver. An NDIS intermediate driver can be installed to + /// interface between upper-level protocol drivers and NDIS miniport drivers. An NDIS filter driver (LWF) can be attached on top of + /// the NDIS intermediate driver. Assume that the NIC reports the MediaConnectState member of the MIB_IF_ROW2 structure as + /// MediaConnectStateConnected but NDIS filter driver modifies the state and reports the state as + /// MediaConnectStateDisconnected. When the interface information is queried with Level parameter set to + /// MibIfTableNormal, the state at the top of the filter stack, that is MediaConnectStateDisconnected is reported. When + /// the interface is queried with the Level parameter set to MibIfTableRaw, the state at the interface level directly, that is + /// MediaConnectStateConnected is returned. + /// + /// + /// Note that the returned MIB_IF_TABLE2 structure pointed to by the Table parameter may contain padding for alignment between the + /// NumEntries member and the first MIB_IF_ROW2 array entry in the Table member of the MIB_IF_TABLE2 structure. + /// Padding for alignment may also be present between the MIB_IF_ROW2 array entries. Any access to a MIB_IF_ROW2 array + /// entry should assume padding may exist. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getiftable2ex _NETIOAPI_SUCCESS_ NETIOAPI_API + // GetIfTable2Ex( MIB_IF_TABLE_LEVEL Level, PMIB_IF_TABLE2 *Table ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "d8663894-50b1-4ca2-a1f4-6ca0970795a7")] public static extern Win32Error GetIfTable2Ex(MIB_IF_TABLE_LEVEL Level, out MIB_IF_TABLE2 pIfTable); - /// The GetInterfaceInfo function obtains the list of the network interface adapters with IPv4 enabled on the local system. + /// + /// + /// The GetInterfaceInfo function obtains the list of the network interface adapters with IPv4 enabled on the local system. + /// + /// /// - /// A pointer to a buffer that specifies an IP_INTERFACE_INFO structure that receives the list of adapters. This buffer must be allocated by the caller. + /// + /// A pointer to a buffer that specifies an IP_INTERFACE_INFO structure that receives the list of adapters. This buffer must be + /// allocated by the caller. + /// /// /// - /// A pointer to a DWORD variable that specifies the size of the buffer pointed to by pIfTable parameter to receive the IP_INTERFACE_INFO structure. If - /// this size is insufficient to hold the IPv4 interface information, GetInterfaceInfo fills in this variable with the required size, and returns an - /// error code of ERROR_INSUFFICIENT_BUFFER. + /// + /// A pointer to a DWORD variable that specifies the size of the buffer pointed to by pIfTable parameter to receive the + /// IP_INTERFACE_INFO structure. If this size is insufficient to hold the IPv4 interface information, GetInterfaceInfo fills + /// in this variable with the required size, and returns an error code of ERROR_INSUFFICIENT_BUFFER. + /// /// - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// 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_INSUFFICIENT_BUFFER + /// + /// The buffer to receive the IPv4 adapter information is too small. This value is returned if the dwOutBufLen parameter indicates + /// that the buffer pointed to by the pIfTable parameter is too small to retrieve the IPv4 interface information. The required size + /// is returned in the DWORD variable pointed to by the dwOutBufLen parameter. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if the dwOutBufLen parameter is NULL, or GetInterfaceInfo + /// is unable to write to the memory pointed to by the dwOutBufLen parameter. + /// + /// + /// + /// ERROR_NO_DATA + /// + /// There are no network adapters enabled for IPv4 on the local system. This value is also returned if all network adapters on the + /// local system are disabled. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// This function is not supported on the operating system in use on the local system. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The GetInterfaceInfo function is specific to network adapters with IPv4 enabled. The function returns an IP_INTERFACE_INFO + /// structure pointed to by the pIfTable parameter that contains the number of network adapters with IPv4 enabled on the local system + /// and an array of IP_ADAPTER_INDEX_MAP structures with information on each network adapter with IPv4 enabled. The + /// IP_INTERFACE_INFO structure returned by GetInterfaceInfo contains at least one IP_ADAPTER_INDEX_MAP + /// structure even if the NumAdapters member of the IP_INTERFACE_INFO structure indicates that no network adapters with + /// IPv4 are enabled. When the NumAdapters member of the IP_INTERFACE_INFO structure returned by + /// GetInterfaceInfo is zero, the value of the members of the single IP_ADAPTER_INDEX_MAP structure returned in the + /// IP_INTERFACE_INFO structure is undefined. + /// + /// + /// If the GetInterfaceInfo function is called with too small a buffer to retrieve the IPv4 interface information (the + /// dwOutBufLen parameter indicates that the buffer pointed to by the pIfTable parameter is too small), the function returns + /// ERROR_INSUFFICIENT_BUFFER. The required size is returned in the DWORD variable pointed to by the dwOutBufLen parameter. + /// + /// + /// The correct way to use the GetInterfaceInfo function is to call this function twice. In the first call, pass a NULL + /// pointer in the pIfTable parameter and zero in the variable pointed to by the dwOutBufLen parameter. The call with fail with + /// ERROR_INSUFFICIENT_BUFFER and the required size for this buffer is returned in the DWORD variable pointed to by the + /// dwOutBufLen parameter. A buffer can then be allocated of the required size using the value pointed by the dwOutBufLen. Then the + /// GetInterfaceInfo function can be called a second time with a pointer to this buffer passed in the pIfTable parameter and + /// the length of the buffer set to the size of this buffer. + /// + /// + /// The GetAdaptersInfo and GetInterfaceInfo functions do not return information about the loopback interface. Information on + /// the loopback interface is returned by the GetIpAddrTable function. + /// + /// + /// On Windows Vista and later, the Name member of the IP_ADAPTER_INDEX_MAP structure returned in the IP_INTERFACE_INFO + /// structure may be a Unicode string of the GUID for the network interface (the string begins with the '{' character). + /// + /// Examples + /// + /// The following example retrieves the list of network adapters with IPv4 enabled on the local system and prints various properties + /// of the first network adapter. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getinterfaceinfo DWORD GetInterfaceInfo( + // PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "efc0d175-2c6d-4608-b385-1623a9e0375c")] public static extern Win32Error GetInterfaceInfo(IntPtr pIfTable, ref uint dwOutBufLen); - /// The GetInterfaceInfo function obtains the list of the network interface adapters with IPv4 enabled on the local system. + /// + /// The GetInterfaceInfo function obtains the list of the network interface adapters with IPv4 enabled on the local system. + /// /// An IP_INTERFACE_INFO structure that receives the list of adapters. public static IP_INTERFACE_INFO GetInterfaceInfo() { uint len = 0; - var e = GetInterfaceInfo(IntPtr.Zero, ref len); - if (e != Win32Error.ERROR_INSUFFICIENT_BUFFER) e.ThrowIfFailed(); - var mem = new IP_INTERFACE_INFO(len); + Win32Error e = GetInterfaceInfo(IntPtr.Zero, ref len); + if (e != Win32Error.ERROR_INSUFFICIENT_BUFFER) + { + e.ThrowIfFailed(); + } + + IP_INTERFACE_INFO mem = new IP_INTERFACE_INFO(len); GetInterfaceInfo(mem, ref len).ThrowIfFailed(); return mem; } - /// The GetIpAddrTable function retrieves the interface–to–IPv4 address mapping table. - /// A pointer to a buffer that receives the interface–to–IPv4 address mapping table as a MIB_IPADDRTABLE structure. + /// + /// The GetIpAddrTable function retrieves the interface–to–IPv4 address mapping table. + /// + /// + /// A pointer to a buffer that receives the interface–to–IPv4 address mapping table as a MIB_IPADDRTABLE structure. + /// /// - /// On input, specifies the size in bytes of the buffer pointed to by the pIpAddrTable parameter. + /// On input, specifies the size in bytes of the buffer pointed to by the pIpAddrTable parameter. /// - /// On output, if the buffer is not large enough to hold the returned mapping table, the function sets this parameter equal to the required buffer size - /// in bytes. + /// On output, if the buffer is not large enough to hold the returned mapping table, the function sets this parameter equal to the + /// required buffer size in bytes. /// /// /// - /// A Boolean value that specifies whether the returned mapping table should be sorted in ascending order by IPv4 address. If this parameter is TRUE, the - /// table is sorted. + /// + /// A Boolean value that specifies whether the returned mapping table should be sorted in ascending order by IPv4 address. If this + /// parameter is TRUE, the table is sorted. + /// /// - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// 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_INSUFFICIENT_BUFFER + /// + /// The buffer pointed to by the pIpAddrTable parameter is not large enough. The required size is returned in the DWORD variable + /// pointed to by the pdwSize parameter. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// The pdwSize parameter is NULL, or GetIpAddrTable is unable to write to the memory pointed to by the pdwSize parameter. + /// + /// + /// ERROR_NOT_SUPPORTED + /// This function is not supported on the operating system in use on the local system. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The GetIpAddrTable function retrieves the interface–to–IPv4 address mapping table on a local computer and returns this + /// information in an MIB_IPADDRTABLE structure. + /// + /// + /// The IPv4 addresses returned by the GetIpAddrTable function are affected by the status of the network interfaces on a local + /// computer. Manually resetting a network interface card (NIC) and certain PnP events may result in an IP address being removed or changed. + /// + /// + /// On Windows Server 2003 and Windows XP, the IPv4 addresses returned by the GetIpAddrTable function are also affected if the + /// media sensing capability of the TCP/IP stack on a local computer has been disabled by calling the DisableMediaSense function. + /// When media sensing has been disabled, the GetIpAddrTable function may return IPv4 addresses associated with disconnected + /// interfaces. These Ipv4 addresses for disconnected interfaces are not valid for use. + /// + /// + /// On Windows Server 2008 and Windows Vista, the IPv4 addresses returned by the GetIpAddrTable function are not affected by + /// the media sensing capability of the TCP/IP stack on a local computer. The GetIpAddrTable function returns only valid IPv4 addresses. + /// + /// + /// The GetAdaptersAddresses function available on Windows XP can be used to retrieve both IPv6 and IPv4 addresses and interface information. + /// + /// + /// The MIB_IPADDRTABLE structure returned by the GetIpAddrTable function may contain padding for alignment between the + /// dwNumEntries member and the first MIB_IPADDRROW array entry in the table member. Padding for alignment may also be + /// present between the MIB_IPADDRROW array entries in the table member. Any access to a MIB_IPADDRROW array + /// entry should assume padding may exist. + /// + /// + /// On the Microsoft Windows Software Development Kit (SDK) released for Windows Vista and later, the organization of header files + /// has changed and the MIB_IPADDRROW is defined in the Ipmib.h header file not in the Iprtrmib.h header file. Note that the Ipmib.h + /// header file is automatically included in Iprtrmib.h which is automatically included in the IpHlpApi.h header file. The Ipmib.h + /// and Iprtrmib.h header files should never be used directly. + /// + /// Examples + /// The following example retrieves the IP address table, then prints some members of the IP address entries in the table. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getipaddrtable DWORD GetIpAddrTable( PMIB_IPADDRTABLE + // pIpAddrTable, PULONG pdwSize, BOOL bOrder ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "03bf5645-8237-4c78-a921-47315cab1c44")] public static extern Win32Error GetIpAddrTable(IntPtr pIpAddrTable, ref uint pdwSize, [MarshalAs(UnmanagedType.Bool)] bool bOrder); /// The GetIpAddrTable function retrieves the interface–to–IPv4 address mapping table. /// - /// A Boolean value that specifies whether the returned mapping table should be sorted in ascending order by IPv4 address. If this parameter is TRUE, the - /// table is sorted. + /// A Boolean value that specifies whether the returned mapping table should be sorted in ascending order by IPv4 address. If this + /// parameter is TRUE, the table is sorted. /// /// The interface–to–IPv4 address mapping table as a MIB_IPADDRTABLE structure. public static MIB_IPADDRTABLE GetIpAddrTable(bool sorted = false) { uint len = 0; - var e = GetIpAddrTable(IntPtr.Zero, ref len, false); - if (e != Win32Error.ERROR_INSUFFICIENT_BUFFER) e.ThrowIfFailed(); - var mem = new MIB_IPADDRTABLE(len); + Win32Error e = GetIpAddrTable(IntPtr.Zero, ref len, false); + if (e != Win32Error.ERROR_INSUFFICIENT_BUFFER) + { + e.ThrowIfFailed(); + } + + MIB_IPADDRTABLE mem = new MIB_IPADDRTABLE(len); GetIpAddrTable(mem, ref len, sorted).ThrowIfFailed(); return mem; } - /// The GetIpNetEntry2 function retrieves information for a neighbor IP address entry on the local computer. - /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this structure will be updated with the properties for neighbor IP address. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] - public static extern Win32Error GetIpNetEntry2(ref MIB_IPNET_ROW2 Row); - - /// The GetIpNetTable function retrieves the IPv4 to physical address mapping table. - /// A pointer to a buffer that receives the IPv4 to physical address mapping table as a MIB_IPNETTABLE structure. - /// - /// On input, specifies the size in bytes of the buffer pointed to by the pIpNetTable parameter. + /// + /// The GetIpNetEntry2 function retrieves information for a neighbor IP address entry on the local computer. + /// + /// /// - /// On output, if the buffer is not large enough to hold the returned mapping table, the function sets this parameter equal to the required buffer size - /// in bytes. + /// 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 Boolean value that specifies whether the returned mapping table should be sorted in ascending order by IP address. If this parameter is TRUE, the - /// table is sorted. + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_FILE_NOT_FOUND + /// + /// The system cannot find the file specified. This error is returned if the network interface LUID or interface index specified by + /// the InterfaceLuid or InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not a value on the local machine. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the + /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid neighbor IPv4 or IPv6 address, or + /// both the InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the Row parameter were unspecified. + /// + /// + /// + /// ERROR_NOT_FOUND + /// + /// Element not found. This error is returned if the network interface specified by the InterfaceLuid or InterfaceIndex member of the + /// MIB_IPNET_ROW2 structure pointed to by the Row parameter does not match the neighbor IP address and address family specified in + /// the Address member in the MIB_IPNET_ROW2 structure. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified + /// in the Address member of the MIB_IPNET_ROW2 structure pointed to by the Row parameter. This error is also returned if no IPv6 + /// stack is on the local computer and an IPv6 address was specified in the Address member of the MIB_IPNET_ROW2 structure. + /// + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// The GetIpNetEntry2 function is defined on Windows Vista and later. + /// The GetIpNetEntry2 function is used to retrieve a MIB_IPNET_ROW2 structure entry. + /// + /// On input, the Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a + /// valid neighbor IPv4 or IPv6 address and family. In addition, at least one of the following members in the MIB_IPNET_ROW2 + /// structure pointed to the Row parameter must be initialized: the InterfaceLuid or InterfaceIndex. + /// + /// + /// On output when the call is successful, GetIpNetEntry2 retrieves the other properties for the neighbor IP address and fills + /// out the MIB_IPNET_ROW2 structure pointed to by the Row parameter. + /// + /// The GetIpNetTable2 function can be called to enumerate the neighbor IP address entries on a local computer. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API + // GetIpNetEntry2( PMIB_IPNET_ROW2 Row ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "c77e01da-2d5a-4c74-b581-62fa6ee52c9e")] + public static extern Win32Error GetIpNetEntry2(ref MIB_IPNET_ROW2 Row); + + /// + /// The GetIpNetTable function retrieves the IPv4 to physical address mapping table. + /// + /// + /// A pointer to a buffer that receives the IPv4 to physical address mapping table as a MIB_IPNETTABLE structure. /// - /// If the function succeeds, the return value is NO_ERROR or ERROR_NO_DATA. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// On input, specifies the size in bytes of the buffer pointed to by the pIpNetTable parameter. + /// + /// On output, if the buffer is not large enough to hold the returned mapping table, the function sets this parameter equal to the + /// required buffer size in bytes. + /// + /// + /// + /// + /// A Boolean value that specifies whether the returned mapping table should be sorted in ascending order by IP address. If this + /// parameter is TRUE, the table is sorted. + /// + /// + /// + /// If the function succeeds, the return value is NO_ERROR or ERROR_NO_DATA. + /// If the function fails or does not return any data, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INSUFFICIENT_BUFFER + /// + /// The buffer pointed to by the pIpNetTable parameter is not large enough. The required size is returned in the DWORD variable + /// pointed to by the pdwSize parameter. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if the pdwSize parameter is NULL, or GetIpNetTable is + /// unable to write to the memory pointed to by the pdwSize parameter. + /// + /// + /// + /// ERROR_NO_DATA + /// + /// There is no data to return. The IPv4 to physical address mapping table is empty. This return value indicates that the call to the + /// GetIpNetTable function succeeded, but there was no data to return. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// The IPv4 transport is not configured on the local computer. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The GetIpNetTable function enumerates the Address Resolution Protocol (ARP) entries for IPv4 on a local system from the + /// IPv4 to physical address mapping table and returns this information in a MIB_IPNETTABLE structure. + /// + /// + /// The IPv4 address entries are returned in a MIB_IPNETTABLE structure in the buffer pointed to by the pIpNetTable parameter. The + /// MIB_IPNETTABLE structure contains a count of ARP entries and an array of MIB_IPNETROW structures for each IPv4 address entry. + /// + /// + /// Note that the returned MIB_IPNETTABLE structure pointed to by the pIpNetTable parameter may contain padding for alignment between + /// the dwNumEntries member and the first MIB_IPNETROW array entry in the table member of the MIB_IPNETTABLE + /// structure. Padding for alignment may also be present between the MIB_IPNETROW array entries. Any access to a + /// MIB_IPNETROW array entry should assume padding may exist. + /// + /// + /// on Windows Vista and later, the GetIpNetTable2 function can be used to retrieve the neighbor IP addresses for both IPv6 and IPv4. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getipnettable ULONG GetIpNetTable( PMIB_IPNETTABLE + // IpNetTable, PULONG SizePointer, BOOL Order ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "01bcf86e-5fcc-4ce9-bb89-02d393e75d1d")] public static extern Win32Error GetIpNetTable(IntPtr pIpNetTable, ref uint pdwSize, [MarshalAs(UnmanagedType.Bool)] bool bOrder); /// The GetIpNetTable function retrieves the IPv4 to physical address mapping table. /// - /// A Boolean value that specifies whether the returned mapping table should be sorted in ascending order by IP address. If this parameter is TRUE, the - /// table is sorted. + /// A Boolean value that specifies whether the returned mapping table should be sorted in ascending order by IP address. If this + /// parameter is TRUE, the table is sorted. /// /// The IPv4 to physical address mapping table as a MIB_IPNETTABLE structure. public static MIB_IPNETTABLE GetIpNetTable(bool sorted = false) { uint len = 0; - var e = GetIpNetTable(IntPtr.Zero, ref len, false); - if (e != Win32Error.ERROR_INSUFFICIENT_BUFFER) e.ThrowIfFailed(); - var mem = new MIB_IPNETTABLE(len); + Win32Error e = GetIpNetTable(IntPtr.Zero, ref len, false); + if (e != Win32Error.ERROR_INSUFFICIENT_BUFFER) + { + e.ThrowIfFailed(); + } + + MIB_IPNETTABLE mem = new MIB_IPNETTABLE(len); GetIpNetTable(mem, ref len, sorted).ThrowIfFailed(); return mem; } - /// The GetIpNetTable2 function retrieves the IP neighbor table on the local computer. - /// The address family to retrieve. - /// 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. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// The GetIpNetTable2 function retrieves the IP neighbor table on the local computer. + /// + /// + /// The address family to retrieve. + /// + /// Possible values for the address family are listed in the Winsock2.h header file. Note that the values for the AF_ address family + /// and PF_ protocol family constants are identical (for example, AF_INET and PF_INET), so either constant can be used. + /// + /// + /// On the Windows SDK released for Windows Vista and later, the organization of header files has changed and possible values for + /// this member are defined in the Ws2def.h header file. Note that the Ws2def.h header file is automatically included in Winsock2.h, + /// and should never be used directly. + /// + /// The values currently supported are AF_INET, AF_INET6, and AF_UNSPEC. + /// + /// + /// Value + /// Meaning + /// + /// + /// AF_UNSPEC 0 + /// + /// The address family is unspecified. When this parameter is specified, this function returns the neighbor IP address table + /// containing both IPv4 and IPv6 entries. + /// + /// + /// + /// AF_INET 2 + /// + /// The Internet Protocol version 4 (IPv4) address family. When this parameter is specified, this function returns the neighbor IP + /// address table containing only IPv4 entries. + /// + /// + /// + /// AF_INET6 23 + /// + /// The Internet Protocol version 6 (IPv6) address family. When this parameter is specified, this function returns the neighbor IP + /// address table containing only IPv6 entries. + /// + /// + /// + /// + /// + /// A pointer to a MIB_IPNET_TABLE2 structure that contains a table of neighbor IP address entries on the local computer. + /// + /// + /// If the function succeeds, the return value is NO_ERROR or ERROR_NOT_FOUND. + /// If the function fails or returns no data, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Table parameter or the + /// Family parameter was not specified as AF_INET, AF_INET6, or AF_UNSPEC. + /// + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// Insufficient memory resources are available to complete the operation. + /// + /// + /// ERROR_NOT_FOUND + /// + /// No neighbor IP address entries as specified in the Family parameter were found. This return value indicates that the call to the + /// GetIpNetTable2 function succeeded, but there was no data to return. This can occur when AF_INET is specified in the Family + /// parameter and there are no ARP entries to return. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and AF_INET was specified in the + /// Family parameter. This error is also returned if no IPv6 stack is on the local computer and AF_INET6 was specified in the Family + /// parameter. This error is also returned on versions of Windows where this function is not supported. + /// + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// The GetIpNetTable2 function is defined on Windows Vista and later. + /// + /// The GetIpNetTable2 function enumerates the neighbor IP addresses on a local system and returns this information in a + /// MIB_IPNET_TABLE2 structure. + /// + /// + /// The neighbor IP address entries are returned in a MIB_IPNET_TABLE2 structure in the buffer pointed to by the Table parameter. The + /// MIB_IPNET_TABLE2 structure contains a neighbor IP address entry count and an array of MIB_IPNET_ROW2 structures for each + /// neighbor IP address entry. When these returned structures are no longer required, free the memory by calling the FreeMibTable. + /// + /// The Family parameter must be initialized to either AF_INET, AF_INET6, or AF_UNSPEC. + /// + /// Note that the returned MIB_IPNET_TABLE2 structure pointed to by the Table parameter may contain padding for alignment between the + /// NumEntries member and the first MIB_IPNET_ROW2 array entry in the Table member of the MIB_IPNET_TABLE2 + /// structure. Padding for alignment may also be present between the MIB_IPNET_ROW2 array entries. Any access to a + /// MIB_IPNET_ROW2 array entry should assume padding may exist. + /// + /// Examples + /// The following example retrieves the IP neighbor table, then prints the values for IP neighbor row entries in the table. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-getipnettable2 _NETIOAPI_SUCCESS_ NETIOAPI_API + // GetIpNetTable2( ADDRESS_FAMILY Family, PMIB_IPNET_TABLE2 *Table ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "6c45d735-9a07-41ca-8d8a-919f32c98a3c")] public static extern Win32Error GetIpNetTable2(ADDRESS_FAMILY Family, out MIB_IPNET_TABLE2 Table); - /// The GetNetworkParams function retrieves network parameters for the local computer. + /// + /// The GetNetworkParams function retrieves network parameters for the local computer. + /// /// - /// A pointer to a buffer that contains a structure that receives the network parameters for the local computer, if the function - /// was successful. This buffer must be allocated by the caller prior to calling the GetNetworkParams function. + /// + /// A pointer to a buffer that contains a FIXED_INFO structure that receives the network parameters for the local computer, if the + /// function was successful. This buffer must be allocated by the caller prior to calling the GetNetworkParams function. + /// /// - /// - /// A pointer to a ULONG variable that specifies the size of the structure. If this size is insufficient to hold the - /// information, GetNetworkParams fills in this variable with the required size, and returns an error code of ERROR_BUFFER_OVERFLOW. + /// + /// + /// A pointer to a ULONG variable that specifies the size of the FIXED_INFO structure. If this size is insufficient to hold + /// the information, GetNetworkParams fills in this variable with the required size, and returns an error code of ERROR_BUFFER_OVERFLOW. + /// /// - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// If the function succeeds, the return value is ERROR_SUCCESS. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_BUFFER_OVERFLOW + /// + /// The buffer to receive the network parameter information is too small. This value is returned if the pOutBufLen parameter is too + /// small to hold the network parameter information or the pFixedInfo parameter was a NULL pointer. When this error code is returned, + /// the pOutBufLen parameter points to the required buffer size. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if the pOutBufLen parameter is a NULL pointer, the + /// calling process does not have read/write access to the memory pointed to by pOutBufLen, or the calling process does not have + /// write access to the memory pointed to by the pFixedInfo parameter. + /// + /// + /// + /// ERROR_NO_DATA + /// No network parameter information exists for the local computer. + /// + /// + /// ERROR_NOT_SUPPORTED + /// The GetNetworkParams function is not supported by the operating system running on the local computer. + /// + /// + /// Other + /// If the function fails, use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The GetNetworkParams function is used to retrieve network parameters for the local computer. Network parameters are + /// returned in a FIXED_INFOstructure. The memory for the FIXED_INFO structure must be allocated by the application. It is the + /// responsibility of the application to free this memory when it is no longer needed. + /// + /// + /// In the Microsoft Windows Software Development Kit (SDK), the FIXED_INFO_WIN2KSP1 structure is defined. When compiling an + /// application if the target platform is Windows 2000 with Service Pack 1 (SP1) and later (, , or ), the FIXED_INFO_WIN2KSP1 + /// struct is typedefed to the FIXED_INFO structure. When compiling an application if the target platform is not Windows 2000 + /// with SP1 and later, the FIXED_INFO structure is undefined. + /// + /// + /// The GetNetworkParams function and the FIXED_INFO structure are supported on Windows 98and later. But to build an + /// application for a target platform earlier than Windows 2000 with Service Pack 1 (SP1), an earlier version of the Platform + /// Software Development Kit (SDK) must be used. + /// + /// Examples + /// + /// The following example retrieves the network parameters for the local computer and prints information from the returned data. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getnetworkparams DWORD GetNetworkParams( PFIXED_INFO + // pFixedInfo, PULONG pOutBufLen ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "5f54a120-5db9-4b8d-a281-1112be0042d6")] public static extern Win32Error GetNetworkParams(IntPtr pFixedInfo, ref uint pBufOutLen); /// The GetNetworkParams function retrieves network parameters for the local computer. /// A structure that receives the network parameters for the local computer. public static FIXED_INFO GetNetworkParams() { - var mem = SafeCoTaskMemHandle.CreateFromStructure(); + SafeCoTaskMemHandle mem = SafeCoTaskMemHandle.CreateFromStructure(); uint len = (uint)mem.Size; - var e = GetNetworkParams((IntPtr)mem, ref len); + Win32Error e = GetNetworkParams((IntPtr)mem, ref len); if (e == Win32Error.ERROR_BUFFER_OVERFLOW) { mem.Size = (int)len; GetNetworkParams((IntPtr)mem, ref len).ThrowIfFailed(); } else + { e.ThrowIfFailed(); + } + return mem.ToStructure(); } - /// The GetPerAdapterInfo function retrieves information about the adapter corresponding to the specified interface. - /// Index of an interface. The GetPerAdapterInfo function retrieves information for the adapter corresponding to this interface. - /// Pointer to an IP_PER_ADAPTER_INFO structure that receives information about the adapter. - /// - /// Pointer to a ULONG variable that specifies the size of the IP_PER_ADAPTER_INFO structure. If this size is insufficient to hold the information, - /// GetPerAdapterInfo fills in this variable with the required size, and returns an error code of ERROR_BUFFER_OVERFLOW. + /// + /// The GetPerAdapterInfo function retrieves information about the adapter corresponding to the specified interface. + /// + /// + /// + /// Index of an interface. The GetPerAdapterInfo function retrieves information for the adapter corresponding to this interface. + /// /// - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// Pointer to an IP_PER_ADAPTER_INFO structure that receives information about the adapter. + /// + /// + /// + /// Pointer to a ULONG variable that specifies the size of the IP_PER_ADAPTER_INFO structure. If this size is insufficient to + /// hold the information, GetPerAdapterInfo fills in this variable with the required size, and returns an error code of ERROR_BUFFER_OVERFLOW. + /// + /// + /// + /// If the function succeeds, the return value is ERROR_SUCCESS. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_BUFFER_OVERFLOW + /// + /// The buffer size indicated by the pOutBufLen parameter is too small to hold the adapter information. The pOutBufLen parameter + /// points to the required size. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// The pOutBufLen parameter is NULL, or the calling process does not have read/write access to the memory pointed to by pOutBufLen, + /// or the calling process does not have write access to the memory pointed to by the pAdapterInfo parameter. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// GetPerAdapterInfo is not supported by the operating system running on the local computer. + /// + /// + /// Other + /// If the function fails, use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// An adapter index may change when the adapter is disabled and then enabled, or under other circumstances, and should not be + /// considered persistent. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getperadapterinfo DWORD GetPerAdapterInfo( ULONG + // IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "fc1ae7e4-f856-4b48-8ab4-56cd511ed161")] public static extern Win32Error GetPerAdapterInfo(uint IfIndex, IntPtr pPerAdapterInfo, ref uint pOutBufLen); /// The GetPerAdapterInfo function retrieves information about the adapter corresponding to the specified interface. - /// Index of an interface. The GetPerAdapterInfo function retrieves information for the adapter corresponding to this interface. + /// + /// Index of an interface. The GetPerAdapterInfo function retrieves information for the adapter corresponding to this interface. + /// /// A PIP_PER_ADAPTER_INFO structure that receives information about the adapter. public static PIP_PER_ADAPTER_INFO GetPerAdapterInfo(uint IfIndex) { uint len = 0; - var e = GetPerAdapterInfo(IfIndex, IntPtr.Zero, ref len); - if (e != Win32Error.ERROR_BUFFER_OVERFLOW) e.ThrowIfFailed(); - var mem = new PIP_PER_ADAPTER_INFO(len); + Win32Error e = GetPerAdapterInfo(IfIndex, IntPtr.Zero, ref len); + if (e != Win32Error.ERROR_BUFFER_OVERFLOW) + { + e.ThrowIfFailed(); + } + + PIP_PER_ADAPTER_INFO mem = new PIP_PER_ADAPTER_INFO(len); GetPerAdapterInfo(IfIndex, mem, ref len).ThrowIfFailed(); return mem; } /// - /// The GetUniDirectionalAdapterInfo function retrieves information about the unidirectional adapters installed on the local computer. A unidirectional - /// adapter is an adapter that can receive datagrams, but not transmit them. + /// + /// The GetUniDirectionalAdapterInfo function retrieves information about the unidirectional adapters installed on the local + /// computer. A unidirectional adapter is an adapter that can receive datagrams, but not transmit them. + /// /// /// - /// Pointer to an IP_UNIDIRECTIONAL_ADAPTER_ADDRESS structure that receives information about the unidirectional adapters installed on the local computer. + /// + /// Pointer to an IP_UNIDIRECTIONAL_ADAPTER_ADDRESS structure that receives information about the unidirectional adapters installed + /// on the local computer. + /// /// - /// Pointer to a ULONG variable that receives the size of the structure pointed to by the pIPIfInfo parameter. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// Pointer to a ULONG variable that receives the size of the structure pointed to by the pIPIfInfo parameter. + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, use FormatMessage to obtain the message string for the returned error. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getunidirectionaladapterinfo DWORD + // GetUniDirectionalAdapterInfo( PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "32aa3a8e-ae74-4da9-bc8d-b28e270d9702")] public static extern Win32Error GetUniDirectionalAdapterInfo(IntPtr pIPIfInfo, ref uint dwOutBufLen); /// - /// The GetUniDirectionalAdapterInfo function retrieves information about the unidirectional adapters installed on the local computer. A unidirectional - /// adapter is an adapter that can receive datagrams, but not transmit them. + /// The GetUniDirectionalAdapterInfo function retrieves information about the unidirectional adapters installed on the local + /// computer. A unidirectional adapter is an adapter that can receive datagrams, but not transmit them. /// - /// An IP_UNIDIRECTIONAL_ADAPTER_ADDRESS structure that receives information about the unidirectional adapters installed on the local computer. + /// + /// An IP_UNIDIRECTIONAL_ADAPTER_ADDRESS structure that receives information about the unidirectional adapters installed on the local computer. + /// public static IP_UNIDIRECTIONAL_ADAPTER_ADDRESS GetUniDirectionalAdapterInfo() { uint len = 0; - var e = GetUniDirectionalAdapterInfo(IntPtr.Zero, ref len); - if (e != Win32Error.ERROR_MORE_DATA) e.ThrowIfFailed(); - var mem = new IP_UNIDIRECTIONAL_ADAPTER_ADDRESS(len); + Win32Error e = GetUniDirectionalAdapterInfo(IntPtr.Zero, ref len); + if (e != Win32Error.ERROR_MORE_DATA) + { + e.ThrowIfFailed(); + } + + IP_UNIDIRECTIONAL_ADAPTER_ADDRESS mem = new IP_UNIDIRECTIONAL_ADAPTER_ADDRESS(len); GetUniDirectionalAdapterInfo(mem, ref len).ThrowIfFailed(); return mem; } - /// The IpReleaseAddress function releases an IPv4 address previously obtained through the Dynamic Host Configuration Protocol (DHCP). - /// A pointer to an IP_ADAPTER_INDEX_MAP structure that specifies the adapter associated with the IPv4 address to release. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// + /// The IpReleaseAddress function releases an IPv4 address previously obtained through the Dynamic Host Configuration Protocol (DHCP). + /// + /// + /// + /// A pointer to an IP_ADAPTER_INDEX_MAP structure that specifies the adapter associated with the IPv4 address to release. + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, use FormatMessage to obtain the message string for the returned error. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// One of the parameters is invalid. This error is returned if the AdapterInfo parameter is NULL or if the Name member of the + /// PIP_ADAPTER_INDEX_MAP structure pointed to by the AdapterInfo parameter is invalid. + /// + /// + /// + /// ERROR_PROC_NOT_FOUND + /// An exception occurred during the request to DHCP for the release of the IPv4 address. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The IpReleaseAddress function is specific to IPv4 and releases only an IPv4 address previously obtained through the + /// Dynamic Host Configuration Protocol (DHCP). The Name member of the IP_ADAPTER_INDEX_MAP structure pointed to by the + /// AdapterInfo parameter is the only member used to determine the DHCP address to release. + /// + /// + /// An array of IP_ADAPTER_INDEX_MAP structures is returned in the IP_INTERFACE_INFO structure by the GetInterfaceInfo function. The + /// IP_INTERFACE_INFO structure returned by GetInterfaceInfo contains at least one IP_ADAPTER_INDEX_MAP + /// structure even if the NumAdapters member of the IP_INTERFACE_INFO structure indicates that no network adapters with + /// IPv4 are enabled. When the NumAdapters member of the IP_INTERFACE_INFO structure returned by + /// GetInterfaceInfo is zero, the value of the members of the single IP_ADAPTER_INDEX_MAP structure returned in the + /// IP_INTERFACE_INFO structure is undefined. + /// + /// + /// If the Name member of the IP_ADAPTER_INDEX_MAP structure pointed to by the AdapterInfo parameter is NULL, the + /// IpReleaseAddress function returns ERROR_INVALID_PARAMETER. + /// + /// + /// There are no functions available for releasing or renewing an IPv6 address. This can only be done by executing the Ipconfig command: + /// + /// ipconfig /release6 + /// ipconfig /renew6 + /// Examples + /// + /// The following example retrieves the list of network adapters with IPv4 enabled on the local system, then releases and renews the + /// IPv4 address for the first adapter in the list. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-ipreleaseaddress DWORD IpReleaseAddress( + // PIP_ADAPTER_INDEX_MAP AdapterInfo ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "d937ea44-1ca3-49e0-913d-fb77888d05fc")] public static extern Win32Error IpReleaseAddress(ref IP_ADAPTER_INDEX_MAP AdapterInfo); - /// The IpRenewAddress function renews a lease on an IPv4 address previously obtained through Dynamic Host Configuration Protocol (DHCP). - /// A pointer to an IP_ADAPTER_INDEX_MAP structure that specifies the adapter associated with the IP address to renew. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// + /// The IpRenewAddress function renews a lease on an IPv4 address previously obtained through Dynamic Host Configuration + /// Protocol (DHCP). + /// + /// + /// + /// A pointer to an IP_ADAPTER_INDEX_MAP structure that specifies the adapter associated with the IP address to renew. + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, use FormatMessage to obtain the message string for the returned error. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// One of the parameters is invalid. This error is returned if the AdapterInfo parameter is NULL or if the Name member of the + /// PIP_ADAPTER_INDEX_MAP structure pointed to by the AdapterInfo parameter is invalid. + /// + /// + /// + /// ERROR_PROC_NOT_FOUND + /// An exception occurred during the request to DHCP for the renewal of the IPv4 address. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The IpRenewAddress function is specific to IPv4 and renews only an IPv4 address previously obtained through the Dynamic + /// Host Configuration Protocol (DHCP). The Name member of the IP_ADAPTER_INDEX_MAP structure pointed to by the AdapterInfo + /// parameter is the only member used to determine the DHCP address to renew. + /// + /// + /// An array of IP_ADAPTER_INDEX_MAP structures are returned in the IP_INTERFACE_INFO structure by the GetInterfaceInfo function. The + /// IP_INTERFACE_INFO structure returned by GetInterfaceInfo contains at least one IP_ADAPTER_INDEX_MAP + /// structure even if the NumAdapters member of the IP_INTERFACE_INFO structure indicates that no network adapters with + /// IPv4 are enabled. When the NumAdapters member of the IP_INTERFACE_INFO structure returned by + /// GetInterfaceInfo is zero, the value of the members of the single IP_ADAPTER_INDEX_MAP structure returned in the + /// IP_INTERFACE_INFO structure is undefined. + /// + /// + /// If the Name member of the IP_ADAPTER_INDEX_MAP structure pointed to by the AdapterInfo parameter is NULL, the + /// IpRenewAddress function returns ERROR_INVALID_PARAMETER. + /// + /// + /// There are no functions available for releasing or renewing an IPv6 address. This can only be done by executing the Ipconfig command: + /// + /// ipconfig /release6 + /// ipconfig /renew6 + /// Examples + /// + /// The following example retrieves the list of network adapters with IPv4 enabled on the local system, then releases and renews the + /// IPv4 address for the first adapter in the list. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-iprenewaddress DWORD IpRenewAddress( + // PIP_ADAPTER_INDEX_MAP AdapterInfo ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "25b1bf9f-3ae1-453c-baae-5f70ae46cd24")] public static extern Win32Error IpRenewAddress(ref IP_ADAPTER_INDEX_MAP AdapterInfo); /// - /// The NotifyAddrChange function causes a notification to be sent to the caller whenever a change occurs in the table that maps IPv4 addresses to interfaces. + /// + /// The NotifyAddrChange function causes a notification to be sent to the caller whenever a change occurs in the table that + /// maps IPv4 addresses to interfaces. + /// /// - /// A pointer to a HANDLE variable that receives a file handle for use in a subsequent call to the GetOverlappedResult function. - /// A pointer to an OVERLAPPED structure that notifies the caller of any changes in the table that maps IP addresses to interfaces. + /// + /// + /// A pointer to a HANDLE variable that receives a file handle for use in a subsequent call to the GetOverlappedResult function. + /// + /// Warning Do not close this handle, and do not associate it with a completion port. + /// + /// + /// A pointer to an OVERLAPPED structure that notifies the caller of any changes in the table that maps IP addresses to interfaces. + /// /// - /// If the function succeeds, the return value is NO_ERROR if the caller specifies NULL for the Handle and overlapped parameters. If the caller specifies - /// non-NULL parameters, the return value for success is ERROR_IO_PENDING. + /// + /// If the function succeeds, the return value is NO_ERROR if the caller specifies NULL for the Handle and overlapped + /// parameters. If the caller specifies non- NULL parameters, the return value for success is ERROR_IO_PENDING. + /// + /// If the function fails, use FormatMessage to obtain the message string for the returned error. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_CANCELLED + /// The context is being deregistered, so the call was canceled immediately. + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed. This error is returned if the both the Handle and overlapped parameters are not NULL, but the + /// memory specified by the input parameters cannot be written by the calling process. This error is also returned if the client + /// already has made a change notification request, so this duplicate request will fail. + /// + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// There was insufficient memory available to complete the operation. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// This error is returned on versions of Windows where this function is not supported such as Windows 98/95 and Windows NT 4.0. + /// + /// + /// /// - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// The + /// NotifyAddrChange function may be called in two ways: + /// + /// + /// Synchronous method + /// + /// + /// Asynchronous method + /// + /// + /// + /// If the caller specifies NULL for the Handle and overlapped parameters, the call to NotifyAddrChange is synchronous + /// and will block until an IP address change occurs. In this case if a change occurs, the NotifyAddrChange function completes + /// to indicate that a change has occurred. + /// + /// + /// If the NotifyAddrChange function is called synchronously, a notification will be sent on the next IPv4 address change + /// until the application terminates. + /// + /// + /// If the caller specifies a handle variable and an OVERLAPPED structure, then the NotifyAddrChange function call is + /// asynchronous and the caller can use the returned handle with the OVERLAPPED structure to receive asynchronous notification + /// of IPv4 address changes using the GetOverlappedResult function. See the following topics for information about using the handle + /// and OVERLAPPED structure to receive notifications: + /// + /// + /// + /// Synchronization and Overlapped Input and Output + /// + /// + /// GetOverlappedResult + /// + /// + /// + /// The CancelIPChangeNotify function cancels notification of IPv4 address and route changes previously requested with successful + /// calls to the NotifyAddrChange or NotifyRouteChange functions. + /// + /// + /// Once an application has been notified of a change, the application can then call the GetIpAddrTable or GetAdaptersAddresses + /// function to retrieve the table of IPv4 addresses to determine what has changed. If the application is notified and requires + /// notification for the next change, then the NotifyAddrChange function must be called again. + /// + /// + /// If the NotifyAddrChange function is called asynchronously, a notification will be sent on the next IPv4 address change + /// until either the application cancels the notification by calling the CancelIPChangeNotify function or the application terminates. + /// If the application terminates, the system will automatically cancel the registration for the notification. It is still + /// recommended that an application explicitly cancel any notification before it terminates. + /// + /// Any registration for a notification does not persist across a system shut down or reboot. + /// + /// On Windows Vista and later, the NotifyIpInterfaceChange function can be used to register to be notified for changes to IPv4 and + /// IPv6 interfaces on the local computer. + /// + /// Examples + /// The following example waits for a change to occur in the table that maps IP addresses to interfaces. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-notifyaddrchange DWORD NotifyAddrChange( PHANDLE Handle, + // LPOVERLAPPED overlapped ); + [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "22ac3b5b-452c-454b-8fbd-47a873675c6c")] public static extern unsafe Win32Error NotifyAddrChange(out IntPtr Handle, System.Threading.NativeOverlapped* overlapped); - /// The NotifyRouteChange function causes a notification to be sent to the caller whenever a change occurs in the IPv4 routing table. - /// A pointer to a HANDLE variable that receives a handle to use in asynchronous notification. - /// A pointer to an OVERLAPPED structure that notifies the caller of any changes in the routing table. + /// + /// + /// The NotifyRouteChange function causes a notification to be sent to the caller whenever a change occurs in the IPv4 routing table. + /// + /// + /// + /// A pointer to a HANDLE variable that receives a handle to use in asynchronous notification. + /// + /// + /// A pointer to an OVERLAPPED structure that notifies the caller of any changes in the routing table. + /// /// - /// If the function succeeds, the return value is NO_ERROR if the caller specifies NULL for the Handle and overlapped parameters. If the caller specifies - /// non-NULL parameters, the return value for success is ERROR_IO_PENDING. + /// + /// If the function succeeds, the return value is NO_ERROR if the caller specifies NULL for the Handle and overlapped + /// parameters. If the caller specifies non- NULL parameters, the return value for success is ERROR_IO_PENDING. If the + /// function fails, use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_CANCELLED + /// The context is being deregistered, so the call was canceled immediately. + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed. This error is returned if the both the Handle and overlapped parameters are not NULL, but the + /// memory specified by the input parameters cannot be written by the calling process. This error is also returned if the client + /// already has made a change notification request, so this duplicate request will fail. + /// + /// + /// + /// ERROR_NOT_ENOUGH_MEMORY + /// There was insufficient memory available to complete the operation. + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// This error is returned on versions of Windows where this function is not supported such as Windows 98/95 and Windows NT 4.0. + /// + /// + /// /// - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// The + /// NotifyRouteChange function may be called in two ways: + /// + /// + /// Synchronous method + /// + /// + /// Asynchronous method + /// + /// + /// + /// If the caller specifies NULL for the Handle and overlapped parameters, the call to NotifyRouteChange is synchronous + /// and will block until an IPv4 routing table change occurs. In this case if a change occurs, the NotifyRouteChange function + /// completes to indicate that a change has occurred. + /// + /// + /// If the NotifyRouteChange function is called synchronously, a notification will be sent on the next IPv4 routing change + /// until the application terminates. + /// + /// + /// If the caller specifies a handle variable and an OVERLAPPED structure, the caller can use the returned handle with the + /// OVERLAPPED structure to receive asynchronous notification of IPv4 routing table changes. See the following topics for + /// information about using the handle and OVERLAPPED structure to receive notifications: + /// + /// + /// + /// Synchronization and Overlapped Input and Output + /// + /// + /// GetQueuedCompletionStatus + /// + /// + /// I/O Completion Ports + /// + /// + /// + /// If the application receives a notification and requires notification for the next change, then the NotifyRouteChange + /// function must be called again. + /// + /// + /// The CancelIPChangeNotify function cancels notification of IP address and route changes previously requested with successful calls + /// to the NotifyAddrChange or NotifyRouteChange functions. + /// + /// + /// Once an application has been notified of a change, the application can then call the GetIpForwardTable or GetIpForwardTable2 + /// function to retrieve the IPv4 routing table to determine what has changed. If the application is notified and requires + /// notification for the next change, then the NotifyRouteChange function must be called again. + /// + /// + /// If the NotifyRouteChange function is called asynchronously, a notification will be sent on the next IPv4 route change + /// until either the application cancels the notification by calling the CancelIPChangeNotify function or the application terminates. + /// If the application terminates, the system will automatically cancel the registration for the notification. It is still + /// recommended that an application explicitly cancel any notification before it terminates. + /// + /// Any registration for a notification does not persist across a system shut down or reboot. + /// + /// On Windows Vista and later, the NotifyRouteChange2 function can be used to register to be notified for changes to the IPv6 + /// routing table on the local computer. + /// + /// Examples + /// The following example waits for a change to occur in the IP routing table. + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-notifyroutechange DWORD NotifyRouteChange( PHANDLE + // Handle, LPOVERLAPPED overlapped ); + [DllImport(Lib.IpHlpApi, SetLastError = true, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "39f2ec4d-131a-4a0a-9740-0d96aaea2dc7")] public static extern unsafe Win32Error NotifyRouteChange(out IntPtr Handle, System.Threading.NativeOverlapped* overlapped); /// Converts a 6 byte Physical Address (MAC) to string. /// The physical address that must have a minimum of 6 values. /// Dashed hex value string representation of a Physical Address (MAC). - public static string PhysicalAddressToString(byte[] physAddr) => $"{physAddr[0]:X}-{physAddr[1]:X}-{physAddr[2]:X}-{physAddr[3]:X}-{physAddr[4]:X}-{physAddr[5]:X}"; + public static string PhysicalAddressToString(byte[] physAddr) + { + return $"{physAddr[0]:X}-{physAddr[1]:X}-{physAddr[2]:X}-{physAddr[3]:X}-{physAddr[4]:X}-{physAddr[5]:X}"; + } - /// The ResolveIpNetEntry2 function resolves the physical address for a neighbor IP address entry on the local computer. - /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this structure will be updated with the properties for neighbor IP address. - /// A pointer to a an optional source IP address used to select the interface to send the requests on for the neighbor IP address entry. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// The ResolveIpNetEntry2 function resolves the physical address for a neighbor IP address entry on the local computer. + /// + /// + /// + /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this structure will be + /// updated with the properties for neighbor IP address. + /// + /// + /// + /// + /// A pointer to a an optional source IP address used to select the interface to send the requests on for the neighbor IP address entry. + /// + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_BAD_NET_NAME + /// The network name cannot be found. This error is returned if the network with the neighbor IP address is unreachable. + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the + /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid IPv4 or IPv6 address, or both the + /// InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the Row parameter were unspecified. This error is + /// also returned if a loopback address was passed in the Address member. + /// + /// + /// + /// ERROR_NOT_FOUND + /// + /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or + /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified + /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter or no IPv6 stack is on the local computer and an IPv6 + /// address was specified in the Address member. + /// + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// The ResolveIpNetEntry2 function is defined on Windows Vista and later. + /// + /// The ResolveIpNetEntry2 function is used to resolve the physical address for a neighbor IP address entry on a local + /// computer. This function flushes any existing neighbor entry that matches the IP address on the interface and then resolves the + /// physical address (MAC) address by sending ARP requests for an IPv4 address or neighbor solicitation requests for an IPv6 address. + /// If the SourceAddress parameter is specified, the ResolveIpNetEntry2 function will select the interface with this source IP + /// address to send the requests on. If the SourceAddress parameter is not specified (NULL was passed in this parameter), the + /// ResolveIpNetEntry2 function will automatically select the best interface to send the requests on. + /// + /// + /// The Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid IPv4 or + /// IPv6 address and family. In addition, at least one of the following members in the MIB_IPNET_ROW2 structure pointed to the + /// Row parameter must be initialized to the interface: the InterfaceLuid or InterfaceIndex. + /// + /// + /// If the IP address passed in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter is a duplicate of an + /// existing neighbor IP address on the interface, the ResolveIpNetEntry2 function will flush the existing entry before + /// resolving the IP address. + /// + /// + /// On output when the call is successful, ResolveIpNetEntry2 retrieves the other properties for the neighbor IP address and + /// fills out the MIB_IPNET_ROW2 structure pointed to by the Row parameter. The PhysicalAddress and + /// PhysicalAddressLength members in the MIB_IPNET_ROW2 structure pointed to by the Row parameter will be initialized + /// to a valid physical address. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-resolveipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API + // ResolveIpNetEntry2( PMIB_IPNET_ROW2 Row, CONST SOCKADDR_INET *SourceAddress ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "37f9dc58-362d-413e-a593-4dda52fb7d8b")] public static extern Win32Error ResolveIpNetEntry2(ref MIB_IPNET_ROW2 Row, IntPtr SourceAddress = default(IntPtr)); - /// The ResolveIpNetEntry2 function resolves the physical address for a neighbor IP address entry on the local computer. - /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this structure will be updated with the properties for neighbor IP address. - /// A pointer to a an optional source IP address used to select the interface to send the requests on for the neighbor IP address entry. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// The ResolveIpNetEntry2 function resolves the physical address for a neighbor IP address entry on the local computer. + /// + /// + /// + /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. On successful return, this structure will be + /// updated with the properties for neighbor IP address. + /// + /// + /// + /// + /// A pointer to a an optional source IP address used to select the interface to send the requests on for the neighbor IP address entry. + /// + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_BAD_NET_NAME + /// The network name cannot be found. This error is returned if the network with the neighbor IP address is unreachable. + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the + /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid IPv4 or IPv6 address, or both the + /// InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the Row parameter were unspecified. This error is + /// also returned if a loopback address was passed in the Address member. + /// + /// + /// + /// ERROR_NOT_FOUND + /// + /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or + /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified + /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter or no IPv6 stack is on the local computer and an IPv6 + /// address was specified in the Address member. + /// + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// The ResolveIpNetEntry2 function is defined on Windows Vista and later. + /// + /// The ResolveIpNetEntry2 function is used to resolve the physical address for a neighbor IP address entry on a local + /// computer. This function flushes any existing neighbor entry that matches the IP address on the interface and then resolves the + /// physical address (MAC) address by sending ARP requests for an IPv4 address or neighbor solicitation requests for an IPv6 address. + /// If the SourceAddress parameter is specified, the ResolveIpNetEntry2 function will select the interface with this source IP + /// address to send the requests on. If the SourceAddress parameter is not specified (NULL was passed in this parameter), the + /// ResolveIpNetEntry2 function will automatically select the best interface to send the requests on. + /// + /// + /// The Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid IPv4 or + /// IPv6 address and family. In addition, at least one of the following members in the MIB_IPNET_ROW2 structure pointed to the + /// Row parameter must be initialized to the interface: the InterfaceLuid or InterfaceIndex. + /// + /// + /// If the IP address passed in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter is a duplicate of an + /// existing neighbor IP address on the interface, the ResolveIpNetEntry2 function will flush the existing entry before + /// resolving the IP address. + /// + /// + /// On output when the call is successful, ResolveIpNetEntry2 retrieves the other properties for the neighbor IP address and + /// fills out the MIB_IPNET_ROW2 structure pointed to by the Row parameter. The PhysicalAddress and + /// PhysicalAddressLength members in the MIB_IPNET_ROW2 structure pointed to by the Row parameter will be initialized + /// to a valid physical address. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-resolveipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API + // ResolveIpNetEntry2( PMIB_IPNET_ROW2 Row, CONST SOCKADDR_INET *SourceAddress ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "37f9dc58-362d-413e-a593-4dda52fb7d8b")] public static extern Win32Error ResolveIpNetEntry2(ref MIB_IPNET_ROW2 Row, ref SOCKADDR_INET SourceAddress); /// - /// The SendARP function sends an Address Resolution Protocol (ARP) request to obtain the physical address that corresponds to the specified destination - /// IPv4 address. + /// + /// The SendARP function sends an Address Resolution Protocol (ARP) request to obtain the physical address that corresponds to + /// the specified destination IPv4 address. + /// /// /// - /// The destination IPv4 address, in the form of an IPAddr structure. The ARP request attempts to obtain the physical address that corresponds to this - /// IPv4 address. + /// + /// The destination IPv4 address, in the form of an IPAddr structure. The ARP request attempts to obtain the physical address that + /// corresponds to this IPv4 address. + /// /// /// - /// The source IPv4 address of the sender, in the form of an IPAddr structure. This parameter is optional and is used to select the interface to send the - /// request on for the ARP entry. The caller may specify zero corresponding to the INADDR_ANY IPv4 address for this parameter. + /// + /// The source IPv4 address of the sender, in the form of an IPAddr structure. This parameter is optional and is used to select the + /// interface to send the request on for the ARP entry. The caller may specify zero corresponding to the INADDR_ANY IPv4 + /// address for this parameter. + /// /// /// - /// A pointer to an array of ULONG variables. This array must have at least two ULONG elements to hold an Ethernet or token ring physical address. The - /// first six bytes of this array receive the physical address that corresponds to the IPv4 address specified by the DestIP parameter. + /// + /// A pointer to an array of ULONG variables. This array must have at least two ULONG elements to hold an Ethernet or + /// token ring physical address. The first six bytes of this array receive the physical address that corresponds to the IPv4 address + /// specified by the DestIP parameter. + /// /// /// - /// On input, a pointer to a ULONG value that specifies the maximum buffer size, in bytes, the application has set aside to receive the physical address - /// or MAC address. The buffer size should be at least 6 bytes for an Ethernet or token ring physical address + /// + /// On input, a pointer to a ULONG value that specifies the maximum buffer size, in bytes, the application has set aside to + /// receive the physical address or MAC address. The buffer size should be at least 6 bytes for an Ethernet or token ring physical address + /// /// The buffer to receive the physical address is pointed to by the pMacAddr parameter. - /// On successful output, this parameter points to a value that specifies the number of bytes written to the buffer pointed to by the pMacAddr. + /// + /// On successful output, this parameter points to a value that specifies the number of bytes written to the buffer pointed to by the pMacAddr. + /// /// - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// 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 on Windows Vista and later when an ARP reply to the SendARP request was + /// not received. This error occurs if the destination IPv4 address could not be reached because it is not on the same subnet or the + /// destination computer is not operating. + /// + /// + /// + /// ERROR_BUFFER_OVERFLOW + /// + /// The file name is too long. This error is returned on Windows Vista if the ULONG value pointed to by the PhyAddrLen parameter is + /// less than 6, the size required to store a complete physical address. + /// + /// + /// + /// ERROR_GEN_FAILURE + /// + /// A device attached to the system is not functioning. This error is returned on Windows Server 2003 and earlier when an ARP reply + /// to the SendARP request was not received. This error can occur if destination IPv4 address could not be reached because it is not + /// on the same subnet or the destination computer is not operating. + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// One of the parameters is invalid. This error is returned on Windows Server 2003 and earlier if either the pMacAddr or PhyAddrLen + /// parameter is a NULL pointer. + /// + /// + /// + /// ERROR_INVALID_USER_BUFFER + /// + /// The supplied user buffer is not valid for the requested operation. This error is returned on Windows Server 2003 and earlier if + /// the ULONG value pointed to by the PhyAddrLen parameter is zero. + /// + /// + /// + /// ERROR_NOT_FOUND + /// + /// Element not found. This error is returned on Windows Vista if the the SrcIp parameter does not specify a source IPv4 address on + /// an interface on the local computer or the INADDR_ANY IP address (an IPv4 address of 0.0.0.0). + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// The SendARP function is not supported by the operating system running on the local computer. + /// + /// + /// Other + /// If the function fails, use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// The SendARP function is used to request the physical hardware address (sometimes referred to as the MAC address) that + /// corresponds to a specified destination IPv4 address. If the information requested is not in the ARP table on the local computer, + /// then the SendARP function will cause an ARP request to be sent to obtain the physical address. If the function is + /// successful, the physical address that corresponds to the specified destination IPv4 address is returned in the array pointed to + /// by the pMacAddr parameter. + /// + /// + /// The physical address of an IPv4 address is only available if the destination IPv4 address is on the local subnet (the IPv4 + /// address can be reached directly without going through any routers). The SendARP function will fail if the destination IPv4 + /// address is not on the local subnet. + /// + /// + /// If the SendARP function is successful on Windows Vista and later, the ARP table on the local computer is updated with the + /// results. If the SendARP function is successful on Windows Server 2003 and earlier, the ARP table on the local computer is + /// not affected. + /// + /// + /// The SendARP function on Windows Vista and later returns different error return values than the SendARP function on + /// Windows Server 2003 and earlier. + /// + /// + /// On Windows Vista and later, a NULL pointer passed as the pMacAddr or PhyAddrLen parameter to the SendARP function + /// causes an access violation and the application is terminated. If an error occurs on Windows Vista and later and + /// ERROR_BAD_NET_NAME, ERROR_BUFFER_OVERFLOW, or ERROR_NOT_FOUND is returned, the ULONG value pointed to + /// by the PhyAddrLen parameter is set to zero. If the ULONG value pointed to by the PhyAddrLen parameter is less than 6 on + /// Windows Vista and later, SendARP function returns ERROR_BUFFER_OVERFLOW indicating the buffer to receive the + /// physical address is too small. If the SrcIp parameter specifies an IPv4 address that is not an interface on the local computer, + /// the SendARP function on Windows Vista and later returns ERROR_NOT_FOUND. + /// + /// + /// On Windows Server 2003 and earlier, a NULL pointer passed as the pMacAddr or PhyAddrLen parameter to the SendARP + /// function returns ERROR_INVALID_PARAMETER. If an error occurs on Windows Server 2003 and earlier and + /// ERROR_GEN_FAILURE or ERROR_INVALID_USER_BUFFER is returned, the ULONG value pointed to by the PhyAddrLen + /// parameter is set to zero. If the ULONG value pointed to by the PhyAddrLen parameter is less than 6 on Windows Server 2003 + /// and earlier, the SendARP function does not return an error but only returns part of the hardware address in the array + /// pointed to by the pMacAddr parameter. So if the value pointed to by the PhyAddrLen parameter is 4, then only the first 4 bytes of + /// the hardware address are returned in the array pointed to by the pMacAddr parameter. If the SrcIp parameter specifies an IPv4 + /// address that is not an interface on the local computer, the SendARP function on Windows Server 2003 and earlier ignores + /// the SrcIp parameter and uses an IPv4 address on the local computer for the source IPv4 address. + /// + /// The GetIpNetTable function retrieves the ARP table on the local computer that maps IPv4 addresses to physical addresses. + /// The CreateIpNetEntry function creates an ARP entry in the ARP table on the local computer. + /// The DeleteIpNetEntry function deletes an ARP entry from the ARP table on the local computer. + /// The SetIpNetEntry function modifies an existing ARP entry in the ARP table on the local computer. + /// The FlushIpNetTable function deletes all ARP entries for the specified interface from the ARP table on the local computer. + /// + /// On Windows Vista and later, the ResolveIpNetEntry2 function can used to replace the SendARP function. An ARP request is + /// sent if the Address member of the MIB_IPNET_ROW2 structure passed to the ResolveIpNetEntry2 function is an IPv4 address. + /// + /// + /// On Windows Vista, a new group of functions can be used to access, modify, and delete the ARP table entries when the + /// Address member of the MIB_IPNET_ROW2 structure passed to these functions is an IPv4 address. The new functions include the + /// following: GetIpNetTable2, CreateIpNetEntry2, DeleteIpNetEntry2, FlushIpNetTable2, and SetIpNetEntry2. + /// + /// + /// For information about the IPAddr data type, see Windows Data Types. To convert an IP address between dotted decimal + /// notation and IPAddr format, use the inet_addr and inet_ntoa functions. + /// + /// Examples + /// + /// The following code demonstrates how to obtain the hardware or media access control (MAC) address associated with a specified IPv4 address. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-sendarp DWORD SendARP( IPAddr DestIP, IPAddr SrcIP, + // PVOID pMacAddr, PULONG PhyAddrLen ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "5cbaf45a-a64e-49fd-a920-01759b5c4f81")] public static extern Win32Error SendARP(IN_ADDR DestIP, IN_ADDR SrcIP, byte[] pMacAddr, ref uint PhyAddrLen); /// - /// The SendARP function sends an Address Resolution Protocol (ARP) request to obtain the physical address that corresponds to the specified destination - /// IPv4 address. + /// The SendARP function sends an Address Resolution Protocol (ARP) request to obtain the physical address that corresponds to the + /// specified destination IPv4 address. /// /// - /// The destination IPv4 address, in the form of an IPAddr structure. The ARP request attempts to obtain the physical address that corresponds to this - /// IPv4 address. + /// The destination IPv4 address, in the form of an IPAddr structure. The ARP request attempts to obtain the physical address that + /// corresponds to this IPv4 address. /// /// - /// The source IPv4 address of the sender, in the form of an IPAddr structure. This parameter is optional and is used to select the interface to send the - /// request on for the ARP entry. The caller may specify zero corresponding to the INADDR_ANY IPv4 address for this parameter. + /// The source IPv4 address of the sender, in the form of an IPAddr structure. This parameter is optional and is used to select the + /// interface to send the request on for the ARP entry. The caller may specify zero corresponding to the INADDR_ANY IPv4 address for + /// this parameter. /// /// The physical address that corresponds to the IPv4 address specified by the DestIP parameter. public static byte[] SendARP(IN_ADDR DestIP, IN_ADDR SrcIP = default(IN_ADDR)) { uint len = 6; - var ret = new byte[(int)len]; + byte[] ret = new byte[(int)len]; SendARP(DestIP, SrcIP, ret, ref len).ThrowIfFailed(); return ret; } - /// The SetIpNetEntry function modifies an existing ARP entry in the ARP table on the local computer. - /// A pointer to a MIB_IPNETROW structure. The information in this structure specifies the entry to modify and the new information for the entry. The caller must specify values for all members of this structure. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// The SetIpNetEntry function modifies an existing ARP entry in the ARP table on the local computer. + /// + /// + /// + /// A pointer to a MIB_IPNETROW structure. The information in this structure specifies the entry to modify and the new information + /// for the entry. The caller must specify values for all members of this 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_ACCESS_DENIED + /// + /// Access is denied. This error is returned on Windows Vista and Windows Server 2008 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 + /// + /// The pArpEntry parameter is NULL, or SetIpNetEntry is unable to read from the memory pointed to by pArpEntry, or one of the + /// members of the MIB_IPNETROW structure is invalid. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// The IPv4 transport is not configured on the local computer. + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// + /// On Windows Vista and later , the SetIpNetEntry function can only be called by a user logged on as a member of the + /// Administrators group. If SetIpNetEntry 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 SetIpNetEntry 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. + /// + /// + /// Note On Windows NT 4.0 and Windows 2000 and later, this function executes a privileged operation. For this function to + /// execute successfully, the caller must be logged on as a member of the Administrators group or the NetworkConfigurationOperators group. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-setipnetentry DWORD SetIpNetEntry( PMIB_IPNETROW + // pArpEntry ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "d985b749-5aa3-4b4a-ba8f-bc8edcf1b1f3")] public static extern Win32Error SetIpNetEntry(ref MIB_IPNETROW pArpEntry); - /// The SetIpNetEntry2 function sets the physical address of an existing neighbor IP address entry on the local computer. - /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// The SetIpNetEntry2 function sets the physical address of an existing neighbor IP address entry on the local computer. + /// + /// + /// A pointer to a MIB_IPNET_ROW2 structure entry for a neighbor IP address entry. + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, the return value is one of the following error codes. + /// + /// + /// Return code + /// Description + /// + /// + /// ERROR_ACCESS_DENIED + /// + /// Access is denied. This error is returned under several conditions that include the following: the user lacks the required + /// administrative privileges on the local computer or the application is not running in an enhanced shell as the built-in + /// Administrator (RunAs administrator). + /// + /// + /// + /// ERROR_INVALID_PARAMETER + /// + /// An invalid parameter was passed to the function. This error is returned if a NULL pointer is passed in the Row parameter, the + /// Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter was not set to a valid unicast, anycast, or multicast IPv4 + /// or IPv6 address, the PhysicalAddress and PhysicalAddressLength members of the MIB_IPNET_ROW2 pointed to by the Row parameter were + /// not set to a valid physical address, or both the InterfaceLuid or InterfaceIndex members of the MIB_IPNET_ROW2 pointed to by the + /// Row parameter were unspecified. This error is also returned if a loopback address was passed in the Address member. + /// + /// + /// + /// ERROR_NOT_FOUND + /// + /// The specified interface could not be found. This error is returned if the network interface specified by the InterfaceLuid or + /// InterfaceIndex member of the MIB_IPNET_ROW2 pointed to by the Row parameter could not be found. + /// + /// + /// + /// ERROR_NOT_SUPPORTED + /// + /// The request is not supported. This error is returned if no IPv4 stack is on the local computer and an IPv4 address was specified + /// in the Address member of the MIB_IPNET_ROW2 pointed to by the Row parameter or no IPv6 stack is on the local computer and an IPv6 + /// address was specified in the Address member. + /// + /// + /// + /// Other + /// Use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// + /// The SetIpNetEntry2 function is defined on Windows Vista and later. + /// + /// The SetIpNetEntry2 function is used to set the physical address for an existing neighbor IP address entry on a local computer. + /// + /// + /// The Address member in the MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid unicast, + /// anycast, or multicast IPv4 or IPv6 address and family. The PhysicalAddress and PhysicalAddressLength members in the + /// MIB_IPNET_ROW2 structure pointed to by the Row parameter must be initialized to a valid physical address. In addition, at + /// least one of the following members in the MIB_IPNET_ROW2 structure pointed to the Row parameter must be initialized to the + /// interface: the InterfaceLuid or InterfaceIndex. + /// + /// + /// The SetIpNetEntry2 function will fail if the IP address passed in the Address member of the MIB_IPNET_ROW2 pointed + /// to by the Row parameter is not an existing neighbor IP address on the interface specified. + /// + /// + /// The SetIpNetEntry2 function can only be called by a user logged on as a member of the Administrators group. If + /// SetIpNetEntry2 is called by a user that is not a member of the Administrators group, the function call will fail and + /// ERROR_ACCESS_DENIED is returned. + /// + /// + /// The SetIpNetEntry2 function can also fail because of user account control (UAC) on Windows Vista and later. If an + /// application that contains this function is executed by a user logged on as a member of the Administrators group other than the + /// built-in Administrator, this call will fail unless the application has been marked in the manifest file with a + /// requestedExecutionLevel set to requireAdministrator. If the application lacks this manifest file, a user logged on as a + /// member of the Administrators group other than the built-in Administrator must then be executing the application in an enhanced + /// shell as the built-in Administrator (RunAs administrator) for this function to succeed. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/netioapi/nf-netioapi-setipnetentry2 _NETIOAPI_SUCCESS_ NETIOAPI_API + // SetIpNetEntry2( PMIB_IPNET_ROW2 Row ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("netioapi.h", MSDNShortId = "4f423700-f721-44a9-ade3-ea5b5b86e394")] public static extern Win32Error SetIpNetEntry2(ref MIB_IPNET_ROW2 Row); /// - /// The UnenableRouter function decrements the reference count that tracks the number of requests to enable IPv4 forwarding. When this reference count - /// reaches zero, UnenableRouter turns off IPv4 forwarding on the local computer. + /// + /// The UnenableRouter function decrements the reference count that tracks the number of requests to enable IPv4 forwarding. + /// When this reference count reaches zero, UnenableRouter turns off IPv4 forwarding on the local computer. + /// /// /// + /// /// A pointer to an OVERLAPPED structure. This structure should be the same as the one used in the call to the EnableRouter function. + /// /// - /// An optional pointer to a DWORD variable. This variable receives the number of references remaining. - /// If the function succeeds, the return value is NO_ERROR. If the function fails, the return value is an error code. - [PInvokeData("Iphlpapi.h")] - [DllImport(Lib.IpHlpApi, ExactSpelling = true)] + /// + /// An optional pointer to a DWORD variable. This variable receives the number of references remaining. + /// + /// + /// If the function succeeds, the return value is NO_ERROR. + /// If the function fails, use FormatMessage to obtain the message string for the returned error. + /// + /// + /// + /// The UnenableRouter function is specific to IPv4 forwarding. Each call that a process makes to UnenableRouter must + /// correspond to a previous call to EnableRouter by the same process. The system returns an error on extraneous calls to + /// UnenableRouter. As a result, a given process is not able to decrement the reference count that tracks the number of + /// requests for enabling IPv4 forwarding for another process. Also, if IPv4 forwarding was enabled by a given process, it cannot be + /// disabled by a different process. + /// + /// + /// It is not possible to accurately determine the reference count that tracks the number of requests for enabling IPv4 forwarding + /// since there might be other outstanding EnableRouter requests. So the value returned for the lpdwEnableCountparmameter is always a + /// large count equal to ULONG_MAX/2. + /// + /// + /// If the process that calls EnableRouter terminates without calling UnenableRouter, the system decrements the reference + /// count that tracks requests to enable IPv4 forwarding as though the process had called UnenableRouter. + /// + /// + /// After calling the UnenableRouter, use the CloseHandle call to close the handle to the event object in the OVERLAPPED structure. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-unenablerouter DWORD UnenableRouter( OVERLAPPED + // *pOverlapped, LPDWORD lpdwEnableCount ); + [DllImport(Lib.IpHlpApi, SetLastError = false, ExactSpelling = true)] + [PInvokeData("iphlpapi.h", MSDNShortId = "95f0387f-24e8-4382-b78e-e59bcec0f2ed")] public static extern unsafe Win32Error UnenableRouter(System.Threading.NativeOverlapped* pOverlapped, out uint lpdwEnableCount); - [PInvokeData("Iphlpapi.h")] + /// + /// The FIXED_INFO structure contains information that is the same across all the interfaces on a computer. + /// + /// + /// The FIXED_INFO structure is retrieved by the GetNetworkParams function. + /// + /// In the Microsoft Windows Software Development Kit (SDK), the FIXED_INFO_WIN2KSP1 structure is defined. When compiling an + /// application if the target platform is Windows 2000 with Service Pack 1 (SP1) and later (, , or ), the FIXED_INFO_WIN2KSP1 + /// struct is typedefed to the FIXED_INFO structure. When compiling an application if the target platform is not Windows 2000 + /// with SP1 and later, the FIXED_INFO structure is undefined. + /// + /// + /// The GetNetworkParams function and the FIXED_INFO structure are supported on Windows 98and later. But to build an + /// application for a target platform earlier than Windows 2000 with Service Pack 1 (SP1), an earlier version of the Platform + /// Software Development Kit (SDK) must be used. + /// + /// Examples + /// + /// The following code retrieves a FIXED_INFO structure that contains network configuration information for the local + /// computer. The code prints selected members from the structure. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-fixed_info_w2ksp1 + // typedef struct FIXED_INFO_W2KSP1 { char HostName[MAX_HOSTNAME_LEN + 4]; char DomainName[MAX_DOMAIN_NAME_LEN + 4]; PIP_ADDR_STRING CurrentDnsServer; IP_ADDR_STRING DnsServerList; UINT NodeType; char ScopeId[MAX_SCOPE_ID_LEN + 4]; UINT EnableRouting; UINT EnableProxy; UINT EnableDns; } *PFIXED_INFO_W2KSP1; + [PInvokeData("iptypes.h", MSDNShortId = "6dcf33c6-33dc-4583-9b04-5231948d3d9a")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct FIXED_INFO { + /// + /// Type: char[MAX_HOSTNAME_LEN + 4] + /// + /// The hostname for the local computer. This may be the fully qualified hostname (including the domain) for a computer that is + /// joined to a domain. + /// + /// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_HOSTNAME_LEN + 4)] public string HostName; + + /// + /// Type: char[MAX_DOMAIN_NAME_LEN + 4] + /// The domain in which the local computer is registered. + /// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_HOSTNAME_LEN + 4)] public string DomainName; + + /// + /// Type: PIP_ADDR_STRING + /// Reserved. Use the DnsServerList member to obtain the DNS servers for the local computer. + /// public IntPtr CurrentDnsServer; + + /// + /// Type: IP_ADDR_STRING + /// A linked list of IP_ADDR_STRING structures that specify the set of DNS servers used by the local computer. + /// public IP_ADDR_STRING DnsServerList; + + /// + /// Type: UINT + /// The node type of the local computer. These values are defined in the Iptypes.h header file. + /// + /// + /// NodeType + /// Meaning + /// + /// + /// BROADCAST_NODETYPE 0x0001 + /// A broadcast nodetype. + /// + /// + /// PEER_TO_PEER_NODETYPE 0x0002 + /// A peer to peer nodetype. + /// + /// + /// MIXED_NODETYPE 0x0004 + /// A mixed nodetype. + /// + /// + /// HYBRID_NODETYPE 0x0008 + /// A hybrid nodetype. + /// + /// + /// public NetBiosNodeType NodeType; + + /// + /// Type: char[MAX_SCOPE_ID_LEN + 4] + /// The DHCP scope name. + /// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_SCOPE_ID_LEN + 4)] public string ScopeId; + + /// + /// Type: UINT + /// A Boolean value that specifies whether routing is enabled on the local computer. + /// [MarshalAs(UnmanagedType.Bool)] public bool EnableRouting; + + /// + /// Type: UINT + /// A Boolean value that specifies whether the local computer is acting as an ARP proxy. + /// [MarshalAs(UnmanagedType.Bool)] public bool EnableProxy; + + /// + /// Type: UINT + /// A Boolean value that specifies whether DNS is enabled on the local computer. + /// [MarshalAs(UnmanagedType.Bool)] public bool EnableDns; } - [PInvokeData("Iphlpapi.h")] + /// + /// + /// The IP_ADAPTER_ADDRESSES structure is the header node for a linked list of addresses for a particular adapter. This + /// structure can simultaneously be used as part of a linked list of IP_ADAPTER_ADDRESSES structures. + /// + /// + /// + /// + /// The GetAdaptersAddresses function retrieves information for IPv4 and IPv6 addresses and returns this information as a linked list + /// of IP_ADAPTER_ADDRESSES structures + /// + /// + /// The adapter index values specified in the IfIndex and Ipv6IfIndex members may change when an adapter is disabled + /// and then enabled, or under other circumstances, and should not be considered persistent. + /// + /// + /// The values for the IfType member are defined in the Ipifcons.h header file. Only the possible values listed in the + /// description of the IfType member are currently supported. + /// + /// + /// The size of the IP_ADAPTER_ADDRESSES structure changed on Windows XP with SP1 and later. The size of the + /// IP_ADAPTER_ADDRESSES structure also changed on Windows Vista and later. The size of the IP_ADAPTER_ADDRESSES + /// structure also changed on Windows Vista with SP1and later and onWindows Server 2008 and later. The Length member should be + /// used to determine which version of the IP_ADAPTER_ADDRESSES structure is being used. + /// + /// + /// The version of the IP_ADAPTER_ADDRESSES structure on Windows XP with SP1 and later has the following new members added: + /// Ipv6IfIndex, ZoneIndices, and FirstPrefix. + /// + /// + /// The version of the IP_ADAPTER_ADDRESSES structure on Windows Vista and later has the following new members added: + /// TransmitLinkSpeed, ReceiveLinkSpeed, FirstWinsServerAddress, FirstGatewayAddress, Ipv4Metric, + /// Ipv6Metric, Luid, Dhcpv4Server, CompartmentId, NetworkGuid, ConnectionType, + /// TunnelType, Dhcpv6Server, Dhcpv6ClientDuid, Dhcpv6ClientDuidLength, and Dhcpv6Iaid. + /// + /// + /// The version of the IP_ADAPTER_ADDRESSES structure on Windows Vista with SP1and later and on Windows Server 2008 and later + /// has the following new member added: FirstDnsSuffix. + /// + /// + /// The Ipv4Metric and Ipv6Metric members are used to prioritize route metrics for routes connected to multiple + /// interfaces on the local computer. + /// + /// + /// The order of linked IP_ADAPTER_UNICAST_ADDRESS structures pointed to by the FirstUnicastAddress member that are returned + /// by the GetAdaptersAddresses function does not reflect the order that IP addresses were added to an adapter and may vary between + /// versions of Windows. Similarly, the order of linked IP_ADAPTER_ANYCAST_ADDRESS structures pointed to by the + /// FirstAnycastAddress member and the order of linked IP_ADAPTER_MULTICAST_ADDRESS structures pointed to by the + /// FirstMulticastAddress member do not reflect the order that IP addresses were added to an adapter and may vary between + /// versions of Windows. + /// + /// + /// In addition, the linked IP_ADAPTER_UNICAST_ADDRESS structures pointed to by the FirstUnicastAddress member and the linked + /// IP_ADAPTER_PREFIXstructures pointed to by the FirstPrefix member are maintained as separate internal linked lists by the + /// operating system. As a result, the order of linked IP_ADAPTER_UNICAST_ADDRESS structures pointed to by the + /// FirstUnicastAddress member does not have any relationship with the order of linked IP_ADAPTER_PREFIX structures + /// pointed to by the FirstPrefix member. + /// + /// + /// On Windows Vista and later, the linked IP_ADAPTER_PREFIXstructures pointed to by the FirstPrefix member include three IP + /// adapter prefixes for each IP address assigned to the adapter. These include the host IP address prefix, the subnet IP address + /// prefix, and the subnet broadcast IP address prefix. In addition, for each adapter there is a multicast address prefix and a + /// broadcast address prefix. + /// + /// + /// On Windows XP with SP1 and later prior to Windows Vista, the linked IP_ADAPTER_PREFIXstructures pointed to by the + /// FirstPrefix member include only a single IP adapter prefix for each IP address assigned to the adapter. + /// + /// + /// In the Windows SDK, the version of the structure for use on Windows Vista and later is defined as IP_ADAPTER_ADDRESSES_LH. + /// In the Microsoft Windows Software Development Kit (SDK), the version of this structure to be used on earlier systems including + /// Windows XP with SP1 and later is defined as IP_ADAPTER_ADDRESSES_XP. When compiling an application if the target platform + /// is Windows Vista and later (, , or ), the IP_ADAPTER_ADDRESSES_LH structure is typedefed to the + /// IP_ADAPTER_ADDRESSES structure. When compiling an application if the target platform is not Windows Vista and later, the + /// IP_ADAPTER_ADDRESSES_XP structure is typedefed to the IP_ADAPTER_ADDRESSES structure. + /// + /// + /// The SOCKET_ADDRESS structure is used in the IP_ADAPTER_ADDRESSES structure. On the Windows SDK released for Windows Vista + /// and later, the organization of header files has changed and the SOCKET_ADDRESS structure is defined in the Ws2def.h header + /// file which is automatically included by the Winsock2.h header file. On the Platform Software Development Kit (SDK) released for + /// Windows Server 2003 and Windows XP, the SOCKET_ADDRESS structure is declared in the Winsock2.h header file. In order to + /// use the IP_ADAPTER_ADDRESSES structure, the Winsock2.h header file must be included before the Iphlpapi.h header file. + /// + /// Examples + /// + /// This example retrieves the IP_ADAPTER_ADDRESSES structure for the adapters associated with the system and prints some + /// members for each adapter interface. + /// + /// + // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_adapter_addresses_lh typedef struct + // _IP_ADAPTER_ADDRESSES_LH { union { ULONGLONG Alignment; struct { ULONG Length; IF_INDEX IfIndex; }; }; struct + // _IP_ADAPTER_ADDRESSES_LH *Next; PCHAR AdapterName; PIP_ADAPTER_UNICAST_ADDRESS_LH FirstUnicastAddress; + // PIP_ADAPTER_ANYCAST_ADDRESS_XP FirstAnycastAddress; PIP_ADAPTER_MULTICAST_ADDRESS_XP FirstMulticastAddress; + // PIP_ADAPTER_DNS_SERVER_ADDRESS_XP FirstDnsServerAddress; PWCHAR DnsSuffix; PWCHAR Description; PWCHAR FriendlyName; BYTE + // PhysicalAddress[MAX_ADAPTER_ADDRESS_LENGTH]; ULONG PhysicalAddressLength; union { ULONG Flags; struct { ULONG DdnsEnabled : 1; + // ULONG RegisterAdapterSuffix : 1; ULONG Dhcpv4Enabled : 1; ULONG ReceiveOnly : 1; ULONG NoMulticast : 1; ULONG + // Ipv6OtherStatefulConfig : 1; ULONG NetbiosOverTcpipEnabled : 1; ULONG Ipv4Enabled : 1; ULONG Ipv6Enabled : 1; ULONG + // Ipv6ManagedAddressConfigurationSupported : 1; }; }; ULONG Mtu; IFTYPE IfType; IF_OPER_STATUS OperStatus; IF_INDEX Ipv6IfIndex; + // ULONG ZoneIndices[16]; PIP_ADAPTER_PREFIX_XP FirstPrefix; ULONG64 TransmitLinkSpeed; ULONG64 ReceiveLinkSpeed; + // PIP_ADAPTER_WINS_SERVER_ADDRESS_LH FirstWinsServerAddress; PIP_ADAPTER_GATEWAY_ADDRESS_LH FirstGatewayAddress; ULONG Ipv4Metric; + // ULONG Ipv6Metric; IF_LUID Luid; SOCKET_ADDRESS Dhcpv4Server; NET_IF_COMPARTMENT_ID CompartmentId; NET_IF_NETWORK_GUID NetworkGuid; + // NET_IF_CONNECTION_TYPE ConnectionType; TUNNEL_TYPE TunnelType; SOCKET_ADDRESS Dhcpv6Server; BYTE + // Dhcpv6ClientDuid[MAX_DHCPV6_DUID_LENGTH]; ULONG Dhcpv6ClientDuidLength; ULONG Dhcpv6Iaid; PIP_ADAPTER_DNS_SUFFIX FirstDnsSuffix; } + // IP_ADAPTER_ADDRESSES_LH, *PIP_ADAPTER_ADDRESSES_LH; + [PInvokeData("iptypes.h", MSDNShortId = "a2df3749-6c75-40c0-8952-1656bbe639a6")] [StructLayout(LayoutKind.Sequential)] public struct IP_ADAPTER_ADDRESSES { public uint Length; public uint IfIndex; + /// + /// Type: struct _IP_ADAPTER_ADDRESSES* + /// A pointer to the next adapter addresses structure in the list. + /// public IntPtr Next; + + /// + /// Type: PCHAR + /// + /// An array of characters that contains the name of the adapter with which these addresses are associated. Unlike an adapter's + /// friendly name, the adapter name specified in AdapterName is permanent and cannot be modified by the user. + /// + /// [MarshalAs(UnmanagedType.LPStr)] public string AdapterName; + + /// + /// Type: PIP_ADAPTER_UNICAST_ADDRESS + /// A pointer to the first IP_ADAPTER_UNICAST_ADDRESS structure in a linked list of IP unicast addresses for the adapter. + /// public IntPtr FirstUnicastAddress; + /// + /// Type: PIP_ADAPTER_ANYCAST_ADDRESS + /// A pointer to the first IP_ADAPTER_ANYCAST_ADDRESS structure in a linked list of IP anycast addresses for the adapter. + /// public IntPtr FirstAnycastAddress; + /// + /// Type: PIP_ADAPTER_MULTICAST_ADDRESS + /// A pointer to the first IP_ADAPTER_MULTICAST_ADDRESS structure in a list of IP multicast addresses for the adapter. + /// public IntPtr FirstMulticastAddress; + /// + /// Type: PIP_ADAPTER_DNS_SERVER_ADDRESS + /// A pointer to the first IP_ADAPTER_DNS_SERVER_ADDRESS structure in a linked list of DNS server addresses for the adapter. + /// public IntPtr FirstDnsServerAddress; + + /// + /// Type: PWCHAR + /// The Domain Name System (DNS) suffix associated with this adapter. + /// [MarshalAs(UnmanagedType.LPWStr)] public string DnsSuffix; + + /// + /// Type: PWCHAR + /// A description for the adapter. This member is read-only. + /// [MarshalAs(UnmanagedType.LPWStr)] public string Description; + + /// + /// Type: PWCHAR + /// + /// A user-friendly name for the adapter. For example: "Local Area Connection 1." This name appears in contexts such as the + /// ipconfig command line program and the Connection folder. This member is read only and can't be modified using any IP + /// Helper functions. + /// + /// + /// This member is the ifAlias field used by NDIS as described in RFC 2863. The ifAlias field can be set by an NDIS interface + /// provider when the NDIS driver is installed. For NDIS miniport drivers, this field is set by NDIS. + /// + /// [MarshalAs(UnmanagedType.LPWStr)] public string FriendlyName; + + /// + /// Type: BYTE[MAX_ADAPTER_ADDRESS_LENGTH] + /// + /// The Media Access Control (MAC) address for the adapter. For example, on an Ethernet network this member would specify the + /// Ethernet hardware address. + /// + /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_ADAPTER_ADDRESS_LENGTH)] public byte[] PhysicalAddress; + + /// + /// Type: DWORD + /// + /// The length, in bytes, of the address specified in the PhysicalAddress member. For interfaces that do not have a + /// data-link layer, this value is zero. + /// + /// public uint PhysicalAddressLength; public IP_ADAPTER_FLAGS Flags; + /// + /// Type: DWORD + /// The maximum transmission unit (MTU) size, in bytes. + /// public uint Mtu; + /// + /// Type: DWORD + /// + /// The interface type as defined by the Internet Assigned Names Authority (IANA). Possible values for the interface type are + /// listed in the Ipifcons.h header file. + /// + /// The table below lists common values for the interface type although many other values are possible. + /// + /// + /// Value + /// Meaning + /// + /// + /// IF_TYPE_OTHER 1 + /// Some other type of network interface. + /// + /// + /// IF_TYPE_ETHERNET_CSMACD 6 + /// An Ethernet network interface. + /// + /// + /// IF_TYPE_ISO88025_TOKENRING 9 + /// A token ring network interface. + /// + /// + /// IF_TYPE_PPP 23 + /// A PPP network interface. + /// + /// + /// IF_TYPE_SOFTWARE_LOOPBACK 24 + /// A software loopback network interface. + /// + /// + /// IF_TYPE_ATM 37 + /// An ATM network interface. + /// + /// + /// IF_TYPE_IEEE80211 71 + /// + /// An IEEE 802.11 wireless network interface. On Windows Vista and later, wireless network cards are reported as + /// IF_TYPE_IEEE80211. On earlier versions of Windows, wireless network cards are reported as IF_TYPE_ETHERNET_CSMACD. On Windows + /// XP with SP3 and on Windows XP with SP2 x86 with the Wireless LAN API for Windows XP with SP2 installed, the + /// WlanEnumInterfaces function can be used to enumerate wireless interfaces on the local computer. + /// + /// + /// + /// IF_TYPE_TUNNEL 131 + /// A tunnel type encapsulation network interface. + /// + /// + /// IF_TYPE_IEEE1394 144 + /// An IEEE 1394 (Firewire) high performance serial bus network interface. + /// + /// + /// public IFTYPE IfType; + /// + /// Type: IF_OPER_STATUS + /// + /// The operational status for the interface as defined in RFC 2863. For more information, see + /// http://www.ietf.org/rfc/rfc2863.txt. This member can be one of the values from the IF_OPER_STATUS enumeration type + /// defined in the Iftypes.h header file. On Windows Vista and later, the header files were reorganized and this enumeration is + /// defined in the Ifdef.h header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// IfOperStatusUp 1 + /// The interface is up and able to pass packets. + /// + /// + /// IfOperStatusDown 2 + /// + /// The interface is down and not in a condition to pass packets. The IfOperStatusDown state has two meanings, depending on the + /// value of AdminStatus member. If AdminStatus is not set to NET_IF_ADMIN_STATUS_DOWN and ifOperStatus is set to + /// IfOperStatusDown then a fault condition is presumed to exist on the interface. If AdminStatus is set to IfOperStatusDown, + /// then ifOperStatus will normally also be set to IfOperStatusDown or IfOperStatusNotPresent and there is not necessarily a + /// fault condition on the interface. + /// + /// + /// + /// IfOperStatusTesting 3 + /// The interface is in testing mode. + /// + /// + /// IfOperStatusUnknown 4 + /// The operational status of the interface is unknown. + /// + /// + /// IfOperStatusDormant 5 + /// + /// The interface is not actually in a condition to pass packets (it is not up), but is in a pending state, waiting for some + /// external event. For on-demand interfaces, this new state identifies the situation where the interface is waiting for events + /// to place it in the IfOperStatusUp state. + /// + /// + /// + /// IfOperStatusNotPresent 6 + /// + /// A refinement on the IfOperStatusDown state which indicates that the relevant interface is down specifically because some + /// component (typically, a hardware component) is not present in the managed system. + /// + /// + /// + /// IfOperStatusLowerLayerDown 7 + /// + /// A refinement on the IfOperStatusDown state. This new state indicates that this interface runs on top of one or more other + /// interfaces and that this interface is down specifically because one or more of these lower-layer interfaces are down. + /// + /// + /// + /// public IF_OPER_STATUS OperStatus; - private uint Ipv6IfIndex; + /// + /// Type: DWORD + /// The interface index for the IPv6 IP address. This member is zero if IPv6 is not available on the interface. + /// Note This structure member is only available on Windows XP with SP1 and later. + /// + private readonly uint Ipv6IfIndex; + + /// + /// Type: DWORD[16] + /// + /// An array of scope IDs for each scope level used for composing sockaddr structures. The SCOPE_LEVEL enumeration is used to + /// index the array. On IPv6, a single interface may be assigned multiple IPv6 multicast addresses based on a scope ID. + /// + /// Note This structure member is only available on Windows XP with SP1 and later. + /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public SCOPE_LEVEL[] ZoneIndices; + + /// + /// Type: PIP_ADAPTER_PREFIX + /// A pointer to the first IP_ADAPTER_PREFIX structure in a linked list of IP adapter prefixes for the adapter. + /// Note This structure member is only available on Windows XP with SP1 and later. + /// public IntPtr FirstPrefix; + /// + /// Type: ULONG64 + /// The current speed in bits per second of the transmit link for the adapter. + /// Note This structure member is only available on Windows Vista and later. + /// public ulong TrasmitLinkSpeed; + /// + /// Type: ULONG64 + /// The current speed in bits per second of the receive link for the adapter. + /// Note This structure member is only available on Windows Vista and later. + /// public ulong ReceiveLinkSpeed; + /// + /// Type: PIP_ADAPTER_WINS_SERVER_ADDRESS_LH + /// + /// A pointer to the first IP_ADAPTER_WINS_SERVER_ADDRESS structure in a linked list of Windows Internet Name Service (WINS) + /// server addresses for the adapter. + /// + /// Note This structure member is only available on Windows Vista and later. + /// public IntPtr FirstWinsServerAddress; + /// + /// Type: PIP_ADAPTER_GATEWAY_ADDRESS_LH + /// A pointer to the first IP_ADAPTER_GATEWAY_ADDRESS structure in a linked list of gateways for the adapter. + /// Note This structure member is only available on Windows Vista and later. + /// public IntPtr FirstGatewayAddress; + /// + /// Type: ULONG + /// The IPv4 interface metric for the adapter address. This member is only applicable to an IPv4 adapter address. + /// + /// The actual route metric used to compute the route preferences for IPv4 is the summation of the route metric offset specified + /// in the Metric member of the MIB_IPFORWARD_ROW2 structure and the interface metric specified in this member for IPv4. + /// + /// Note This structure member is only available on Windows Vista and later. + /// public uint Ipv4Metric; + /// + /// Type: ULONG + /// The IPv6 interface metric for the adapter address. This member is only applicable to an IPv6 adapter address. + /// + /// The actual route metric used to compute the route preferences for IPv6 is the summation of the route metric offset specified + /// in the Metric member of the MIB_IPFORWARD_ROW2 structure and the interface metric specified in this member for IPv4. + /// + /// Note This structure member is only available on Windows Vista and later. + /// public uint Ipv6Metric; + /// + /// Type: IF_LUID + /// The interface LUID for the adapter address. + /// Note This structure member is only available on Windows Vista and later. + /// public NET_LUID Luid; + /// + /// Type: SOCKET_ADDRESS + /// + /// The IPv4 address of the DHCP server for the adapter address. This member is only applicable to an IPv4 adapter address + /// configured using DHCP. + /// + /// Note This structure member is only available on Windows Vista and later. + /// public SOCKET_ADDRESS Dhcpv4Server; + /// + /// Type: NET_IF_COMPARTMENT_ID + /// The routing compartment ID for the adapter address. + /// + /// Note This structure member is only available on Windows Vista and later. This member is not currently supported and is + /// reserved for future use. + /// + /// public uint CompartmentId; + /// + /// Type: NET_IF_NETWORK_GUID + /// The GUID that is associated with the network that the interface belongs to. + /// + /// If the interface provider cannot provide the network GUID, this member can be a zero GUID. In this case, the interface + /// was registered by NDIS in the default network. + /// + /// Note This structure member is only available on Windows Vista and later. + /// public Guid NetworkGuid; + /// + /// Type: NET_IF_CONNECTION_TYPE + /// The interface connection type for the adapter address. + /// + /// This member can be one of the values from the NET_IF_CONNECTION_TYPE enumeration type defined in the Ifdef.h header file. + /// + /// + /// + /// Value + /// Meaning + /// + /// + /// NET_IF_CONNECTION_DEDICATED 1 + /// + /// The connection type is dedicated. The connection comes up automatically when media sense is TRUE. For example, an Ethernet + /// connection is dedicated. + /// + /// + /// + /// NET_IF_CONNECTION_PASSIVE 2 + /// + /// The connection type is passive. The remote end must bring up the connection to the local station. For example, a RAS + /// interface is passive. + /// + /// + /// + /// NET_IF_CONNECTION_DEMAND 3 + /// + /// The connection type is demand-dial. A connection of this type comes up in response to a local action (sending a packet, for example). + /// + /// + /// + /// NET_IF_CONNECTION_MAXIMUM 4 + /// + /// The maximum possible value for the NET_IF_CONNECTION_TYPE enumeration type. This is not a legal value for ConnectionType member. + /// + /// + /// + /// Note This structure member is only available on Windows Vista and later. + /// public NET_IF_CONNECTION_TYPE ConnectionType; + /// + /// Type: TUNNEL_TYPE + /// The encapsulation method used by a tunnel if the adapter address is a tunnel. + /// Note This structure member is only available on Windows Vista and later. + /// The tunnel type is defined by the Internet Assigned Names Authority (IANA). For more information, see + /// http://www.iana.org/assignments/ianaiftype-mib + /// . This member can be one of the values from the + /// TUNNEL_TYPE + /// enumeration type defined in the + /// Ifdef.h + /// header file. + /// + /// + /// Value + /// Meaning + /// + /// + /// TUNNEL_TYPE_NONE 0 + /// Not a tunnel. + /// + /// + /// TUNNEL_TYPE_OTHER 1 + /// None of the following tunnel types. + /// + /// + /// TUNNEL_TYPE_DIRECT 2 + /// + /// A packet is encapsulated directly within a normal IP header, with no intermediate header, and unicast to the remote tunnel endpoint. + /// + /// + /// + /// TUNNEL_TYPE_6TO4 11 + /// + /// An IPv6 packet is encapsulated directly within an IPv4 header, with no intermediate header, and unicast to the destination + /// determined by the 6to4 protocol. + /// + /// + /// + /// TUNNEL_TYPE_ISATAP 13 + /// + /// An IPv6 packet is encapsulated directly within an IPv4 header, with no intermediate header, and unicast to the destination + /// determined by the ISATAP protocol. + /// + /// + /// + /// TUNNEL_TYPE_TEREDO 14 + /// Teredo encapsulation for IPv6 packets. + /// + /// + /// TUNNEL_TYPE_IPHTTPS 15 + /// IP over HTTPS encapsulation for IPv6 packets. + /// + /// + /// public TUNNEL_TYPE TunnelType; + /// + /// Type: SOCKET_ADDRESS + /// + /// The IPv6 address of the DHCPv6 server for the adapter address. This member is only applicable to an IPv6 adapter address + /// configured using DHCPv6. This structure member is not currently supported and is reserved for future use. + /// + /// Note This structure member is only available on Windows Vista and later. + /// public SOCKET_ADDRESS Dhcpv6Server; + + /// + /// Type: BYTE[MAX_DHCPV6_DUID_LENGTH] + /// + /// The DHCP unique identifier (DUID) for the DHCPv6 client. This member is only applicable to an IPv6 adapter address configured + /// using DHCPv6. + /// + /// Note This structure member is only available on Windows Vista and later. + /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_DHCPV6_DUID_LENGTH)] public byte[] Dhcpv6ClientDuid; + + /// + /// Type: ULONG + /// + /// The length, in bytes, of the DHCP unique identifier (DUID) for the DHCPv6 client. This member is only applicable to an IPv6 + /// adapter address configured using DHCPv6. + /// + /// Note This structure member is only available on Windows Vista and later. + /// public uint Dhcpv6ClientDuidLength; + /// + /// Type: ULONG + /// + /// The identifier for an identity association chosen by the DHCPv6 client. This member is only applicable to an IPv6 adapter + /// address configured using DHCPv6. + /// + /// Note This structure member is only available on Windows Vista and later. + /// public uint Dhcpv6Iaid; + /// + /// Type: PIP_ADAPTER_DNS_SUFFIX + /// A pointer to the first IP_ADAPTER_DNS_SUFFIX structure in a linked list of DNS suffixes for the adapter. + /// + /// Note This structure member is only available on Windows Vista with SP1and later and on Windows Server 2008 and later. + /// + /// public IntPtr FirstDnsSuffix; public IEnumerable UnicastAddresses => FirstUnicastAddress.LinkedListToIEnum(t => t.Next); @@ -1633,12 +5822,18 @@ namespace Vanara.PInvoke public IEnumerable GatewayAddresses => FirstGatewayAddress.LinkedListToIEnum(t => t.Next); public IEnumerable DnsSuffixes => FirstDnsSuffix.LinkedListToIEnum(t => t.Next); - public IP_ADAPTER_ADDRESSES? GetNext() => Next.ToNullableStructure(); + public IP_ADAPTER_ADDRESSES? GetNext() + { + return Next.ToNullableStructure(); + } - public static IEnumerable ListFromPtr(IntPtr ptr) => ptr.LinkedListToIEnum(t => t.Next); + public static IEnumerable ListFromPtr(IntPtr ptr) + { + return ptr.LinkedListToIEnum(t => t.Next); + } } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct IP_ADAPTER_ANYCAST_ADDRESS { @@ -1648,7 +5843,7 @@ namespace Vanara.PInvoke public SOCKET_ADDRESS Address; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct IP_ADAPTER_DNS_SERVER_ADDRESS { @@ -1658,16 +5853,17 @@ namespace Vanara.PInvoke public SOCKET_ADDRESS Address; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct IP_ADAPTER_DNS_SUFFIX { public IntPtr Next; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_DNS_SUFFIX_STRING_LENGTH)] public string String; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct IP_ADAPTER_GATEWAY_ADDRESS { @@ -1677,45 +5873,55 @@ namespace Vanara.PInvoke public SOCKET_ADDRESS Address; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct IP_ADAPTER_INDEX_MAP { public uint Index; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_ADAPTER_NAME)] public string Name; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct IP_ADAPTER_INFO { public IntPtr Next; public uint ComboIndex; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_ADAPTER_NAME_LENGTH + 4)] public string AdapterName; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_ADAPTER_DESCRIPTION_LENGTH + 4)] public string AdapterDescription; + public uint AddressLength; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_ADAPTER_ADDRESS_LENGTH)] public byte[] Address; + public uint Index; public IFTYPE Type; + [MarshalAs(UnmanagedType.Bool)] public bool DhcpEnabled; + public IntPtr CurrentIpAddress; public IP_ADDR_STRING IpAddressList; public IP_ADDR_STRING GatewayList; public IP_ADDR_STRING DhcpServer; + [MarshalAs(UnmanagedType.Bool)] public bool HaveWins; + public IP_ADDR_STRING PrimaryWinsServer; public IP_ADDR_STRING SecondaryWinsServer; public uint LeaseObtained; public uint LeaseExpires; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct IP_ADAPTER_MULTICAST_ADDRESS { @@ -1725,7 +5931,7 @@ namespace Vanara.PInvoke public SOCKET_ADDRESS Address; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct IP_ADAPTER_PREFIX { @@ -1736,7 +5942,7 @@ namespace Vanara.PInvoke public uint PrefixLength; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct IP_ADAPTER_UNICAST_ADDRESS { @@ -1753,7 +5959,7 @@ namespace Vanara.PInvoke public byte OnLinkPrefixLength; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct IP_ADAPTER_WINS_SERVER_ADDRESS { @@ -1763,15 +5969,18 @@ namespace Vanara.PInvoke public SOCKET_ADDRESS Address; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct IP_ADDR_STRING { public IntPtr Next; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] public string IpAddress; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] public string IpMask; + public uint Context; } @@ -1782,14 +5991,16 @@ namespace Vanara.PInvoke public byte PrefixLength; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct IP_PER_ADAPTER_INFO { [MarshalAs(UnmanagedType.Bool)] public bool AutoconfigEnabled; + [MarshalAs(UnmanagedType.Bool)] public bool AutoconfigActive; + public IntPtr CurrentDnsServer; /* IpAddressList* */ public IP_ADDR_STRING DnsServerList; @@ -1798,9 +6009,14 @@ namespace Vanara.PInvoke get { if (!string.IsNullOrEmpty(DnsServerList.IpAddress)) + { yield return DnsServerList; - foreach (var i in DnsServerList.Next.LinkedListToIEnum(s => s.Next)) + } + + foreach (IP_ADDR_STRING i in DnsServerList.Next.LinkedListToIEnum(s => s.Next)) + { yield return i; + } } } } @@ -1811,88 +6027,181 @@ namespace Vanara.PInvoke { /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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. + + /// + /// 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; @@ -1911,19 +6220,22 @@ namespace Vanara.PInvoke } } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct MIB_IFROW { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_INTERFACE_NAME_LEN)] public string wszName; + public uint dwIndex; // index of the interface public uint dwType; // type of interface public uint dwMtu; // max transmission unit public uint dwSpeed; // speed of the interface public uint dwPhysAddrLen; // length of physical address + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAXLEN_PHYSADDR)] public byte[] bPhysAddr; // physical address of adapter + public uint dwAdminStatus; // administrative status public uint dwOperStatus; // operational status public uint dwLastChange; // last time operational status changed @@ -1940,11 +6252,12 @@ namespace Vanara.PInvoke public uint dwOutErrors; // erroneous packets sent public uint dwOutQLen; // output queue length public uint dwDescrLen; // length of bDescr member + [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAXLEN_IFDESCR)] public byte[] bDescr; // interface description } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential, Pack = 2)] public struct MIB_IPADDRROW { @@ -1957,7 +6270,7 @@ namespace Vanara.PInvoke public MIB_IPADDRTYPE wType; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct MIB_IPFORWARD_ROW2 { @@ -1978,7 +6291,7 @@ namespace Vanara.PInvoke public NL_ROUTE_ORIGIN Origin; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_IPFORWARDROW { @@ -1998,23 +6311,20 @@ namespace Vanara.PInvoke public uint dwForwardMetric5; } - [Flags] - public enum MIB_IPNET_ROW2_FLAGS : uint - { - IsRouther = 1, - IsUnreachable = 2 - } - - /// The MIB_IPNETROW structure contains information for an Address Resolution Protocol (ARP) table entry for an IPv4 address. - [PInvokeData("Iphlpapi.h")] + /// + /// The MIB_IPNETROW structure contains information for an Address Resolution Protocol (ARP) table entry for an IPv4 address. + /// + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential, Pack = 2)] public struct MIB_IPNET_ROW2 { public SOCKADDR_INET Address; public uint InterfaceIndex; public NET_LUID InterfaceLuid; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = IF_MAX_PHYS_ADDRESS_LENGTH)] public byte[] PhysicalAddress; + public uint PhysicalAddressLength; public NL_NEIGHBOR_STATE State; public MIB_IPNET_ROW2_FLAGS Flags; @@ -2026,9 +6336,15 @@ namespace Vanara.PInvoke SetMac(macAddr); } - public MIB_IPNET_ROW2(SOCKADDR_IN ipV4, NET_LUID ifLuid, byte[] macAddr = null) : this(ipV4, macAddr) { InterfaceLuid = ifLuid; } + public MIB_IPNET_ROW2(SOCKADDR_IN ipV4, NET_LUID ifLuid, byte[] macAddr = null) : this(ipV4, macAddr) + { + InterfaceLuid = ifLuid; + } - public MIB_IPNET_ROW2(SOCKADDR_IN ipV4, uint ifIdx, byte[] macAddr = null) : this(ipV4, macAddr) { InterfaceIndex = ifIdx; } + public MIB_IPNET_ROW2(SOCKADDR_IN ipV4, uint ifIdx, byte[] macAddr = null) : this(ipV4, macAddr) + { + InterfaceIndex = ifIdx; + } private MIB_IPNET_ROW2(SOCKADDR_IN6 ipV6, byte[] macAddr) : this() { @@ -2036,40 +6352,59 @@ namespace Vanara.PInvoke SetMac(macAddr); } - public MIB_IPNET_ROW2(SOCKADDR_IN6 ipV6, NET_LUID ifLuid, byte[] macAddr = null) : this(ipV6, macAddr) { InterfaceLuid = ifLuid; } + public MIB_IPNET_ROW2(SOCKADDR_IN6 ipV6, NET_LUID ifLuid, byte[] macAddr = null) : this(ipV6, macAddr) + { + InterfaceLuid = ifLuid; + } - public MIB_IPNET_ROW2(SOCKADDR_IN6 ipV6, uint ifIdx, byte[] macAddr = null) : this(ipV6, macAddr) { InterfaceIndex = ifIdx; } + public MIB_IPNET_ROW2(SOCKADDR_IN6 ipV6, uint ifIdx, byte[] macAddr = null) : this(ipV6, macAddr) + { + InterfaceIndex = ifIdx; + } private void SetMac(byte[] macAddr) { - if (macAddr == null) return; + 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())}"; + public override string ToString() + { + return $"{Address}; MAC:{PhysicalAddressToString(PhysicalAddress)}; If:{(InterfaceIndex != 0 ? InterfaceIndex.ToString() : InterfaceLuid.ToString())}"; + } } - /// The MIB_IPNETROW structure contains information for an Address Resolution Protocol (ARP) table entry for an IPv4 address. - [PInvokeData("Iphlpapi.h")] + /// + /// The MIB_IPNETROW structure contains information for an Address Resolution Protocol (ARP) table entry for an IPv4 address. + /// + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_IPNETROW { /// The index of the adapter. public uint dwIndex; + /// The length, in bytes, of the physical address. public uint dwPhysAddrLen; + /// The physical address. [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAXLEN_PHYSADDR)] public byte[] bPhysAddr; + /// The IPv4 address. public IN_ADDR dwAddr; + /// The type of ARP entry. This type can be one of the following values. public MIB_IPNET_TYPE dwType; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_TCP6ROW { @@ -2082,43 +6417,50 @@ namespace Vanara.PInvoke public uint dwRemotePort; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_TCP6ROW_OWNER_MODULE { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] ucLocalAddr; + public uint dwLocalScopeId; public uint dwLocalPort; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] ucRemoteAddr; + public uint dwRemoteScopeId; public uint dwRemotePort; public MIB_TCP_STATE dwState; public uint dwOwningPid; public SYSTEMTIME liCreateTimestamp; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = TCPIP_OWNING_MODULE_SIZE)] public ulong[] OwningModuleInfo; } // https://msdn.microsoft.com/en-us/library/aa366896 - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_TCP6ROW_OWNER_PID { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] ucLocalAddr; + public uint dwLocalScopeId; public uint dwLocalPort; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] ucRemoteAddr; + public uint dwRemoteScopeId; public uint dwRemotePort; public MIB_TCP_STATE dwState; public uint dwOwningPid; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_TCPROW { @@ -2129,7 +6471,7 @@ namespace Vanara.PInvoke public uint dwRemotePort; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_TCPROW_OWNER_MODULE { @@ -2140,12 +6482,13 @@ namespace Vanara.PInvoke public uint dwRemotePort; public uint dwOwningPid; public SYSTEMTIME liCreateTimestamp; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = TCPIP_OWNING_MODULE_SIZE)] public ulong[] OwningModuleInfo; } // https://msdn2.microsoft.com/en-us/library/aa366913.aspx - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_TCPROW_OWNER_PID { @@ -2157,7 +6500,7 @@ namespace Vanara.PInvoke public uint dwOwningPid; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_TCPROW2 { @@ -2170,7 +6513,7 @@ namespace Vanara.PInvoke public TCP_CONNECTION_OFFLOAD_STATE dwOffloadState; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_TCPSTATS { @@ -2191,7 +6534,7 @@ namespace Vanara.PInvoke public uint dwNumConns; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_TCPSTATS2 { @@ -2212,7 +6555,7 @@ namespace Vanara.PInvoke public uint dwNumConns; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_UDP6ROW { @@ -2221,33 +6564,36 @@ namespace Vanara.PInvoke public uint dwLocalPort; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_UDP6ROW_OWNER_MODULE { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] ucLocalAddr; + public uint dwLocalScopeId; public uint dwLocalPort; public uint dwOwningPid; public SYSTEMTIME liCreateTimestamp; public int SpecificPortBind; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = TCPIP_OWNING_MODULE_SIZE)] public ulong[] OwningModuleInfo; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_UDP6ROW_OWNER_PID { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] public byte[] ucLocalAddr; + public uint dwLocalScopeId; public uint dwLocalPort; public uint dwOwningPid; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_UDPROW { @@ -2255,7 +6601,7 @@ namespace Vanara.PInvoke public uint dwLocalPort; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_UDPROW_OWNER_MODULE { @@ -2264,11 +6610,12 @@ namespace Vanara.PInvoke public uint dwOwningPid; public SYSTEMTIME liCreateTimestamp; public int SpecificPortBind; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = TCPIP_OWNING_MODULE_SIZE)] public ulong[] OwningModuleInfo; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct MIB_UDPROW_OWNER_PID { @@ -2277,7 +6624,7 @@ namespace Vanara.PInvoke public uint dwOwningPid; } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [StructLayout(LayoutKind.Sequential)] public struct NET_LUID { @@ -2300,36 +6647,49 @@ namespace Vanara.PInvoke set => Value = ((ulong)value << 48) | Value; } - public override string ToString() => $"{NetLuidIndex}:{IfType}"; + public override string ToString() + { + return $"{NetLuidIndex}:{IfType}"; + } } [CorrespondingType(typeof(IP_ADAPTER_INDEX_MAP))] [DefaultProperty(nameof(Adapter))] public class IP_INTERFACE_INFO : SafeElementArray { - public IP_INTERFACE_INFO(uint byteSize) : base((int)byteSize, 0) { } + public IP_INTERFACE_INFO(uint byteSize) : base((int)byteSize, 0) + { + } public IP_ADAPTER_INDEX_MAP[] Adapter { get => Elements; set => Elements = value; } public int NumAdapters => Count; - public static implicit operator IntPtr(IP_INTERFACE_INFO iii) => iii.DangerousGetHandle(); + public static implicit operator IntPtr(IP_INTERFACE_INFO iii) + { + return iii.DangerousGetHandle(); + } } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(IN_ADDR))] [DefaultProperty(nameof(Address))] public class IP_UNIDIRECTIONAL_ADAPTER_ADDRESS : SafeElementArray { - public IP_UNIDIRECTIONAL_ADAPTER_ADDRESS(uint byteSize) : base((int)byteSize, 0) { } + public IP_UNIDIRECTIONAL_ADAPTER_ADDRESS(uint byteSize) : base((int)byteSize, 0) + { + } public IN_ADDR[] Address { get => Elements; set => Elements = value; } public uint NumAdapters => Count; - public static implicit operator IntPtr(IP_UNIDIRECTIONAL_ADAPTER_ADDRESS table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(IP_UNIDIRECTIONAL_ADAPTER_ADDRESS table) + { + return table.DangerousGetHandle(); + } } /// The MIB_IF_TABLE2 structure contains a table of logical and physical interface entries. - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_IF_ROW2))] [DefaultProperty(nameof(Elements))] public class MIB_IF_TABLE2 : GenericSafeHandle, IEnumerable @@ -2345,41 +6705,60 @@ namespace Vanara.PInvoke /// The number of interface entries in the array. public uint NumEntries => IsInvalid ? 0 : handle.ToStructure(); - public IEnumerator GetEnumerator() => ((IEnumerable)Elements).GetEnumerator(); + public IEnumerator GetEnumerator() + { + return ((IEnumerable)Elements).GetEnumerator(); + } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } - private static bool Free(IntPtr handle) { FreeMibTable(handle); return true; } + private static bool Free(IntPtr handle) + { + FreeMibTable(handle); return true; + } } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_IFROW))] [DefaultProperty(nameof(table))] public class MIB_IFTABLE : SafeElementArray { - public MIB_IFTABLE(uint byteSize) : base((int)byteSize, 0) { } + public MIB_IFTABLE(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_IFROW[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_IFTABLE table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_IFTABLE table) + { + return table.DangerousGetHandle(); + } } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_IPADDRROW))] [DefaultProperty(nameof(table))] public class MIB_IPADDRTABLE : SafeElementArray { - public MIB_IPADDRTABLE(uint byteSize) : base((int)byteSize, 0) { } + public MIB_IPADDRTABLE(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_IPADDRROW[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_IPADDRTABLE table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_IPADDRTABLE table) + { + return table.DangerousGetHandle(); + } } /// The MIB_IPNET_TABLE2 structure contains a table of neighbor IP address entries. - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_IPNET_ROW2))] [DefaultProperty(nameof(Elements))] public class MIB_IPNET_TABLE2 : GenericSafeHandle, IEnumerable @@ -2395,181 +6774,256 @@ namespace Vanara.PInvoke /// The number of interface entries in the array. public uint NumEntries => IsInvalid ? 0 : handle.ToStructure(); - public IEnumerator GetEnumerator() => ((IEnumerable)Elements).GetEnumerator(); + public IEnumerator GetEnumerator() + { + return ((IEnumerable)Elements).GetEnumerator(); + } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } - private static bool Free(IntPtr handle) { FreeMibTable(handle); return true; } + private static bool Free(IntPtr handle) + { + FreeMibTable(handle); return true; + } } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_IPNETROW))] [DefaultProperty(nameof(table))] public class MIB_IPNETTABLE : SafeElementArray { - public MIB_IPNETTABLE(uint byteSize) : base((int)byteSize, 0) { } + public MIB_IPNETTABLE(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_IPNETROW[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_IPNETTABLE table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_IPNETTABLE table) + { + return table.DangerousGetHandle(); + } } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_TCP6ROW_OWNER_MODULE))] [DefaultProperty(nameof(table))] public class MIB_TCP6TABLE_OWNER_MODULE : SafeElementArray { - public MIB_TCP6TABLE_OWNER_MODULE(uint byteSize) : base((int)byteSize, 0) { } + public MIB_TCP6TABLE_OWNER_MODULE(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_TCP6ROW_OWNER_MODULE[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_TCP6TABLE_OWNER_MODULE table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_TCP6TABLE_OWNER_MODULE table) + { + return table.DangerousGetHandle(); + } } // https://msdn.microsoft.com/en-us/library/windows/desktop/aa366905 - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_TCP6ROW_OWNER_PID))] [DefaultProperty(nameof(table))] public class MIB_TCP6TABLE_OWNER_PID : SafeElementArray { - public MIB_TCP6TABLE_OWNER_PID(uint byteSize) : base((int)byteSize, 0) { } + public MIB_TCP6TABLE_OWNER_PID(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_TCP6ROW_OWNER_PID[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_TCP6TABLE_OWNER_PID table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_TCP6TABLE_OWNER_PID table) + { + return table.DangerousGetHandle(); + } } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_TCPROW))] [DefaultProperty(nameof(table))] public class MIB_TCPTABLE : SafeElementArray { - public MIB_TCPTABLE(uint byteSize) : base((int)byteSize, 0) { } + public MIB_TCPTABLE(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_TCPROW[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_TCPTABLE table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_TCPTABLE table) + { + return table.DangerousGetHandle(); + } } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_TCPROW_OWNER_MODULE))] [DefaultProperty(nameof(table))] public class MIB_TCPTABLE_OWNER_MODULE : SafeElementArray { - public MIB_TCPTABLE_OWNER_MODULE(uint byteSize) : base((int)byteSize, 0) { } + public MIB_TCPTABLE_OWNER_MODULE(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_TCPROW_OWNER_MODULE[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_TCPTABLE_OWNER_MODULE table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_TCPTABLE_OWNER_MODULE table) + { + return table.DangerousGetHandle(); + } } // https://msdn2.microsoft.com/en-us/library/aa366921.aspx - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_TCPROW_OWNER_PID))] [DefaultProperty(nameof(table))] public class MIB_TCPTABLE_OWNER_PID : SafeElementArray { - public MIB_TCPTABLE_OWNER_PID(uint byteSize) : base((int)byteSize, 0) { } + public MIB_TCPTABLE_OWNER_PID(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_TCPROW_OWNER_PID[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_TCPTABLE_OWNER_PID table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_TCPTABLE_OWNER_PID table) + { + return table.DangerousGetHandle(); + } } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_UDP6ROW))] [DefaultProperty(nameof(table))] public class MIB_UDP6TABLE : SafeElementArray { - public MIB_UDP6TABLE(uint byteSize) : base((int)byteSize, 0) { } + public MIB_UDP6TABLE(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_UDP6ROW[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_UDP6TABLE table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_UDP6TABLE table) + { + return table.DangerousGetHandle(); + } } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_UDP6ROW_OWNER_MODULE))] [DefaultProperty(nameof(table))] public class MIB_UDP6TABLE_OWNER_MODULE : SafeElementArray { - public MIB_UDP6TABLE_OWNER_MODULE(uint byteSize) : base((int)byteSize, 0) { } + public MIB_UDP6TABLE_OWNER_MODULE(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_UDP6ROW_OWNER_MODULE[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_UDP6TABLE_OWNER_MODULE table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_UDP6TABLE_OWNER_MODULE table) + { + return table.DangerousGetHandle(); + } } // https://msdn.microsoft.com/en-us/library/windows/desktop/aa366905 - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_UDP6ROW_OWNER_PID))] [DefaultProperty(nameof(table))] public class MIB_UDP6TABLE_OWNER_PID : SafeElementArray { - public MIB_UDP6TABLE_OWNER_PID(uint byteSize) : base((int)byteSize, 0) { } + public MIB_UDP6TABLE_OWNER_PID(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_UDP6ROW_OWNER_PID[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_UDP6TABLE_OWNER_PID table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_UDP6TABLE_OWNER_PID table) + { + return table.DangerousGetHandle(); + } } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_UDPROW))] [DefaultProperty(nameof(table))] public class MIB_UDPTABLE : SafeElementArray { - public MIB_UDPTABLE(uint byteSize) : base((int)byteSize, 0) { } + public MIB_UDPTABLE(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_UDPROW[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_UDPTABLE table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_UDPTABLE table) + { + return table.DangerousGetHandle(); + } } - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_UDPROW_OWNER_MODULE))] [DefaultProperty(nameof(table))] public class MIB_UDPTABLE_OWNER_MODULE : SafeElementArray { - public MIB_UDPTABLE_OWNER_MODULE(uint byteSize) : base((int)byteSize, 0) { } + public MIB_UDPTABLE_OWNER_MODULE(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_UDPROW_OWNER_MODULE[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_UDPTABLE_OWNER_MODULE table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_UDPTABLE_OWNER_MODULE table) + { + return table.DangerousGetHandle(); + } } // https://msdn2.microsoft.com/en-us/library/aa366921.aspx - [PInvokeData("Iphlpapi.h")] + [PInvokeData("IpHlpApi.h")] [CorrespondingType(typeof(MIB_UDPROW_OWNER_PID))] [DefaultProperty(nameof(table))] public class MIB_UDPTABLE_OWNER_PID : SafeElementArray { - public MIB_UDPTABLE_OWNER_PID(uint byteSize) : base((int)byteSize, 0) { } + public MIB_UDPTABLE_OWNER_PID(uint byteSize) : base((int)byteSize, 0) + { + } public uint dwNumEntries => Count; public MIB_UDPROW_OWNER_PID[] table { get => Elements; set => Elements = value; } - public static implicit operator IntPtr(MIB_UDPTABLE_OWNER_PID table) => table.DangerousGetHandle(); + public static implicit operator IntPtr(MIB_UDPTABLE_OWNER_PID table) + { + return table.DangerousGetHandle(); + } } public class PIP_PER_ADAPTER_INFO : SafeMemoryHandle { - public PIP_PER_ADAPTER_INFO(uint byteSize) : base((int)byteSize) { } + public PIP_PER_ADAPTER_INFO(uint byteSize) : base((int)byteSize) + { + } public bool AutoconfigActive => !IsInvalid && handle.ToStructure().AutoconfigActive; public bool AutoconfigEnabled => !IsInvalid && handle.ToStructure().AutoconfigEnabled; public IEnumerable DnsServerList => IsInvalid ? new IP_ADDR_STRING[0] : handle.ToStructure().DnsServers; - public static implicit operator IntPtr(PIP_PER_ADAPTER_INFO info) => info.DangerousGetHandle(); + + public static implicit operator IntPtr(PIP_PER_ADAPTER_INFO info) + { + return info.DangerousGetHandle(); + } } } } \ No newline at end of file