diff --git a/PInvoke/IpHlpApi/UdpMib.cs b/PInvoke/IpHlpApi/UdpMib.cs index 3fd48f3b..1d268d1e 100644 --- a/PInvoke/IpHlpApi/UdpMib.cs +++ b/PInvoke/IpHlpApi/UdpMib.cs @@ -61,6 +61,9 @@ public static partial class IpHlpApi /// The port number of the UDP endpoint on the local computer. This member is stored in network byte order. /// public uint dwLocalPort; + + /// The port number of the UDP endpoint on the local computer. This member is stored in network byte order. + public ushort dwHostLocalPort { readonly get => ntohs((ushort)dwLocalPort); set => dwLocalPort = htons(value); } } /// @@ -109,7 +112,7 @@ public static partial class IpHlpApi // OwningModuleInfo[TCPIP_OWNING_MODULE_SIZE]; } MIB_UDP6ROW_OWNER_MODULE, *PMIB_UDP6ROW_OWNER_MODULE; [PInvokeData("udpmib.h", MSDNShortId = "dcc80b3c-d4d5-44f4-9c7f-df6be2e21889")] [StructLayout(LayoutKind.Sequential, Pack = 8)] - public struct MIB_UDP6ROW_OWNER_MODULE + public struct MIB_UDP6ROW_OWNER_MODULE : IComparable, IComparable { /// /// Type: UCHAR[16] @@ -161,6 +164,24 @@ public static partial class IpHlpApi /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = TCPIP_OWNING_MODULE_SIZE)] public ulong[] OwningModuleInfo; + + /// The port number for the local UDP endpoint. This member is stored in network byte order. + public ushort dwHostLocalPort { readonly get => ntohs((ushort)dwLocalPort); set => dwLocalPort = htons(value); } + + /// + readonly int IComparable.CompareTo(MIB_UDP6ROW_OWNER_MODULE p) + { + var cmp = ((IComparable)ucLocalAddr).CompareTo(p.ucLocalAddr); + if (cmp == 0) + cmp = dwHostLocalPort.CompareTo(p.dwHostLocalPort); + if (cmp == 0) + cmp = dwOwningPid.CompareTo(p.dwOwningPid); + return cmp; + } + + /// + readonly int IComparable.CompareTo(object? obj) => obj is MIB_UDP6ROW_OWNER_MODULE i ? ((IComparable)this).CompareTo(i) : + (obj is null ? 1 : throw new ArgumentException("Invalid type for comparison.", nameof(obj))); } /// @@ -207,7 +228,7 @@ public static partial class IpHlpApi // MIB_UDP6ROW_OWNER_PID, *PMIB_UDP6ROW_OWNER_PID; [PInvokeData("udpmib.h", MSDNShortId = "d3d02485-381b-4058-b4b9-0a2c9c365f43")] [StructLayout(LayoutKind.Sequential, Size = 28, Pack = 4)] - public struct MIB_UDP6ROW_OWNER_PID + public struct MIB_UDP6ROW_OWNER_PID : IComparable, IComparable { /// /// The IPv6 address for the local UDP endpoint. This member is stored in a character array in network byte order. @@ -236,6 +257,24 @@ public static partial class IpHlpApi /// /// public uint dwOwningPid; + + /// The port number of the UDP endpoint on the local computer. This member is in host byte order. + public ushort dwHostLocalPort { readonly get => ntohs((ushort)dwLocalPort); set => dwLocalPort = htons(value); } + + /// + readonly int IComparable.CompareTo(MIB_UDP6ROW_OWNER_PID p) + { + var cmp = ((IComparable)ucLocalAddr).CompareTo(p.ucLocalAddr); + if (cmp == 0) + cmp = dwHostLocalPort.CompareTo(p.dwHostLocalPort); + if (cmp == 0) + cmp = dwOwningPid.CompareTo(p.dwOwningPid); + return cmp; + } + + /// + readonly int IComparable.CompareTo(object? obj) => obj is MIB_UDP6ROW_OWNER_PID i ? ((IComparable)this).CompareTo(i) : + (obj is null ? 1 : throw new ArgumentException("Invalid type for comparison.", nameof(obj))); } /// @@ -291,6 +330,9 @@ public static partial class IpHlpApi /// The port number of the UDP endpoint on the local computer. This member is stored in network byte order. /// public uint dwLocalPort; + + /// The port number of the UDP endpoint on the local computer. This member is in host byte order. + public ushort dwHostLocalPort { readonly get => ntohs((ushort)dwLocalPort); set => dwLocalPort = htons(value); } } /// @@ -380,6 +422,9 @@ public static partial class IpHlpApi /// [MarshalAs(UnmanagedType.ByValArray, SizeConst = TCPIP_OWNING_MODULE_SIZE)] public ulong[] OwningModuleInfo; + + /// The port number of the UDP endpoint on the local computer. This member is in host byte order. + public ushort dwHostLocalPort { readonly get => ntohs((ushort)dwLocalPort); set => dwLocalPort = htons(value); } } ///