예제 #1
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>
        internal bool Add(byte[] packet, PcapUnmanagedStructures.pcap_pkthdr pcapHdr)
        {
            if (m_queue == IntPtr.Zero)
            {
                throw new PcapException("Can't add packet, this queue is disposed");
            }

            if (pcapHdr.caplen == 0)
            {
                pcapHdr.caplen = (uint)packet.Length;//set the length in the header field
            }
            //Marshal packet
            IntPtr pktPtr;

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

            //Marshal header
            IntPtr hdrPtr;

            hdrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PcapUnmanagedStructures.pcap_pkthdr)));
            Marshal.StructureToPtr(pcapHdr, hdrPtr, true);

            int res = SafeNativeMethods.pcap_sendqueue_queue(m_queue, hdrPtr, pktPtr);

            Marshal.FreeHGlobal(pktPtr);
            Marshal.FreeHGlobal(hdrPtr);

            return(res != -1);
        }
예제 #2
0
        protected virtual Packet MarshalPacket(IntPtr /* pcap_pkthdr* */ header, IntPtr data)
        {
            Packet p;

            PcapUnmanagedStructures.pcap_pkthdr pkt_header =
                (PcapUnmanagedStructures.pcap_pkthdr)Marshal.PtrToStructure(header,
                                                                            typeof(PcapUnmanagedStructures.pcap_pkthdr));
            byte[] pkt_data = new byte[pkt_header.caplen];
            Marshal.Copy(data, pkt_data, 0, (int)pkt_header.caplen);

            p = Packets.PacketFactory.dataToPacket(PcapDataLink, pkt_data,
                                                   new Packets.Util.Timeval((ulong)pkt_header.ts.tv_sec,
                                                                            (ulong)pkt_header.ts.tv_usec));
            p.pcapHeader = new PcapHeader(pkt_header);

            return(p);
        }
예제 #3
0
 internal PcapStatistics(Packets.Packet p)
 {
     this.m_pktHdr  = p.PcapHeader.m_pcap_pkthdr;
     this.m_pktData = p.Bytes;
 }
예제 #4
0
 /// <summary>
 /// Constructs a new Pcap Statistics strcuture
 /// </summary>
 /// <param name="pktHdr">Time value as PCAP_PKTHDR</param>
 /// <param name="pktData">Statistics values as PCAP_PKTDATA</param>
 internal PcapStatistics(PcapUnmanagedStructures.pcap_pkthdr pktHdr, PcapUnmanagedStructures.PCAP_PKTDATA pktData)
 {
     this.m_pktHdr  = pktHdr;
     this.m_pktData = pktData.bytes;
 }
예제 #5
0
 internal PcapStatistics(Packets.Packet p)
 {
     this.m_pktHdr   = p.PcapHeader.m_pcap_pkthdr;
     this.m_pktData  = p.Bytes;
 }
예제 #6
0
 /// <summary>
 /// Constructs a new Pcap Statistics strcuture
 /// </summary>
 /// <param name="pktHdr">Time value as PCAP_PKTHDR</param>
 /// <param name="pktData">Statistics values as PCAP_PKTDATA</param>
 internal PcapStatistics(PcapUnmanagedStructures.pcap_pkthdr pktHdr, PcapUnmanagedStructures.PCAP_PKTDATA pktData)
 {
     this.m_pktHdr   = pktHdr;
     this.m_pktData  = pktData.bytes;
 }
예제 #7
0
 /// <summary>
 /// Constructs a new PcapHeader
 /// </summary>
 /// <param name="m_pcap_pkthdr">The underlying pcap_pkthdr structure</param>
 internal PcapHeader( PcapUnmanagedStructures.pcap_pkthdr m_pcap_pkthdr )
 {
     this.m_pcap_pkthdr = m_pcap_pkthdr;
 }
예제 #8
0
 /// <summary>
 /// Constructs a new PcapHeader
 /// </summary>
 public PcapHeader()
 {
     m_pcap_pkthdr = new PcapUnmanagedStructures.pcap_pkthdr();
 }
예제 #9
0
파일: PcapHeader.cs 프로젝트: uvbs/NScanner
 /// <summary>
 /// Constructs a new PcapHeader
 /// </summary>
 /// <param name="m_pcap_pkthdr">The underlying pcap_pkthdr structure</param>
 internal PcapHeader(PcapUnmanagedStructures.pcap_pkthdr m_pcap_pkthdr)
 {
     this.m_pcap_pkthdr = m_pcap_pkthdr;
 }
예제 #10
0
파일: PcapHeader.cs 프로젝트: uvbs/NScanner
 /// <summary>
 /// Constructs a new PcapHeader
 /// </summary>
 public PcapHeader()
 {
     m_pcap_pkthdr = new PcapUnmanagedStructures.pcap_pkthdr();
 }