Example #1
0
 internal AirPcapDevice(WinPcap.WinPcapDevice dev) : base(dev.Interface)
 {
 }
Example #2
0
 /// <summary>
 /// Sends all packets in a 'PcapSendQueue' out this pcap device
 /// </summary>
 /// <param name="q">
 /// A <see cref="SendQueue"/>
 /// </param>
 /// <param name="transmitMode">
 /// A <see cref="SendQueueTransmitModes"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.Int32"/>
 /// </returns>
 public int SendQueue( WinPcap.SendQueue q, SendQueueTransmitModes transmitMode )
 {
     return q.Transmit( this, transmitMode);
 }
Example #3
0
        /// <summary>
        /// Opens an Airpcap device with optional WinPcap.OpenFlags
        /// </summary>
        /// <param name="flags">
        /// A <see cref="WinPcap.OpenFlags"/>
        /// </param>
        /// <param name="read_timeout">
        /// A <see cref="System.Int32"/>
        /// </param>
        public override void Open(WinPcap.OpenFlags flags, int read_timeout)
        {
            base.Open(flags, read_timeout);

            // reteieve the airpcap device given the winpcap handle
            AirPcapDeviceHandle = WinPcap.SafeNativeMethods.pcap_get_airpcap_handle(PcapHandle);
        }
Example #4
0
        /// <summary>
        /// Gets a pcap stat object and calculate bps and pps
        /// </summary>
        private static void device_OnPcapStatistics(object sender, WinPcap.StatisticsModeEventArgs e)
        {
            // Calculate the delay in microseconds from the last sample.
            // This value is obtained from the timestamp that's associated with the sample.
            ulong delay = (e.Statistics.Timeval.Seconds - oldSec) * 1000000 - oldUsec + e.Statistics.Timeval.MicroSeconds;

            // Get the number of Bits per second
            ulong bps = ((ulong)e.Statistics.RecievedBytes * 8 * 1000000) / delay;
            /*                                       ^       ^
                                                     |       |
                                                     |       | 
                                                     |       |
                            converts bytes in bits --        |
                                                             |
                        delay is expressed in microseconds --
            */

            // Get the number of Packets per second
            ulong pps = ((ulong)e.Statistics.RecievedPackets * 1000000) / delay;

            // Convert the timestamp to readable format
            var ts = e.Statistics.Timeval.Date.ToLongTimeString();

            // Print Statistics
            Console.WriteLine("{0}: bps={1}, pps={2}", ts, bps, pps); 

            //store current timestamp
            oldSec = e.Statistics.Timeval.Seconds;
            oldUsec = e.Statistics.Timeval.MicroSeconds;
        }