Esempio n. 1
0
        /// <summary>
        /// Writes a packet to the pcap dump file associated with this device.
        /// </summary>
        /// <param name="p">The packet to write</param>
        public void PcapDump(byte[] p, PcapHeader h)
        {
            if (!PcapOpened)
            {
                throw new InvalidOperationException("Cannot dump packet, device is not opened");
            }
            if (!PcapDumpOpened)
            {
                throw new InvalidOperationException("Cannot dump packet, dump file is not opened");
            }

            //Marshal packet
            IntPtr pktPtr;

            pktPtr = Marshal.AllocHGlobal(p.Length);
            Marshal.Copy(p, 0, pktPtr, p.Length);

            //Marshal header
            IntPtr hdrPtr;

            hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SharpPcap.PCAP_PKTHDR)));
            Marshal.StructureToPtr(h.m_pcap_pkthdr, hdrPtr, true);

            SharpPcap.pcap_dump(m_pcapDumpHandle, hdrPtr, pktPtr);

            Marshal.FreeHGlobal(pktPtr);
            Marshal.FreeHGlobal(hdrPtr);
        }
Esempio n. 2
0
 /// <summary>
 /// Add a packet to this send queue.
 /// </summary>
 /// <param name="packet">The packet bytes to add</param>
 /// <param name="pcapHdr">The pcap header of the packet</param>
 /// <returns>True if success, else false</returns>
 public bool Add(byte[] packet, PcapHeader pcapHdr)
 {
     return(this.Add(packet, pcapHdr.m_pcap_pkthdr));
 }
Esempio n. 3
0
        /// <summary>
        /// Writes a packet to the pcap dump file associated with this device.
        /// </summary>
        /// <param name="p">The packet to write</param>
        public void PcapDump(byte[] p, PcapHeader h)
        {
            if(!PcapOpened)
                throw new InvalidOperationException("Cannot dump packet, device is not opened");
            if(!PcapDumpOpened)
                throw new InvalidOperationException("Cannot dump packet, dump file is not opened");

            //Marshal packet
            IntPtr pktPtr;
            pktPtr = Marshal.AllocHGlobal(p.Length);
            Marshal.Copy(p, 0, pktPtr, p.Length);

            //Marshal header
            IntPtr hdrPtr;
            hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SharpPcap.PCAP_PKTHDR)));
            Marshal.StructureToPtr(h.m_pcap_pkthdr, hdrPtr, true);

            SharpPcap.pcap_dump(m_pcapDumpHandle, hdrPtr, pktPtr);

            Marshal.FreeHGlobal(pktPtr);
            Marshal.FreeHGlobal(hdrPtr);
        }
Esempio n. 4
0
 /// <summary>
 /// Add a packet to this send queue. 
 /// </summary>
 /// <param name="packet">The packet bytes to add</param>
 /// <param name="pcapHdr">The pcap header of the packet</param>
 /// <returns>True if success, else false</returns>
 public bool Add( byte[] packet, PcapHeader pcapHdr )
 {
     return this.Add( packet, pcapHdr.m_pcap_pkthdr);
 }