Example #1
0
        public static IList <pcap_if> findalldevs()
        {
            IntPtr        alldevsp = IntPtr.Zero;
            StringBuilder error    = new StringBuilder(libpcap.PCAP_ERRBUF_SIZE);

            if (libpcap.pcap_findalldevs(ref alldevsp, error) < 0)
            {
                return(null);
            }

            try
            {
                var       all = new List <pcap_if>();
                pcap_if_t dev = (pcap_if_t)Marshal.PtrToStructure(alldevsp, typeof(pcap_if_t));
                all.Add(get_if(dev));

                while (dev.next != IntPtr.Zero)
                {
                    dev = (pcap_if_t)Marshal.PtrToStructure(dev.next, typeof(pcap_if_t));
                    all.Add(get_if(dev));
                }

                return(all);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                libpcap.pcap_freealldevs(alldevsp);
            }
        }
Example #2
0
 private static pcap_if get_if(pcap_if_t ifdata)
 {
     return(new pcap_if()
     {
         m_description = Marshal.PtrToStringAnsi(ifdata.description),
         m_name = Marshal.PtrToStringAnsi(ifdata.name),
         m_flags = ifdata.flags,
         addrs = pcap_addr.get_addresses(ifdata.addresses)
     });
 }