Пример #1
0
        /// <summary>
        /// Example showing how to retrieve a list of AirPcap devices
        /// We can't use this because AirPcap devices don't have a pcap handle
        /// but this code is worth keeping around
        /// </summary>
        /// <returns>
        /// A <see cref="List<AirPcapDevice>"/>
        /// </returns>
        private static List <AirPcapDevice> GetAirPcapDevices()
        {
            var deviceList = new List <AirPcapDevice>();

            var devicePtr   = IntPtr.Zero;
            var errorBuffer = new StringBuilder(Pcap.PCAP_ERRBUF_SIZE);

            int result = AirPcapSafeNativeMethods.AirpcapGetDeviceList(ref devicePtr, errorBuffer);

            if (result < 0)
            {
                throw new PcapException(errorBuffer.ToString());
            }

            IntPtr nextDevPtr = devicePtr;

            while (nextDevPtr != IntPtr.Zero)
            {
                // Marshal pointer into a struct
                AirPcapUnmanagedStructures.AirpcapDeviceDescription deviceDescUnmanaged =
                    (AirPcapUnmanagedStructures.AirpcapDeviceDescription)Marshal.PtrToStructure(nextDevPtr,
                                                                                                typeof(AirPcapUnmanagedStructures.AirpcapDeviceDescription));
                var managedDeviceDesc = new AirPcapDeviceDescription(deviceDescUnmanaged);
//                deviceList.Add(new AirPcapDevice(managedDeviceDesc));
                nextDevPtr = deviceDescUnmanaged.next;
            }
            AirPcapSafeNativeMethods.AirpcapFreeDeviceList(devicePtr); // Free unmanaged memory

            return(deviceList);
        }
Пример #2
0
 internal AirPcapDeviceDescription(AirPcapUnmanagedStructures.AirpcapDeviceDescription desc)
 {
     this.Name        = desc.Name;
     this.Description = desc.Description;
 }