using System; using System.Collections.Generic; using System.Runtime.InteropServices; using Vanara.Extensions; using Vanara.InteropServices; using static Vanara.PInvoke.Ws2_32; namespace Vanara.PInvoke { public static partial class IpHlpApi { /// Flags for an IP address. [PInvokeData("IpTypes.h")] [Flags] public enum IP_ADAPTER_CAST_FLAGS { /// The IP address is legal to appear in DNS. IP_ADAPTER_ADDRESS_DNS_ELIGIBLE = 0x01, /// The IP address is a cluster address and should not be used by most applications. IP_ADAPTER_ADDRESS_TRANSIENT = 0x02 } /// Flags for . [PInvokeData("IPTypes.h")] [Flags] public enum IP_ADAPTER_FLAGS : uint { /// Dynamic DNS is enabled on this adapter. IP_ADAPTER_DDNS_ENABLED = 0x00000001, /// Register the DNS suffix for this adapter. IP_ADAPTER_REGISTER_ADAPTER_SUFFIX = 0x00000002, /// Dynamic Host Configuration Protocol is enabled on this adapter. IP_ADAPTER_DHCP_ENABLED = 0x00000004, /// The adapter is a receive-only adapter. IP_ADAPTER_RECEIVE_ONLY = 0x00000008, /// The adapter is not a multicast recipient. IP_ADAPTER_NO_MULTICAST = 0x00000010, /// The adapter contains other IPv6-specific stateful configuration information. IP_ADAPTER_IPV6_OTHER_STATEFUL_CONFIG = 0x00000020, /// /// The adapter is enabled for NetBIOS over TCP/IP. This flag is only supported on Windows Vista and later when /// the application has been compiled for a target platform with an NTDDI version equal or greater than NTDDI_LONGHORN. This flag /// is defined in the IP_ADAPTER_ADDRESSES_LH structure as the NetbiosOverTcpipEnabled bitfield. /// IP_ADAPTER_NETBIOS_OVER_TCPIP_ENABLED = 0x00000040, /// /// The adapter is enabled for IPv4. This flag is only supported on Windows Vista and later when the /// application has been compiled for a target platform with an NTDDI version equal or greater than NTDDI_LONGHORN. This flag is /// defined in the IP_ADAPTER_ADDRESSES_LH structure as the Ipv4Enabled bitfield. /// IP_ADAPTER_IPV4_ENABLED = 0x00000080, /// /// The adapter is enabled for IPv6. This flag is only supported on Windows Vista and later when the /// application has been compiled for a target platform with an NTDDI version equal or greater than NTDDI_LONGHORN. This flag is /// defined in the IP_ADAPTER_ADDRESSES_LH structure as the Ipv6Enabled bitfield. /// IP_ADAPTER_IPV6_ENABLED = 0x00000100, /// /// The adapter is enabled for IPv6 managed address configuration. This flag is only supported on Windows Vista /// and later when the application has been compiled for a target platform with an NTDDI version equal or greater than /// NTDDI_LONGHORN. This flag is defined in the IP_ADAPTER_ADDRESSES_LH structure as the Ipv6ManagedAddressConfigurationSupported bitfield. /// IP_ADAPTER_IPV6_MANAGE_ADDRESS_CONFIG = 0x00000200, } /// Identifies a class or structure that supports a linked-list model. /// The type of the element in the list. public interface ILinkedListElement where T : struct { /// Gets the next element in the list. /// A nullable type. A value indicates the end of the list. T? GetNext(); } private static IEnumerable GetLinkedList(this T start, Func includeFirst) where T : struct, ILinkedListElement { if (includeFirst(start)) yield return start; for (var cur = ((ILinkedListElement)start).GetNext(); cur != null; cur = ((ILinkedListElement)cur).GetNext()) yield return cur.Value; } /// /// 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; /// /// A list of IP_ADDR_STRING structures that specify the set of DNS servers used by the local computer. /// public IEnumerable DnsServers { get { if (DnsServerList.IpAddress.String != null) yield return DnsServerList; var next = DnsServerList.GetNext(); while (next != null) { yield return next.Value; next = next.Value.GetNext(); } } } } /// /// /// 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 : ILinkedListElement { /// public uint Length; /// public uint IfIndex; /// /// Type: struct _IP_ADAPTER_ADDRESSES* /// A pointer to the next adapter addresses structure in the list. /// public IntPtr Next; /// /// Type: PCHAR /// /// An array of characters that contains the name of the adapter with which these addresses are associated. Unlike an adapter's /// friendly name, the adapter name specified in AdapterName is permanent and cannot be modified by the user. /// /// [MarshalAs(UnmanagedType.LPStr)] public string AdapterName; /// /// Type: PIP_ADAPTER_UNICAST_ADDRESS /// A pointer to the first IP_ADAPTER_UNICAST_ADDRESS structure in a linked list of IP unicast addresses for the adapter. /// public IntPtr FirstUnicastAddress; /// /// Type: PIP_ADAPTER_ANYCAST_ADDRESS /// A pointer to the first IP_ADAPTER_ANYCAST_ADDRESS structure in a linked list of IP anycast addresses for the adapter. /// public IntPtr FirstAnycastAddress; /// /// Type: PIP_ADAPTER_MULTICAST_ADDRESS /// A pointer to the first IP_ADAPTER_MULTICAST_ADDRESS structure in a list of IP multicast addresses for the adapter. /// public IntPtr FirstMulticastAddress; /// /// Type: PIP_ADAPTER_DNS_SERVER_ADDRESS /// A pointer to the first IP_ADAPTER_DNS_SERVER_ADDRESS structure in a linked list of DNS server addresses for the adapter. /// public IntPtr FirstDnsServerAddress; /// /// Type: PWCHAR /// The Domain Name System (DNS) suffix associated with this adapter. /// [MarshalAs(UnmanagedType.LPWStr)] public string DnsSuffix; /// /// Type: PWCHAR /// A description for the adapter. This member is read-only. /// [MarshalAs(UnmanagedType.LPWStr)] public string Description; /// /// Type: PWCHAR /// /// A user-friendly name for the adapter. For example: "Local Area Connection 1." This name appears in contexts such as the /// ipconfig command line program and the Connection folder. This member is read only and can't be modified using any IP /// Helper functions. /// /// /// This member is the ifAlias field used by NDIS as described in RFC 2863. The ifAlias field can be set by an NDIS interface /// provider when the NDIS driver is installed. For NDIS miniport drivers, this field is set by NDIS. /// /// [MarshalAs(UnmanagedType.LPWStr)] public string FriendlyName; /// /// Type: BYTE[MAX_ADAPTER_ADDRESS_LENGTH] /// /// The Media Access Control (MAC) address for the adapter. For example, on an Ethernet network this member would specify the /// Ethernet hardware address. /// /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_ADAPTER_ADDRESS_LENGTH)] public byte[] PhysicalAddress; /// /// Type: DWORD /// /// The length, in bytes, of the address specified in the PhysicalAddress member. For interfaces that do not have a /// data-link layer, this value is zero. /// /// public uint PhysicalAddressLength; /// public IP_ADAPTER_FLAGS Flags; /// /// Type: DWORD /// The maximum transmission unit (MTU) size, in bytes. /// public uint Mtu; /// /// Type: DWORD /// /// The interface type as defined by the Internet Assigned Names Authority (IANA). Possible values for the interface type are /// listed in the Ipifcons.h header file. /// /// The table below lists common values for the interface type although many other values are possible. /// /// /// Value /// Meaning /// /// /// IF_TYPE_OTHER 1 /// Some other type of network interface. /// /// /// IF_TYPE_ETHERNET_CSMACD 6 /// An Ethernet network interface. /// /// /// IF_TYPE_ISO88025_TOKENRING 9 /// A token ring network interface. /// /// /// IF_TYPE_PPP 23 /// A PPP network interface. /// /// /// IF_TYPE_SOFTWARE_LOOPBACK 24 /// A software loopback network interface. /// /// /// IF_TYPE_ATM 37 /// An ATM network interface. /// /// /// IF_TYPE_IEEE80211 71 /// /// An IEEE 802.11 wireless network interface. On Windows Vista and later, wireless network cards are reported as /// IF_TYPE_IEEE80211. On earlier versions of Windows, wireless network cards are reported as IF_TYPE_ETHERNET_CSMACD. On Windows /// XP with SP3 and on Windows XP with SP2 x86 with the Wireless LAN API for Windows XP with SP2 installed, the /// WlanEnumInterfaces function can be used to enumerate wireless interfaces on the local computer. /// /// /// /// IF_TYPE_TUNNEL 131 /// A tunnel type encapsulation network interface. /// /// /// IF_TYPE_IEEE1394 144 /// An IEEE 1394 (Firewire) high performance serial bus network interface. /// /// /// public IFTYPE IfType; /// /// Type: IF_OPER_STATUS /// /// The operational status for the interface as defined in RFC 2863. For more information, see /// http://www.ietf.org/rfc/rfc2863.txt. This member can be one of the values from the IF_OPER_STATUS enumeration type /// defined in the Iftypes.h header file. On Windows Vista and later, the header files were reorganized and this enumeration is /// defined in the Ifdef.h header file. /// /// /// /// Value /// Meaning /// /// /// IfOperStatusUp 1 /// The interface is up and able to pass packets. /// /// /// IfOperStatusDown 2 /// /// The interface is down and not in a condition to pass packets. The IfOperStatusDown state has two meanings, depending on the /// value of AdminStatus member. If AdminStatus is not set to NET_IF_ADMIN_STATUS_DOWN and ifOperStatus is set to /// IfOperStatusDown then a fault condition is presumed to exist on the interface. If AdminStatus is set to IfOperStatusDown, /// then ifOperStatus will normally also be set to IfOperStatusDown or IfOperStatusNotPresent and there is not necessarily a /// fault condition on the interface. /// /// /// /// IfOperStatusTesting 3 /// The interface is in testing mode. /// /// /// IfOperStatusUnknown 4 /// The operational status of the interface is unknown. /// /// /// IfOperStatusDormant 5 /// /// The interface is not actually in a condition to pass packets (it is not up), but is in a pending state, waiting for some /// external event. For on-demand interfaces, this new state identifies the situation where the interface is waiting for events /// to place it in the IfOperStatusUp state. /// /// /// /// IfOperStatusNotPresent 6 /// /// A refinement on the IfOperStatusDown state which indicates that the relevant interface is down specifically because some /// component (typically, a hardware component) is not present in the managed system. /// /// /// /// IfOperStatusLowerLayerDown 7 /// /// A refinement on the IfOperStatusDown state. This new state indicates that this interface runs on top of one or more other /// interfaces and that this interface is down specifically because one or more of these lower-layer interfaces are down. /// /// /// /// public IF_OPER_STATUS OperStatus; /// /// Type: DWORD /// The interface index for the IPv6 IP address. This member is zero if IPv6 is not available on the interface. /// Note This structure member is only available on Windows XP with SP1 and later. /// public 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; /// A sequence of IP_ADAPTER_UNICAST_ADDRESS structures for the adapter. public IEnumerable UnicastAddresses => FirstUnicastAddress.LinkedListToIEnum(t => t.Next); /// A sequence of IP_ADAPTER_ANYCAST_ADDRESS structures for the adapter. public IEnumerable AnycastAddresses => FirstAnycastAddress.LinkedListToIEnum(t => t.Next); /// A sequence of IP_ADAPTER_MULTICAST_ADDRESS structures for the adapter. public IEnumerable MulticastAddresses => FirstMulticastAddress.LinkedListToIEnum(t => t.Next); /// A sequence of IP_ADAPTER_DNS_SERVER_ADDRESS structures for the adapter. public IEnumerable DnsServerAddresses => FirstDnsServerAddress.LinkedListToIEnum(t => t.Next); /// A sequence of IP_ADAPTER_PREFIX structures for the adapter. public IEnumerable Prefixes => FirstPrefix.LinkedListToIEnum(t => t.Next); /// A sequence of IP_ADAPTER_WINS_SERVER_ADDRESS structures for the adapter. public IEnumerable WinsServerAddresses => FirstWinsServerAddress.LinkedListToIEnum(t => t.Next); /// A sequence of IP_ADAPTER_GATEWAY_ADDRESS structures for the adapter. public IEnumerable GatewayAddresses => FirstGatewayAddress.LinkedListToIEnum(t => t.Next); /// A sequence of IP_ADAPTER_DNS_SUFFIX structures for the adapter. public IEnumerable DnsSuffixes => FirstDnsSuffix.LinkedListToIEnum(t => t.Next); /// Gets the next element in the linked list. /// A nullable type. A value indicates the end of the list. public IP_ADAPTER_ADDRESSES? GetNext() => Next.ToNullableStructure(); } /// /// /// The IP_ADAPTER_ANYCAST_ADDRESS structure stores a single anycast IP address in a linked list of addresses for a particular adapter. /// /// /// /// /// The IP_ADAPTER_ADDRESSES structure is retrieved by the GetAdaptersAddresses function. The FirstAnycastAddress member of /// the IP_ADAPTER_ADDRESSES structure is a pointer to a linked list of IP_ADAPTER_ANYCAST_ADDRESS structures. /// /// /// The SOCKET_ADDRESS structure is used in the IP_ADAPTER_ANYCAST_ADDRESS structure. On the Microsoft Windows Software /// Development Kit (SDK) released for Windows Vista and later, the organization of header files has changed and the /// 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_ANYCAST_ADDRESS structure, the /// Winsock2.h header file must be included before the Iphlpapi.h header file. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_adapter_anycast_address_xp typedef struct // _IP_ADAPTER_ANYCAST_ADDRESS_XP { union { ULONGLONG Alignment; struct { ULONG Length; DWORD Flags; }; }; struct // _IP_ADAPTER_ANYCAST_ADDRESS_XP *Next; SOCKET_ADDRESS Address; } IP_ADAPTER_ANYCAST_ADDRESS_XP, *PIP_ADAPTER_ANYCAST_ADDRESS_XP; [PInvokeData("iptypes.h", MSDNShortId = "2626fc86-e29b-4162-8625-207c709d67ed")] [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct IP_ADAPTER_ANYCAST_ADDRESS : ILinkedListElement { private long Alignment; /// Specifies the length of this structure. public uint Length { get => Alignment.LowPart(); set => Alignment = Macros.MAKELONG64(value, Alignment.HighPart()); } /// Specifies flags for this address. public IP_ADAPTER_CAST_FLAGS Flags { get => (IP_ADAPTER_CAST_FLAGS)Alignment.HighPart(); set => Alignment = Macros.MAKELONG64(Alignment.LowPart(), (int)value); } /// /// Type: struct _IP_ADAPTER_ANYCAST_ADDRESS* /// A pointer to the next anycast IP address structure in the list. /// public IntPtr Next; /// /// Type: SOCKET_ADDRESS /// The IP address for this anycast IP address entry. This member can be an IPv6 address or an IPv4 address. /// public SOCKET_ADDRESS Address; /// /// Gets a reference to the next IP_ADAPTER_ANYCAST_ADDRESS structure in the list. /// public IP_ADAPTER_ANYCAST_ADDRESS? GetNext() => Next.ToNullableStructure(); /// public override string ToString() => Address.ToString(); } /// /// /// The IP_ADAPTER_DNS_SERVER_ADDRESS structure stores a single DNS server address in a linked list of DNS server addresses /// for a particular adapter. /// /// /// /// /// The IP_ADAPTER_ADDRESSES structure is retrieved by the GetAdaptersAddresses function. The FirstDnsServerAddress member of /// the IP_ADAPTER_ADDRESSES structure is a pointer to a linked list of IP_ADAPTER_DNS_SERVER_ADDRESS structures. /// /// /// The SOCKET_ADDRESS structure is used in the IP_ADAPTER_DNS_SERVER_ADDRESS structure. On the Microsoft Windows Software /// Development Kit (SDK) released for Windows Vista and later, the organization of header files has changed and the /// 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_DNS_SERVER_ADDRESS structure, the /// Winsock2.h header file must be included before the Iphlpapi.h header file. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_adapter_dns_server_address_xp typedef struct // _IP_ADAPTER_DNS_SERVER_ADDRESS_XP { union { ULONGLONG Alignment; struct { ULONG Length; DWORD Reserved; }; }; struct // _IP_ADAPTER_DNS_SERVER_ADDRESS_XP *Next; SOCKET_ADDRESS Address; } IP_ADAPTER_DNS_SERVER_ADDRESS_XP, *PIP_ADAPTER_DNS_SERVER_ADDRESS_XP; [PInvokeData("iptypes.h", MSDNShortId = "96855386-9010-40df-8260-16b43ad6646f")] [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct IP_ADAPTER_DNS_SERVER_ADDRESS : ILinkedListElement { private long Alignment; /// Specifies the length of this structure. public uint Length { get => Alignment.LowPart(); set => Alignment = Macros.MAKELONG64(value, Alignment.HighPart()); } /// Reserved public int Reserved { get => Alignment.HighPart(); set => Alignment = Macros.MAKELONG64(Alignment.LowPart(), value); } /// /// A pointer to the next DNS server address structure in the list. /// public IntPtr Next; /// /// The IP address for this DNS server entry. This member can be an IPv6 address or an IPv4 address. /// public SOCKET_ADDRESS Address; /// /// Gets a reference to the next IP_ADAPTER_DNS_SERVER_ADDRESS structure in the list. /// public IP_ADAPTER_DNS_SERVER_ADDRESS? GetNext() => Next.ToNullableStructure(); /// public override string ToString() => Address.ToString(); } /// /// The IP_ADAPTER_DNS_SUFFIX structure stores a DNS suffix in a linked list of DNS suffixes for a particular adapter. /// /// /// /// The IP_ADAPTER_ADDRESSES structure is retrieved by the GetAdaptersAddresses function. The FirstDnsSuffix member of the /// IP_ADAPTER_ADDRESSES structure is a pointer to a linked list of IP_ADAPTER_DNS_SUFFIX structures. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_adapter_dns_suffix typedef struct // _IP_ADAPTER_DNS_SUFFIX { struct _IP_ADAPTER_DNS_SUFFIX *Next; WCHAR String[MAX_DNS_SUFFIX_STRING_LENGTH]; } IP_ADAPTER_DNS_SUFFIX, *PIP_ADAPTER_DNS_SUFFIX; [PInvokeData("iptypes.h", MSDNShortId = "3730a406-2995-48f7-b70e-1cf8258ee4a6")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct IP_ADAPTER_DNS_SUFFIX : ILinkedListElement { /// /// A pointer to the next DNS suffix in the linked list. /// public IntPtr Next; /// /// The DNS suffix for this DNS suffix entry. /// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_DNS_SUFFIX_STRING_LENGTH)] public string String; /// /// Gets a reference to the next IP_ADAPTER_DNS_SUFFIX structure in the list. /// public IP_ADAPTER_DNS_SUFFIX? GetNext() => Next.ToNullableStructure(); /// public override string ToString() => String; } /// /// /// The IP_ADAPTER_GATEWAY_ADDRESS structure stores a single gateway address in a linked list of gateway addresses for a /// particular adapter. /// /// /// /// /// The IP_ADAPTER_ADDRESSES structure is retrieved by the GetAdaptersAddresses function. The FirstGatewayAddress member of /// the IP_ADAPTER_ADDRESSES structure is a pointer to a linked list of IP_ADAPTER_GATEWAY_ADDRESS structures. /// /// /// The SOCKET_ADDRESS structure is used in the IP_ADAPTER_GATEWAY_ADDRESS structure. On the Microsoft Windows Software /// Development Kit (SDK) released for Windows Vista and later, the organization of header files has changed and the /// 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_GATEWAY_ADDRESS structure, the /// Winsock2.h header file must be included before the Iphlpapi.h header file. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_adapter_gateway_address_lh typedef struct // _IP_ADAPTER_GATEWAY_ADDRESS_LH { union { ULONGLONG Alignment; struct { ULONG Length; DWORD Reserved; }; }; struct // _IP_ADAPTER_GATEWAY_ADDRESS_LH *Next; SOCKET_ADDRESS Address; } IP_ADAPTER_GATEWAY_ADDRESS_LH, *PIP_ADAPTER_GATEWAY_ADDRESS_LH; [PInvokeData("iptypes.h", MSDNShortId = "CA38504A-1CC9-4ABA-BD4E-1B2EAD6F588B")] [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct IP_ADAPTER_GATEWAY_ADDRESS : ILinkedListElement { private long Alignment; /// Specifies the length of this structure. public uint Length { get => Alignment.LowPart(); set => Alignment = Macros.MAKELONG64(value, Alignment.HighPart()); } /// Reserved public int Reserved { get => Alignment.HighPart(); set => Alignment = Macros.MAKELONG64(Alignment.LowPart(), value); } /// /// A pointer to the next gateway address structure in the list. /// public IntPtr Next; /// /// The IP address for this gateway entry. This member can be an IPv6 address or an IPv4 address. /// public SOCKET_ADDRESS Address; /// /// Gets a reference to the next IP_ADAPTER_GATEWAY_ADDRESS structure in the list. /// public IP_ADAPTER_GATEWAY_ADDRESS? GetNext() => Next.ToNullableStructure(); /// public override string ToString() => Address.ToString(); } /// /// The IP_ADAPTER_INFO structure contains information about a particular network adapter on the local computer. /// /// /// /// The IP_ADAPTER_INFO structure is limited to IPv4 information about a particular network adapter on the local computer. The /// IP_ADAPTER_INFO structure is retrieved by calling the GetAdaptersInfofunction. /// /// /// When using Visual Studio 2005 and later, the time_t datatype defaults to an 8-byte datatype, not the 4-byte datatype used /// for the LeaseObtained and LeaseExpires members on a 32-bit platform. To properly use the IP_ADAPTER_INFO /// structure on a 32-bit platform, define _USE_32BIT_TIME_T (use as an option, for example) when compiling the application to /// force the time_t datatype to a 4-byte datatype. /// /// /// For use on Windows XP and later, the IP_ADAPTER_ADDRESSES structure contains both IPv4 and IPv6 information. The /// GetAdaptersAddresses function retrieves IPv4 and IPv6 adapter information. /// /// Examples /// This example retrieves the adapter information and prints various properties of each adapter. /// // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_adapter_info typedef struct _IP_ADAPTER_INFO { struct // _IP_ADAPTER_INFO *Next; DWORD ComboIndex; char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4]; char // Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4]; UINT AddressLength; BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH]; DWORD Index; UINT // Type; UINT DhcpEnabled; PIP_ADDR_STRING CurrentIpAddress; IP_ADDR_STRING IpAddressList; IP_ADDR_STRING GatewayList; IP_ADDR_STRING // DhcpServer; BOOL HaveWins; IP_ADDR_STRING PrimaryWinsServer; IP_ADDR_STRING SecondaryWinsServer; time_t LeaseObtained; time_t // LeaseExpires; } IP_ADAPTER_INFO, *PIP_ADAPTER_INFO; [PInvokeData("iptypes.h", MSDNShortId = "f8035801-ca0c-4d86-bfc5-8e2d746af1b4")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct IP_ADAPTER_INFO : ILinkedListElement { /// /// Type: struct _IP_ADAPTER_INFO* /// A pointer to the next adapter in the list of adapters. /// public IntPtr Next; /// /// Type: DWORD /// Reserved. /// public uint ComboIndex; /// /// Type: char[MAX_ADAPTER_NAME_LENGTH + 4] /// An ANSI character string of the name of the adapter. /// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_ADAPTER_NAME_LENGTH + 4)] public string AdapterName; /// /// Type: char[MAX_ADAPTER_DESCRIPTION_LENGTH + 4] /// An ANSI character string that contains the description of the adapter. /// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_ADAPTER_DESCRIPTION_LENGTH + 4)] public string AdapterDescription; /// /// Type: UINT /// The length, in bytes, of the hardware address for the adapter. /// public uint AddressLength; /// /// Type: BYTE[MAX_ADAPTER_ADDRESS_LENGTH] /// The hardware address for the adapter represented as a BYTE array. /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_ADAPTER_ADDRESS_LENGTH)] public byte[] Address; /// /// Type: DWORD /// The adapter index. /// /// The adapter index may change when an adapter is disabled and then enabled, or under other circumstances, and should not be /// considered persistent. /// /// public uint Index; /// /// Type: UINT /// The adapter type. Possible values for the adapter type are listed in the Ipifcons.h header file. /// The table below lists common values for the adapter type although other values are possible on Windows Vista and later. /// /// /// Value /// Meaning /// /// /// MIB_IF_TYPE_OTHER 1 /// Some other type of network interface. /// /// /// MIB_IF_TYPE_ETHERNET 6 /// An Ethernet network interface. /// /// /// IF_TYPE_ISO88025_TOKENRING 9 /// MIB_IF_TYPE_TOKENRING /// /// /// MIB_IF_TYPE_PPP 23 /// A PPP network interface. /// /// /// MIB_IF_TYPE_LOOPBACK 24 /// A software loopback network interface. /// /// /// MIB_IF_TYPE_SLIP 28 /// An ATM network interface. /// /// /// IF_TYPE_IEEE80211 71 /// An IEEE 802.11 wireless network interface. /// /// /// public IFTYPE Type; /// /// Type: UINT /// An option value that specifies whether the dynamic host configuration protocol (DHCP) is enabled for this adapter. /// [MarshalAs(UnmanagedType.Bool)] public bool DhcpEnabled; /// /// Type: PIP_ADDR_STRING /// Reserved. /// public IntPtr CurrentIpAddress; /// /// Type: IP_ADDR_STRING /// /// The list of IPv4 addresses associated with this adapter represented as a linked list of IP_ADDR_STRING structures. An /// adapter can have multiple IPv4 addresses assigned to it. /// /// public IP_ADDR_STRING IpAddressList; /// /// Type: IP_ADDR_STRING /// /// The IPv4 address of the gateway for this adapter represented as a linked list of IP_ADDR_STRING structures. An adapter /// can have multiple IPv4 gateway addresses assigned to it. This list usually contains a single entry for IPv4 address of the /// default gateway for this adapter. /// /// public IP_ADDR_STRING GatewayList; /// /// Type: IP_ADDR_STRING /// /// The IPv4 address of the DHCP server for this adapter represented as a linked list of IP_ADDR_STRING structures. This /// list contains a single entry for the IPv4 address of the DHCP server for this adapter. A value of 255.255.255.255 indicates /// the DHCP server could not be reached, or is in the process of being reached. /// /// This member is only valid when the DhcpEnabled member is nonzero. /// public IP_ADDR_STRING DhcpServer; /// /// Type: BOOL /// An option value that specifies whether this adapter uses the Windows Internet Name Service (WINS). /// [MarshalAs(UnmanagedType.Bool)] public bool HaveWins; /// /// Type: IP_ADDR_STRING /// /// The IPv4 address of the primary WINS server represented as a linked list of IP_ADDR_STRING structures. This list /// contains a single entry for the IPv4 address of the primary WINS server for this adapter. /// /// This member is only valid when the HaveWins member is TRUE. /// public IP_ADDR_STRING PrimaryWinsServer; /// /// Type: IP_ADDR_STRING /// /// The IPv4 address of the secondary WINS server represented as a linked list of IP_ADDR_STRING structures. An adapter /// can have multiple secondary WINS server addresses assigned to it. /// /// This member is only valid when the HaveWins member is TRUE. /// public IP_ADDR_STRING SecondaryWinsServer; /// /// Type: time_t /// The time when the current DHCP lease was obtained. /// This member is only valid when the DhcpEnabled member is nonzero. /// public time_t LeaseObtained; /// /// Type: time_t /// The time when the current DHCP lease expires. /// This member is only valid when the DhcpEnabled member is nonzero. /// public time_t LeaseExpires; /// Gets a sequence of IP_ADDR_STRING values representing IP addresses. public IEnumerable IpAddresses => IpAddressList.GetLinkedList(s => s.IpAddress.String != null); /// Gets a sequence of IP_ADDR_STRING values representing gateways. public IEnumerable Gateways => GatewayList.GetLinkedList(s => s.IpAddress.String != null); /// Gets a sequence of IP_ADDR_STRING values representing DHCP servers. public IEnumerable DhcpServers => DhcpServer.GetLinkedList(s => s.IpAddress.String != null); /// Gets a sequence of IP_ADDR_STRING values representing primary WINS servers. public IEnumerable PrimaryWinsServers => PrimaryWinsServer.GetLinkedList(s => s.IpAddress.String != null); /// Gets a sequence of IP_ADDR_STRING values representing secondary WINS servers. public IEnumerable SecondaryWinsServers => SecondaryWinsServer.GetLinkedList(s => s.IpAddress.String != null); /// /// Gets a reference to the next IP_ADAPTER_INFO structure in the list. /// public IP_ADAPTER_INFO? GetNext() => Next.ToNullableStructure(); } /// /// /// The IP_ADAPTER_MULTICAST_ADDRESS structure stores a single multicast address in a linked-list of addresses for a /// particular adapter. /// /// /// /// /// The IP_ADAPTER_ADDRESSES structure is retrieved by the GetAdaptersAddresses function. The FirstMulticastAddress member of /// the IP_ADAPTER_ADDRESSES structure is a pointer to a linked list of IP_ADAPTER_MULTICAST_ADDRESS structures. /// /// /// The SOCKET_ADDRESS structure is used in the IP_ADAPTER_MULTICAST_ADDRESS structure. On the Microsoft Windows Software /// Development Kit (SDK) released for Windows Vista and later, the organization of header files has changed and the /// 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_MULTICAST_ADDRESS structure, the /// Winsock2.h header file must be included before the Iphlpapi.h header file. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_adapter_multicast_address_xp typedef struct // _IP_ADAPTER_MULTICAST_ADDRESS_XP { union { ULONGLONG Alignment; struct { ULONG Length; DWORD Flags; }; }; struct // _IP_ADAPTER_MULTICAST_ADDRESS_XP *Next; SOCKET_ADDRESS Address; } IP_ADAPTER_MULTICAST_ADDRESS_XP, *PIP_ADAPTER_MULTICAST_ADDRESS_XP; [PInvokeData("iptypes.h", MSDNShortId = "b85a6e0a-df2c-4608-b07a-191b34440a43")] [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct IP_ADAPTER_MULTICAST_ADDRESS : ILinkedListElement { private long Alignment; /// Specifies the length of this structure. public uint Length { get => Alignment.LowPart(); set => Alignment = Macros.MAKELONG64(value, Alignment.HighPart()); } /// Specifies flags for this address. public IP_ADAPTER_CAST_FLAGS Flags { get => (IP_ADAPTER_CAST_FLAGS)Alignment.HighPart(); set => Alignment = Macros.MAKELONG64(Alignment.LowPart(), (int)value); } /// /// Type: struct _IP_ADAPTER_MULTICAST_ADDRESS* /// A pointer to the next multicast IP address structure in the list. /// public IntPtr Next; /// /// Type: SOCKET_ADDRESS /// The IP address for this multicast IP address entry. This member can be an IPv6 address or an IPv4 address. /// public SOCKET_ADDRESS Address; /// /// Gets a reference to the next IP_ADAPTER_MULTICAST_ADDRESS structure in the list. /// public IP_ADAPTER_MULTICAST_ADDRESS? GetNext() => Next.ToNullableStructure(); /// public override string ToString() => Address.ToString(); } /// /// The IP_ADAPTER_PREFIX structure stores an IP address prefix. /// /// /// /// The IP_ADAPTER_ADDRESSES structure is retrieved by the GetAdaptersAddresses function. On Windows XP with Service Pack 1 (SP1) and /// later, the FirstPrefix member of the IP_ADAPTER_ADDRESSES structure is a pointer to a linked list of /// IP_ADAPTER_PREFIX structures. /// /// /// The SOCKET_ADDRESS structure is used in the IP_ADAPTER_PREFIX structure. 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 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_PREFIX structure, the Winsock2.h header file must be included /// before the Iphlpapi.h header file. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_adapter_prefix_xp typedef struct _IP_ADAPTER_PREFIX_XP // { union { ULONGLONG Alignment; struct { ULONG Length; DWORD Flags; }; }; struct _IP_ADAPTER_PREFIX_XP *Next; SOCKET_ADDRESS // Address; ULONG PrefixLength; } IP_ADAPTER_PREFIX_XP, *PIP_ADAPTER_PREFIX_XP; [PInvokeData("iptypes.h", MSDNShortId = "680b412d-2352-421d-ae58-dcf34ee6cf31")] [StructLayout(LayoutKind.Sequential)] public struct IP_ADAPTER_PREFIX : ILinkedListElement { /// Specifies the length of this structure. public uint Length; /// This member is reserved and should be set to zero. public uint Flags; /// /// A pointer to the next adapter prefix structure in the list. /// public IntPtr Next; /// /// The address prefix, in the form of a SOCKET_ADDRESS structure. /// public SOCKET_ADDRESS Address; /// /// The length of the prefix, in bits. /// public uint PrefixLength; /// /// Gets a reference to the next IP_ADAPTER_PREFIX structure in the list. /// public IP_ADAPTER_PREFIX? GetNext() => Next.ToNullableStructure(); /// public override string ToString() => Address.ToString(); } /// /// /// The IP_ADAPTER_UNICAST_ADDRESS structure stores a single unicast IP address in a linked list of IP addresses for a /// particular adapter. /// /// /// /// /// The IP_ADAPTER_ADDRESSES structure is retrieved by the GetAdaptersAddresses function. The FirstUnicastAddress member of /// the IP_ADAPTER_ADDRESSES structure is a pointer to a linked list of IP_ADAPTER_UNICAST_ADDRESS structures. /// /// /// The size of the IP_ADAPTER_UNICAST_ADDRESS structure changed on Windows Vista and later. The Length member should /// be used to determine which version of the IP_ADAPTER_UNICAST_ADDRESS structure is being used. /// /// /// The version of the IP_ADAPTER_UNICAST_ADDRESS structure on Windows Vista and later has the following new member added: OnLinkPrefixLength. /// /// /// When this structure is used with the GetAdaptersAddresses function and similar management functions, all configured addresses are /// shown, including duplicate addresses. Such duplicate address entries can occur when addresses are configured statically. Such /// reporting facilitates administrator troubleshooting. The DadState member is effective in identifying and troubleshooting /// such situations. /// /// /// In the Windows SDK, the version of the structure for use on Windows Vista and later is defined as /// IP_ADAPTER_UNICAST_ADDRESS_LH. In the Windows SDK, the version of this structure to be used on earlier systems including /// Windows XP with Service Pack 1 (SP1) and later is defined as IP_ADAPTER_UNICAST_ADDRESS_XP. When compiling an application /// if the target platform is Windows Vista and later (, , or ), the IP_ADAPTER_UNICAST_ADDRESS_LH structure is typedefed to /// the IP_ADAPTER_UNICAST_ADDRESS structure. When compiling an application if the target platform is not Windows Vista and /// later, the IP_ADAPTER_UNICAST_ADDRESS_XP structure is typedefed to the IP_ADAPTER_UNICAST_ADDRESS structure. /// /// /// The SOCKET_ADDRESS structure is used in the IP_ADAPTER_UNICAST_ADDRESS structure. On the Microsoft Windows Software /// Development Kit (SDK) released for Windows Vista and later, the organization of header files has changed and the /// 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_UNICAST_ADDRESS structure, the /// Winsock2.h header file must be included before the Iphlpapi.h header file. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_adapter_unicast_address_lh typedef struct // _IP_ADAPTER_UNICAST_ADDRESS_LH { union { ULONGLONG Alignment; struct { ULONG Length; DWORD Flags; }; }; struct // _IP_ADAPTER_UNICAST_ADDRESS_LH *Next; SOCKET_ADDRESS Address; IP_PREFIX_ORIGIN PrefixOrigin; IP_SUFFIX_ORIGIN SuffixOrigin; // IP_DAD_STATE DadState; ULONG ValidLifetime; ULONG PreferredLifetime; ULONG LeaseLifetime; UINT8 OnLinkPrefixLength; } // IP_ADAPTER_UNICAST_ADDRESS_LH, *PIP_ADAPTER_UNICAST_ADDRESS_LH; [PInvokeData("iptypes.h", MSDNShortId = "65c3648c-89bd-417b-8a9b-feefa6149c4a")] [StructLayout(LayoutKind.Sequential)] public struct IP_ADAPTER_UNICAST_ADDRESS : ILinkedListElement { private long Alignment; /// Specifies the length of this structure. public uint Length { get => Alignment.LowPart(); set => Alignment = Macros.MAKELONG64(value, Alignment.HighPart()); } /// This member is reserved and should be set to zero. public uint Flags { get => unchecked((uint)Alignment.HighPart()); set => Alignment = Macros.MAKELONG64(Alignment.LowPart(), unchecked((int)value)); } /// /// Type: struct _IP_ADAPTER_UNICAST_ADDRESS* /// A pointer to the next IP adapter address structure in the list. /// public IntPtr Next; /// /// Type: SOCKET_ADDRESS /// The IP address for this unicast IP address entry. This member can be an IPv6 address or an IPv4 address. /// public SOCKET_ADDRESS Address; /// /// Type: IP_PREFIX_ORIGIN /// /// The prefix or network part of IP the address. This member can be one of the values from the IP_PREFIX_ORIGIN enumeration type /// defined in the Iptypes.h header file. /// /// public IP_PREFIX_ORIGIN PrefixOrigin; /// /// Type: IP_SUFFIX_ORIGIN /// /// The suffix or host part of the IP address. This member can be one of the values from the IP_SUFFIX_ORIGIN enumeration type /// defined in the Iptypes.h header file. /// /// public IP_SUFFIX_ORIGIN SuffixOrigin; /// /// Type: IP_DAD_STATE /// /// The duplicate address detection (DAD) state. This member can be one of the values from the IP_DAD_STATE enumeration type /// defined in the Iptypes.h header file. Duplicate address detection is available for both IPv4 and IPv6 addresses. /// /// public IP_DAD_STATE DadState; /// /// Type: ULONG /// The maximum lifetime, in seconds, that the IP address is valid. A value of 0xffffffff is considered to be infinite. /// public uint ValidLifetime; /// /// Type: ULONG /// The preferred lifetime, in seconds, that the IP address is valid. A value of 0xffffffff is considered to be infinite. /// public uint PreferredLifetime; /// /// Type: ULONG /// The lease lifetime, in seconds, that the IP address is valid. /// public uint LeaseLifetime; /// /// Type: UINT8 /// /// The length, in bits, of the prefix or network part of the IP address. For a unicast IPv4 address, any value greater than 32 /// is an illegal value. For a unicast IPv6 address, any value greater than 128 is an illegal value. A value of 255 is commonly /// used to represent an illegal value. /// /// Note This structure member is only available on Windows Vista and later. /// public byte OnLinkPrefixLength; /// /// Gets a reference to the next IP_ADAPTER_UNICAST_ADDRESS structure in the list. /// public IP_ADAPTER_UNICAST_ADDRESS? GetNext() => Next.ToNullableStructure(); /// public override string ToString() => Address.ToString(); } /// /// /// The IP_ADAPTER_WINS_SERVER_ADDRESS structure stores a single Windows Internet Name Service (WINS) server address in a /// linked list of WINS server addresses for a particular adapter. /// /// /// /// /// The IP_ADAPTER_ADDRESSES structure is retrieved by the GetAdaptersAddresses function. The FirstWinsServerAddress member of /// the IP_ADAPTER_ADDRESSES structure is a pointer to a linked list of IP_ADAPTER_WINS_SERVER_ADDRESS structures. /// /// /// The SOCKET_ADDRESS structure is used in the IP_ADAPTER_GATEWAY_ADDRESS structure. On the Microsoft Windows Software Development /// Kit (SDK) released for Windows Vista and later, the organization of header files has changed and the 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_GATEWAY_ADDRESS structure, the Winsock2.h header file must /// be included before the Iphlpapi.h header file. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_adapter_wins_server_address_lh typedef struct // _IP_ADAPTER_WINS_SERVER_ADDRESS_LH { union { ULONGLONG Alignment; struct { ULONG Length; DWORD Reserved; }; }; struct // _IP_ADAPTER_WINS_SERVER_ADDRESS_LH *Next; SOCKET_ADDRESS Address; } IP_ADAPTER_WINS_SERVER_ADDRESS_LH, *PIP_ADAPTER_WINS_SERVER_ADDRESS_LH; [PInvokeData("iptypes.h", MSDNShortId = "AF9A40C4-63DB-4830-A689-1DFE4DC2CAB7")] [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct IP_ADAPTER_WINS_SERVER_ADDRESS : ILinkedListElement { private long Alignment; /// Specifies the length of this structure. public uint Length { get => Alignment.LowPart(); set => Alignment = Macros.MAKELONG64(value, Alignment.HighPart()); } /// Reserved public int Reserved { get => Alignment.HighPart(); set => Alignment = Macros.MAKELONG64(Alignment.LowPart(), value); } /// /// A pointer to the next WINS server address structure in the list. /// public IntPtr Next; /// /// The IP address for this WINS server entry. This member can be an IPv6 address or an IPv4 address. /// public SOCKET_ADDRESS Address; /// /// Gets a reference to the next IP_ADAPTER_WINS_SERVER_ADDRESS structure in the list. /// public IP_ADAPTER_WINS_SERVER_ADDRESS? GetNext() => Next.ToNullableStructure(); /// public override string ToString() => Address.ToString(); } /// /// The IP_ADDR_STRING structure represents a node in a linked-list of IPv4 addresses. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_addr_string typedef struct _IP_ADDR_STRING { struct // _IP_ADDR_STRING *Next; IP_ADDRESS_STRING IpAddress; IP_MASK_STRING IpMask; DWORD Context; } IP_ADDR_STRING, *PIP_ADDR_STRING; [PInvokeData("iptypes.h", MSDNShortId = "783c383d-7fd3-45bc-90f6-2e8ce01db3c3")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct IP_ADDR_STRING : ILinkedListElement { /// /// A pointer to the next IP_ADDR_STRING structure in the list. /// public IntPtr Next; /// /// A value that specifies a structure type with a single member, String. The String member is a char array /// of size 16. This array holds an IPv4 address in dotted decimal notation. /// public IP_ADDRESS_STRING IpAddress; /// /// A value that specifies a structure type with a single member, String. The String member is a char array /// of size 16. This array holds the IPv4 subnet mask in dotted decimal notation. /// public IP_ADDRESS_STRING IpMask; /// /// A network table entry (NTE). This value corresponds to the NTEContext parameters in the and functions. /// public uint Context; /// /// Gets a reference to the next IP_ADDR_STRING structure in the list. /// /// /// A nullable type. A value indicates the end of the list. /// public IP_ADDR_STRING? GetNext() => Next.ToNullableStructure(); } /// /// The IP_ADDRESS_STRING structure stores an IPv4 address in dotted decimal notation. The IP_ADDRESS_STRING structure /// definition is also the type definition for the IP_MASK_STRING structure. /// /// The IP_ADDRESS_STRING structure is used as a parameter in the IP_ADDR_STRING structure. // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-ip_address_string typedef struct { char *String[4 4]; } // IP_ADDRESS_STRING, *PIP_ADDRESS_STRING, IP_MASK_STRING, *PIP_MASK_STRING; [PInvokeData("iptypes.h", MSDNShortId = "f426b22f-66e4-43e4-8852-357359df6f88")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct IP_ADDRESS_STRING { /// A character string that represents an IPv4 address or an IPv4 subnet mask in dotted decimal notation. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] public string String; /// public override string ToString() => String ?? ""; } /// The IP_INTERFACE_NAME_INFO structure contains information about an IPv4 interface on the local computer. /// /// /// In the Microsoft Windows Software Development Kit (SDK), the version of the structure for use on Windows 2000 with Service Pack 1 /// (SP1) and later is defined as IP_INTERFACE_NAME_INFO_W2KSP1. When compiling an application if the target platform is /// Windows 2000 with SP1 and later (, , or ), the IP_INTERFACE_NAME_INFO_W2KSP1 structure is typedefed to the /// IP_INTERFACE_NAME_INFO structure. /// /// /// The MediaType, ConnectionType, and AccessType members, definitions and assigned values are available from /// the Ipifcons.h header file. /// /// /// The optional InterfaceGuid member is often set for dial-up interfaces, and can be used to distinguish multiple dial-up /// interfaces that share the same device GUID. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-ip_interface_name_info_w2ksp1 typedef struct // ip_interface_name_info_w2ksp1 { ULONG Index; ULONG MediaType; UCHAR ConnectionType; UCHAR AccessType; GUID DeviceGuid; GUID // InterfaceGuid; } IP_INTERFACE_NAME_INFO_W2KSP1, *PIP_INTERFACE_NAME_INFO_W2KSP1; [PInvokeData("iptypes.h", MSDNShortId = "c113e97d-6f41-490a-a872-20d662fd763b")] [StructLayout(LayoutKind.Sequential)] public struct IP_INTERFACE_NAME_INFO { /// /// Type: ULONG /// The index of the IP interface for the active instance. /// public uint Index; /// /// Type: ULONG /// /// 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. Windows Server 2003, Windows 2000 Server with SP1 and Windows XP/2000: Wireless network cards are reported /// as IF_TYPE_ETHERNET_CSMACD. /// /// /// /// 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 MediaType; private byte _ConnectionType; /// /// Type: UCHAR /// The interface connection type for the adapter. /// The possible values for this member are defined in the Ipifcons.h header file. /// /// /// Value /// Meaning /// /// /// 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. /// /// /// /// 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. /// /// /// /// 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). /// /// /// /// public NET_IF_CONNECTION_TYPE ConnectionType { get => (NET_IF_CONNECTION_TYPE)_ConnectionType; set => _ConnectionType = (byte)value; } private byte _AccessType; /// /// Type: UCHAR /// A value of the IF_ACCESS_TYPE enumeration that specifies the access type for the interface. /// /// Windows Server 2003, Windows 2000 Server with SP1 and Windows XP/2000: The possible values for this member are defined /// in the Ipifcons.h header file. /// /// /// /// Value /// Meaning /// /// /// IF_ACCESS_LOOPBACK 1 /// The loopback access type. This value indicates that the interface loops back transmit data as receive data. /// /// /// IF_ACCESS_BROADCAST 2 /// /// The LAN access type which includes Ethernet. This value indicates that the interface provides native support for multicast or /// broadcast services. /// /// /// /// IF_ACCESS_POINT_TO_POINT 3 /// /// The point to point access type. This value indicates support for CoNDIS/WAN, except for non-broadcast multi-access (NBMA) /// interfaces. Windows Server 2003, Windows 2000 Server with SP1 and Windows XP/2000: This value was defined as /// IF_ACCESS_POINTTOPOINT in the Ipifcons.h header file. /// /// /// /// IF_ACCESS_POINT_TO_MULTI_POINT 4 /// /// The point to multipoint access type. This value indicates support for non-broadcast multi-access media, including the RAS /// internal interface and native ATM. Windows Server 2003, Windows 2000 Server with SP1 and Windows XP/2000: This value was /// defined as IF_ACCESS_POINTTOMULTIPOINT in the Ipifcons.h header file. /// /// /// /// public NET_IF_ACCESS_TYPE AccessType { get => (NET_IF_ACCESS_TYPE)_AccessType; set => _AccessType = (byte)value; } /// /// Type: GUID /// The GUID that identifies the underlying device for the interface. This member can be a zero GUID. /// public Guid DeviceGuid; /// /// Type: GUID /// The GUID that identifies the interface mapped to the device. Optional. This member can be a zero GUID. /// public Guid InterfaceGuid; } /// /// The IP_PER_ADAPTER_INFO structure contains information specific to a particular adapter. /// /// /// /// APIPA enables automatic IP address configuration on networks without DHCP servers, using the IANA-reserved Class B network /// 169.254.0.0, with a subnet mask of 255.255.0.0. Clients send ARP messages to ensure the selected address is not currently in use. /// Clients auto-configured in this fashion continue to poll for a valid DHCP server every five minutes, and if found, the DHCP /// server configuration overrides all auto-configuration settings. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_per_adapter_info_w2ksp1 typedef struct // _IP_PER_ADAPTER_INFO_W2KSP1 { UINT AutoconfigEnabled; UINT AutoconfigActive; PIP_ADDR_STRING CurrentDnsServer; IP_ADDR_STRING // DnsServerList; } IP_PER_ADAPTER_INFO_W2KSP1, *PIP_PER_ADAPTER_INFO_W2KSP1; [PInvokeData("iptypes.h", MSDNShortId = "10cfdded-4184-4d34-9ccd-85446c13d497")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct IP_PER_ADAPTER_INFO { /// /// Specifies whether IP address auto-configuration (APIPA) is enabled on this adapter. See Remarks. /// [MarshalAs(UnmanagedType.Bool)] public bool AutoconfigEnabled; /// /// Specifies whether this adapter's IP address is currently auto-configured by APIPA. /// [MarshalAs(UnmanagedType.Bool)] public bool AutoconfigActive; /// /// Reserved. Use the DnsServerList member to obtain the DNS servers for the local computer. /// public IntPtr CurrentDnsServer; /* IpAddressList* */ /// /// 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; /// /// /// A list of IP_ADDR_STRING structures pulled from that specify the set of DNS servers used by the /// local computer. /// /// public IEnumerable DnsServers => DnsServerList.GetLinkedList(s => s.IpAddress.String != null); } /// /// The IP_PER_ADAPTER_INFO structure contains information specific to a particular adapter. /// /// /// /// APIPA enables automatic IP address configuration on networks without DHCP servers, using the IANA-reserved Class B network /// 169.254.0.0, with a subnet mask of 255.255.0.0. Clients send ARP messages to ensure the selected address is not currently in use. /// Clients auto-configured in this fashion continue to poll for a valid DHCP server every five minutes, and if found, the DHCP /// server configuration overrides all auto-configuration settings. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/iptypes/ns-iptypes-_ip_per_adapter_info_w2ksp1 typedef struct // _IP_PER_ADAPTER_INFO_W2KSP1 { UINT AutoconfigEnabled; UINT AutoconfigActive; PIP_ADDR_STRING CurrentDnsServer; IP_ADDR_STRING // DnsServerList; } IP_PER_ADAPTER_INFO_W2KSP1, *PIP_PER_ADAPTER_INFO_W2KSP1; [PInvokeData("iptypes.h", MSDNShortId = "10cfdded-4184-4d34-9ccd-85446c13d497")] public class PIP_PER_ADAPTER_INFO : SafeMemoryHandle { /// Initializes a new instance of the class. /// Amount of space, in bytes, to reserve. public PIP_PER_ADAPTER_INFO(uint byteSize) : base((int)byteSize) { } /// /// Specifies whether this adapter's IP address is currently auto-configured by APIPA. /// public bool AutoconfigActive => !IsInvalid && handle.ToStructure().AutoconfigActive; /// /// Specifies whether IP address auto-configuration (APIPA) is enabled on this adapter. See Remarks. /// public bool AutoconfigEnabled => !IsInvalid && handle.ToStructure().AutoconfigEnabled; /// /// A linked list of IP_ADDR_STRING structures that specify the set of DNS servers used by the local computer. /// public IEnumerable DnsServerList => IsInvalid ? new IP_ADDR_STRING[0] : handle.ToStructure().DnsServers; /// Performs an implicit conversion from to . /// The PIP_PER_ADAPTER_INFO instance. /// The result of the conversion. public static implicit operator IntPtr(PIP_PER_ADAPTER_INFO info) => info.DangerousGetHandle(); } } }