public void GetUdpConnections() { byte[] buffer = new byte[20000]; // Start with 20.000 bytes left for information about tcp table int pdwSize = 20000; int res = IPHlpAPI32Wrapper.GetUdpTable(buffer, out pdwSize, true); if (res != Utils.NO_ERROR) { buffer = new byte[pdwSize]; res = IPHlpAPI32Wrapper.GetUdpTable(buffer, out pdwSize, true); if (res != Utils.NO_ERROR) { return; // Error. You should handle it } } UdpConnections = new IpHlpApidotnet.MIB_UDPTABLE(); int nOffset = 0; // number of entry in the UdpConnections.dwNumEntries = Convert.ToInt32(buffer[nOffset]); nOffset += 4; UdpConnections.table = new MIB_UDPROW[UdpConnections.dwNumEntries]; for (int i = 0; i < UdpConnections.dwNumEntries; i++) { ((MIB_UDPROW)(UdpConnections.table[i])).Local = Utils.BufferToIPEndPoint(buffer, ref nOffset, false);//new IPEndPoint(IPAddress.Parse(LocalAdrr), LocalPort); } }
public void GetUdpConnexions() { byte[] buffer = new byte[20000]; // Start with 20.000 bytes left for information about tcp table int pdwSize = 20000; int res = IPHlpAPI32Wrapper.GetUdpTable(buffer, out pdwSize, true); if (res != NO_ERROR) { buffer = new byte[pdwSize]; res = IPHlpAPI32Wrapper.GetUdpTable(buffer, out pdwSize, true); if (res != 0) { return; // Error. You should handle it } } UdpConnexion = new IpHlpApidotnet.MIB_UDPTABLE(); int nOffset = 0; // number of entry in the UdpConnexion.dwNumEntries = Convert.ToInt32(buffer[nOffset]); nOffset += 4; UdpConnexion.table = new MIB_UDPROW[UdpConnexion.dwNumEntries]; for (int i = 0; i < UdpConnexion.dwNumEntries; i++) { string LocalAdrr = buffer[nOffset].ToString() + "." + buffer[nOffset + 1].ToString() + "." + buffer[nOffset + 2].ToString() + "." + buffer[nOffset + 3].ToString(); nOffset += 4; int LocalPort = (((int)buffer[nOffset]) << 8) + (((int)buffer[nOffset + 1])) + (((int)buffer[nOffset + 2]) << 24) + (((int)buffer[nOffset + 3]) << 16); nOffset += 4; ((MIB_UDPROW)(UdpConnexion.table[i])).Local = new IPEndPoint(IPAddress.Parse(LocalAdrr), LocalPort); } }