mirror of https://github.com/dahall/Vanara.git
Reworked all structures in IpHlpApi assembly to ensure size compatibility. (#296)
parent
92e7ca7365
commit
a517d536a3
|
@ -318,12 +318,12 @@ namespace Vanara.PInvoke
|
|||
|
||||
/// <summary>A WCHAR buffer that contains the string. The string does not need to be null-terminated.</summary>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 257)]
|
||||
public string[] String;
|
||||
public string String;
|
||||
}
|
||||
|
||||
/// <summary/>
|
||||
[PInvokeData("ifdef.h")]
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public struct IF_PHYSICAL_ADDRESS
|
||||
{
|
||||
/// <summary>A USHORT value that contains the length, in bytes, of the string.</summary>
|
||||
|
@ -331,7 +331,7 @@ namespace Vanara.PInvoke
|
|||
|
||||
/// <summary/>
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
||||
public string[] Address;
|
||||
public string Address;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -868,7 +868,12 @@ namespace Vanara.PInvoke
|
|||
// _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)]
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 8,
|
||||
#if x64
|
||||
Size = 32)]
|
||||
#else
|
||||
Size = 24)]
|
||||
#endif
|
||||
public struct IP_ADAPTER_ANYCAST_ADDRESS : ILinkedListElement<IP_ADAPTER_ANYCAST_ADDRESS>
|
||||
{
|
||||
/// <summary>Specifies the length of this structure.</summary>
|
||||
|
@ -922,7 +927,12 @@ namespace Vanara.PInvoke
|
|||
// _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)]
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 8,
|
||||
#if x64
|
||||
Size = 32)]
|
||||
#else
|
||||
Size = 24)]
|
||||
#endif
|
||||
public struct IP_ADAPTER_DNS_SERVER_ADDRESS : ILinkedListElement<IP_ADAPTER_DNS_SERVER_ADDRESS>
|
||||
{
|
||||
/// <summary>Specifies the length of this structure.</summary>
|
||||
|
@ -1009,7 +1019,12 @@ namespace Vanara.PInvoke
|
|||
// _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)]
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 8,
|
||||
#if x64
|
||||
Size = 32)]
|
||||
#else
|
||||
Size = 24)]
|
||||
#endif
|
||||
public struct IP_ADAPTER_GATEWAY_ADDRESS : ILinkedListElement<IP_ADAPTER_GATEWAY_ADDRESS>
|
||||
{
|
||||
/// <summary>Specifies the length of this structure.</summary>
|
||||
|
@ -1065,7 +1080,7 @@ namespace Vanara.PInvoke
|
|||
// 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)]
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 4)]
|
||||
public struct IP_ADAPTER_INFO : ILinkedListElement<IP_ADAPTER_INFO>
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -1233,14 +1248,14 @@ namespace Vanara.PInvoke
|
|||
/// <para>The time when the current DHCP lease was obtained.</para>
|
||||
/// <para>This member is only valid when the <c>DhcpEnabled</c> member is nonzero.</para>
|
||||
/// </summary>
|
||||
public uint LeaseObtained;
|
||||
public time_t LeaseObtained;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Type: <c>time_t</c></para>
|
||||
/// <para>The time when the current DHCP lease expires.</para>
|
||||
/// <para>This member is only valid when the <c>DhcpEnabled</c> member is nonzero.</para>
|
||||
/// </summary>
|
||||
public uint LeaseExpires;
|
||||
public time_t LeaseExpires;
|
||||
|
||||
/// <summary>Gets a sequence of IP_ADDR_STRING values representing IP addresses.</summary>
|
||||
public IEnumerable<IP_ADDR_STRING> IpAddresses => IpAddressList.GetLinkedList(s => s.IpAddress != null);
|
||||
|
@ -1281,7 +1296,12 @@ namespace Vanara.PInvoke
|
|||
// _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)]
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 8,
|
||||
#if x64
|
||||
Size = 32)]
|
||||
#else
|
||||
Size = 24)]
|
||||
#endif
|
||||
public struct IP_ADAPTER_MULTICAST_ADDRESS : ILinkedListElement<IP_ADAPTER_MULTICAST_ADDRESS>
|
||||
{
|
||||
/// <summary>Specifies the length of this structure.</summary>
|
||||
|
@ -1523,7 +1543,12 @@ namespace Vanara.PInvoke
|
|||
// _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)]
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 8,
|
||||
#if x64
|
||||
Size = 32)]
|
||||
#else
|
||||
Size = 24)]
|
||||
#endif
|
||||
public struct IP_ADAPTER_WINS_SERVER_ADDRESS : ILinkedListElement<IP_ADAPTER_WINS_SERVER_ADDRESS>
|
||||
{
|
||||
/// <summary>Specifies the length of this structure.</summary>
|
||||
|
@ -1558,7 +1583,7 @@ namespace Vanara.PInvoke
|
|||
// 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)]
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 4)]
|
||||
public struct IP_ADDR_STRING : ILinkedListElement<IP_ADDR_STRING>
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -1696,6 +1721,8 @@ namespace Vanara.PInvoke
|
|||
/// </summary>
|
||||
public IFTYPE MediaType;
|
||||
|
||||
private byte _ConnectionType;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Type: <c>UCHAR</c></para>
|
||||
/// <para>The interface connection type for the adapter.</para>
|
||||
|
@ -1727,8 +1754,9 @@ namespace Vanara.PInvoke
|
|||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public NET_IF_CONNECTION_TYPE ConnectionType;
|
||||
public NET_IF_CONNECTION_TYPE ConnectionType { get => (NET_IF_CONNECTION_TYPE)_ConnectionType; set => _ConnectionType = (byte)value; }
|
||||
|
||||
private byte _AccessType;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Type: <c>UCHAR</c></para>
|
||||
|
@ -1771,8 +1799,7 @@ namespace Vanara.PInvoke
|
|||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public NET_IF_ACCESS_TYPE AccessType;
|
||||
public NET_IF_ACCESS_TYPE AccessType { get => (NET_IF_ACCESS_TYPE)_AccessType; set => _AccessType = (byte)value; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>Type: <c>GUID</c></para>
|
||||
|
|
|
@ -119,7 +119,7 @@ namespace Vanara.PInvoke
|
|||
// MIB_TCP_STATE State; IN6_ADDR LocalAddr; DWORD dwLocalScopeId; DWORD dwLocalPort; IN6_ADDR RemoteAddr; DWORD dwRemoteScopeId;
|
||||
// DWORD dwRemotePort; } MIB_TCP6ROW, *PMIB_TCP6ROW;
|
||||
[PInvokeData("tcpmib.h", MSDNShortId = "b3e9eda5-5e86-4790-8b1b-ca9bae44b502")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 4)]
|
||||
public struct MIB_TCP6ROW
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -682,7 +682,7 @@ namespace Vanara.PInvoke
|
|||
// LocalAddr; DWORD dwLocalScopeId; DWORD dwLocalPort; IN6_ADDR RemoteAddr; DWORD dwRemoteScopeId; DWORD dwRemotePort; MIB_TCP_STATE
|
||||
// State; DWORD dwOwningPid; TCP_CONNECTION_OFFLOAD_STATE dwOffloadState; } MIB_TCP6ROW2, *PMIB_TCP6ROW2;
|
||||
[PInvokeData("tcpmib.h", MSDNShortId = "bbec3397-0317-40f7-926f-2ec48cf5386d")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 4)]
|
||||
public struct MIB_TCP6ROW2
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace Vanara.PInvoke
|
|||
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/api/udpmib/ns-udpmib-_mib_udp6row typedef struct _MIB_UDP6ROW {
|
||||
// IN6_ADDR dwLocalAddr; DWORD dwLocalScopeId; DWORD dwLocalPort; } MIB_UDP6ROW, *PMIB_UDP6ROW;
|
||||
[PInvokeData("udpmib.h", MSDNShortId = "c2cc4f77-8557-4206-9e46-aadf065eb8df")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[StructLayout(LayoutKind.Sequential, Size = 24, Pack = 4)]
|
||||
public struct MIB_UDP6ROW
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -280,7 +280,7 @@ namespace Vanara.PInvoke
|
|||
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/api/udpmib/ns-udpmib-_mib_udprow typedef struct _MIB_UDPROW {
|
||||
// DWORD dwLocalAddr; DWORD dwLocalPort; } MIB_UDPROW, *PMIB_UDPROW;
|
||||
[PInvokeData("udpmib.h", MSDNShortId = "db366802-962f-4e83-838e-1e2f51beab92")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 4)]
|
||||
public struct MIB_UDPROW
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -425,7 +425,7 @@ namespace Vanara.PInvoke
|
|||
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/api/udpmib/ns-udpmib-_mib_udprow_owner_pid typedef struct
|
||||
// _MIB_UDPROW_OWNER_PID { DWORD dwLocalAddr; DWORD dwLocalPort; DWORD dwOwningPid; } MIB_UDPROW_OWNER_PID, *PMIB_UDPROW_OWNER_PID;
|
||||
[PInvokeData("udpmib.h", MSDNShortId = "b914b6eb-adf9-4a61-ae8f-05d3ff90ce90")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 4)]
|
||||
public struct MIB_UDPROW_OWNER_PID
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
@ -1447,7 +1447,12 @@ namespace Vanara.PInvoke
|
|||
// https://docs.microsoft.com/en-us/windows/win32/api/ws2def/ns-ws2def-socket_address typedef struct _SOCKET_ADDRESS { LPSOCKADDR
|
||||
// lpSockaddr; INT iSockaddrLength; } SOCKET_ADDRESS, *PSOCKET_ADDRESS, *LPSOCKET_ADDRESS;
|
||||
[PInvokeData("ws2def.h", MSDNShortId = "37fbcb96-a859-4eca-8928-8051f95407b9")]
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
[StructLayout(LayoutKind.Sequential,
|
||||
#if x64
|
||||
Size = 16)]
|
||||
#else
|
||||
Size = 8)]
|
||||
#endif
|
||||
public struct SOCKET_ADDRESS
|
||||
{
|
||||
/// <summary>A pointer to a socket address represented as a SOCKADDR structure.</summary>
|
||||
|
|
|
@ -36,7 +36,9 @@ namespace Vanara.PInvoke.Tests
|
|||
{
|
||||
System.Reflection.TypeAttributes attr = System.Reflection.TypeAttributes.SequentialLayout | System.Reflection.TypeAttributes.ExplicitLayout;
|
||||
return types.Where(t => t.IsValueType && !t.IsEnum && !t.IsGenericType && (t.Attributes & attr) != 0 && ((filters?.Length ?? 0) == 0 || filters.Any(s => t.Name.Contains(s)))).
|
||||
OrderBy(t => (fullName ? t.FullName : t.Name)).Select(t => $"{(fullName ? t.FullName : t.Name)} = {InteropExtensions.SizeOf(t)}").ToList();
|
||||
OrderBy(t => fullName ? t.FullName : t.Name).Select(t => $"{(fullName ? t.FullName : t.Name)} = {GetTypeSize(t)}").ToList();
|
||||
|
||||
static long GetTypeSize(Type t) { try { return (long)InteropExtensions.SizeOf(t); } catch { return -1; } }
|
||||
}
|
||||
|
||||
public static void RunForEach<TEnum>(Type lib, string name, Func<TEnum, object[]> makeParam, Action<TEnum, object, object[]> action = null, Action<Exception> error = null) where TEnum : Enum =>
|
||||
|
|
|
@ -39,6 +39,13 @@ namespace Vanara.PInvoke.Tests
|
|||
private static SOCKADDR_IN LocalAddrV4 => localv4.sin_family == 0 ? (localv4 = primaryAdapter.UnicastAddresses.Select(r => r.Address.GetSOCKADDR()).First(a => a.si_family == ADDRESS_FAMILY.AF_INET).Ipv4) : localv4;
|
||||
private static SOCKADDR_IN6 LocalAddrV6 => localv6.sin6_family == 0 ? (localv6 = primaryAdapter.UnicastAddresses.Select(r => r.Address.GetSOCKADDR()).First(a => a.si_family == ADDRESS_FAMILY.AF_INET6).Ipv6) : localv6;
|
||||
|
||||
[Test]
|
||||
public void _StructSizeTest()
|
||||
{
|
||||
foreach (var s in typeof(Vanara.PInvoke.IpHlpApi).GetNestedStructSizes())
|
||||
TestContext.WriteLine(s);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddDeleteIPAddressTest()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue