/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="device">
		/// A <see cref="LibPcapLiveDevice"/>
		/// </param>
		/// <param name="captureFilename">
		/// A <see cref="System.String"/>
		/// </param>
		public CaptureFileWriterDevice(LibPcapLiveDevice device,
									   string captureFilename) :
			this((GodLesZ.Library.Network.Packet.LinkLayers)LibPcapSafeNativeMethods.pcap_datalink(device.PcapHandle),
				 LibPcapSafeNativeMethods.pcap_snapshot(device.PcapHandle),
				 captureFilename,
				 FileMode.OpenOrCreate) {
		}
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="device">
 /// A <see cref="LibPcapLiveDevice"/>
 /// </param>
 /// <param name="captureFilename">
 /// A <see cref="System.String"/>
 /// </param>
 public CaptureFileWriterDevice(LibPcapLiveDevice device,
                                string captureFilename) :
     this((GodLesZ.Library.Network.Packet.LinkLayers)LibPcapSafeNativeMethods.pcap_datalink(device.PcapHandle),
          LibPcapSafeNativeMethods.pcap_snapshot(device.PcapHandle),
          captureFilename,
          FileMode.OpenOrCreate)
 {
 }
Example #3
0
        /// <summary>
        /// Retrieve pcap statistics from the adapter
        /// </summary>
        /// <param name="pcap_t">
        /// pcap_t* for the adapter
        /// A <see cref="IntPtr"/>
        /// </param>
        internal PcapStatistics(IntPtr pcap_t)
        {
            IntPtr stat;

            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                // allocate memory for the struct
                stat = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PcapUnmanagedStructures.pcap_stat_unix)));
            }
            else
            {
                // allocate memory for the struct
                stat = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PcapUnmanagedStructures.pcap_stat_windows)));
            }

            // retrieve the stats
            var result = (PcapUnmanagedStructures.PcapStatReturnValue)LibPcapSafeNativeMethods.pcap_stats(pcap_t, stat);

            // process the return value
            switch (result)
            {
            case PcapUnmanagedStructures.PcapStatReturnValue.Error:
                // retrieve the error information
                var error = LibPcapLiveDevice.GetLastError(pcap_t);

                // free the stats memory so we don't leak before we throw
                Marshal.FreeHGlobal(stat);

                throw new StatisticsException(error);

            case PcapUnmanagedStructures.PcapStatReturnValue.Success:
                // nothing to do upon success
                break;
            }

            // marshal the unmanaged memory into an object of the proper type
            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                var managedStat = (PcapUnmanagedStructures.pcap_stat_unix)Marshal.PtrToStructure(stat,
                                                                                                 typeof(PcapUnmanagedStructures.pcap_stat_unix));

                // copy the values
                this.ReceivedPackets = (uint)managedStat.ps_recv;
                this.DroppedPackets  = (uint)managedStat.ps_drop;
                //                this.InterfaceDroppedPackets = (uint)managedStat.ps_ifdrop;
            }
            else
            {
                var managedStat = (PcapUnmanagedStructures.pcap_stat_windows)Marshal.PtrToStructure(stat,
                                                                                                    typeof(PcapUnmanagedStructures.pcap_stat_windows));

                // copy the values
                this.ReceivedPackets = (uint)managedStat.ps_recv;
                this.DroppedPackets  = (uint)managedStat.ps_drop;
                //                this.InterfaceDroppedPackets = (uint)managedStat.ps_ifdrop;
            }

            // NOTE: Not supported on unix or winpcap, no need to
            //       put a bogus value in this field
            this.InterfaceDroppedPackets = 0;

            // free the stats
            Marshal.FreeHGlobal(stat);
        }
Example #4
0
		/// <summary>
		/// Constructs a new ARP Resolver
		/// </summary>
		/// <param name="device">The network device on which this resolver sends its ARP packets</param>
		public ARP(LibPcap.LibPcapLiveDevice device) {
			_device = device;
		}
Example #5
0
 /// <summary>
 /// Constructs a new ARP Resolver
 /// </summary>
 /// <param name="device">The network device on which this resolver sends its ARP packets</param>
 public ARP(LibPcap.LibPcapLiveDevice device)
 {
     _device = device;
 }