public unsafe override IPEndPoint [] GetActiveUdpListeners ()
{
List<IPEndPoint> list = new List<IPEndPoint> ();
byte [] bytes4 = null;
int size4 = 0;
GetUdpTable (null, ref size4, true); // get size
bytes4 = new byte [size4];
GetUdpTable (bytes4, ref size4, true); // get list
int structSize4 = Marshal.SizeOf (typeof (Win32_MIB_UDPROW));
fixed (byte* ptr = bytes4) {
int count = Marshal.ReadInt32 ((IntPtr) ptr);
for (int i = 0; i < count; i++) {
Win32_MIB_UDPROW row = new Win32_MIB_UDPROW ();
Marshal.PtrToStructure ((IntPtr) (ptr + i * structSize4 + 4), row);
list.Add (row.LocalEndPoint);
}
}
if (Environment.OSVersion.Version.Major >= 6) { // Vista
byte [] bytes6 = null;
int size6 = 0;
GetUdp6Table (null, ref size6, true); // get size
bytes6 = new byte [size6];
GetUdp6Table (bytes6, ref size6, true); // get list
int structSize6 = Marshal.SizeOf (typeof (Win32_MIB_UDP6ROW));
fixed (byte* ptr = bytes6) {
int count = Marshal.ReadInt32 ((IntPtr) ptr);
for (int i = 0; i < count; i++) {
Win32_MIB_UDP6ROW row = new Win32_MIB_UDP6ROW ();
Marshal.PtrToStructure ((IntPtr) (ptr + i * structSize6 + 4), row);
list.Add (row.LocalEndPoint);
}
}
}
return list.ToArray ();
}