コード例 #1
0
        public UdpConnectInfo GetUdpConnexions()
        {
            byte[] buffer  = new byte[20000]; // Start with 20.000 bytes left for information about tcp table
            int    pdwSize = 20000;
            int    res     = ConInfosHlpAPI32Wrapper.GetUdpTable(buffer, out pdwSize, true);

            if (res != NO_ERROR)
            {
                buffer = new byte[pdwSize];
                res    = ConInfosHlpAPI32Wrapper.GetUdpTable(buffer, out pdwSize, true);
                if (res != 0)
                {
                    return(UdpConnexion);     // Error. You should handle it
                }
            }

            UdpConnexion = new UdpConnectInfo();

            int nOffset = 0;

            // number of entry in the
            UdpConnexion.dwNumEntries = Convert.ToInt32(buffer[nOffset]);
            nOffset           += 4;
            UdpConnexion.table = new UdpConnectTable[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;
                UdpConnexion.table[i].Local = new IPEndPoint(IPAddress.Parse(LocalAdrr), LocalPort);
            }
            return(UdpConnexion);
        }
コード例 #2
0
        public UdpConnectInfo GetUdpConnexions()
        {
            byte[] buffer = new byte[20000]; // Start with 20.000 bytes left for information about tcp table
            int pdwSize = 20000;
            int res = ConInfosHlpAPI32Wrapper.GetUdpTable(buffer, out pdwSize, true);
            if (res != NO_ERROR)
            {
                buffer = new byte[pdwSize];
                res = ConInfosHlpAPI32Wrapper.GetUdpTable(buffer, out pdwSize, true);
                if (res != 0)
                    return UdpConnexion;     // Error. You should handle it
            }

            UdpConnexion = new UdpConnectInfo();

            int nOffset = 0;
            // number of entry in the
            UdpConnexion.dwNumEntries = Convert.ToInt32(buffer[nOffset]);
            nOffset += 4;
            UdpConnexion.table = new UdpConnectTable[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;
                UdpConnexion.table[i].Local = new IPEndPoint(IPAddress.Parse(LocalAdrr), LocalPort);
            }
            return UdpConnexion;
        }