/// <summary> /// Constructor /// </summary> /// <param name="linkLayerType"> /// A <see cref="PacketDotNet.LinkLayers"/> /// </param> /// <param name="snapshotLength"> /// A <see cref="System.Nullable<System.Int32>"/> /// </param> /// <param name="captureFilename"> /// A <see cref="System.String"/> /// </param> /// <param name="mode"> /// A <see cref="FileMode"/> /// </param> public CaptureFileWriterDevice(PacketDotNet.LinkLayers linkLayerType, int?snapshotLength, string captureFilename, FileMode mode) { m_pcapFile = captureFilename; // append isn't possible without some difficulty and not implemented yet if (mode == FileMode.Append) { throw new System.InvalidOperationException("FileMode.Append is not supported, please contact the developers if you are interested in helping to implementing it"); } if (!snapshotLength.HasValue) { snapshotLength = Pcap.MAX_PACKET_SIZE; } else if (snapshotLength > Pcap.MAX_PACKET_SIZE) { throw new System.InvalidOperationException("snapshotLength > Pcap.MAX_PACKET_SIZE"); } // set the device handle PcapHandle = LibPcapSafeNativeMethods.pcap_open_dead((int)linkLayerType, snapshotLength.Value); m_pcapDumpHandle = LibPcapSafeNativeMethods.pcap_dump_open(PcapHandle, captureFilename); if (m_pcapDumpHandle == IntPtr.Zero) { throw new PcapException("Error opening dump file '" + LastError + "'"); } }
/// <summary> /// Open the device. To start capturing call the 'StartCapture' function /// </summary> /// <param name="configuration"> /// A <see cref="DeviceConfiguration"/> /// </param> public virtual void Open(DeviceConfiguration configuration) { // Caches linkType value. // Open refers to the device being "created" // This method is called by sub-classes in the override method int dataLink = 0; if (Opened) { dataLink = LibPcapSafeNativeMethods.pcap_datalink(Handle); } if (dataLink >= 0) { linkType = (PacketDotNet.LinkLayers)dataLink; } }
public packet(SharpPcap.RawCapture pPacket) { var timestamp = pPacket.Timeval.Date; this.layer = pPacket.LinkLayerType; this.time = timestamp.Hour.ToString() + ":" + timestamp.Minute.ToString() + ":" + timestamp.Second.ToString() + "," + timestamp.Millisecond.ToString(); this.srcIp = ""; this.destIp = ""; this.protocol = ""; this.info = ""; this.color = "White"; this.pPacket = pPacket; this.rPacket = PacketDotNet.Packet.ParsePacket(pPacket.LinkLayerType, pPacket.Data); this.frame_info = new Dictionary <string, string>(); this.ethernet_info = new Dictionary <string, string>(); this.ip_info = new Dictionary <string, string>(); this.arp_info = new Dictionary <string, string>(); this.icmp_info = new Dictionary <string, string>(); this.igmp_info = new Dictionary <string, string>(); this.tcp_info = new Dictionary <string, string>(); this.udp_info = new Dictionary <string, string>(); this.application_info = new Dictionary <string, string>(); this.application_byte = null; this.mf = false; this.df = true; this.offset = 0; analysis_packet(); // 计算校验和 if (this.tcp_info.Count > 0 && this.tcp_info["Checksum(校验和)"] != this.tcp_info["tcpPacket计算校验和函数计算结果"]) { this.color = "Red"; } }
public packet(SharpPcap.RawCapture pPacket) { var timestamp = pPacket.Timeval.Date; this.layer = pPacket.LinkLayerType; this.time = timestamp.Hour.ToString() + ":" + timestamp.Minute.ToString() + ":" + timestamp.Second.ToString() + "," + timestamp.Millisecond.ToString(); this.srcIp = ""; this.destIp = ""; this.protocol = ""; this.info = ""; this.color = "White"; this.pPacket = pPacket; this.rPacket = PacketDotNet.Packet.ParsePacket(pPacket.LinkLayerType, pPacket.Data); this.frame_info = new Dictionary<string, string>(); this.ethernet_info = new Dictionary<string, string>(); this.ip_info = new Dictionary<string, string>(); this.arp_info = new Dictionary<string, string>(); this.icmp_info = new Dictionary<string, string>(); this.igmp_info = new Dictionary<string, string>(); this.tcp_info = new Dictionary<string, string>(); this.udp_info = new Dictionary<string, string>(); this.application_info = new Dictionary<string, string>(); this.application_byte = null; analysis_packet(); // 计算校验和 if (this.tcp_info.Count > 0 && this.tcp_info["Checksum(校验和)"] != this.tcp_info["tcpPacket计算校验和函数计算结果"]) { this.color = "Red"; } }