Example #1
0
        public unsafe PacketCommunicatorReceiveResult ReceivePacket(out Packet packet)
        {
            this.AssertMode(PacketCommunicatorMode.Capture);
            pcap_pkthdr *pcapPkthdrPtr1;
            byte *       numPtr;
            PacketCommunicatorReceiveResult communicatorReceiveResult = this.RunPcapNextEx(&pcapPkthdrPtr1, &numPtr);

            if (communicatorReceiveResult != PacketCommunicatorReceiveResult.Ok)
            {
                packet = (Packet)null;
                return(communicatorReceiveResult);
            }
            IDataLink    dataLink           = (IDataLink) new PcapDataLink(\u003CModule\u003E.pcap_datalink(this._pcapDescriptor));
            byte *       unmanagedByteArray = numPtr;
            pcap_pkthdr *pcapPkthdrPtr2     = pcapPkthdrPtr1;
            DateTime     dateTime           = new DateTime();

            PacketTimestamp.PcapTimestampToDateTime((timeval *)pcapPkthdrPtr1, out dateTime);
            int offset = 0;
            int count  = *(int *)((IntPtr)pcapPkthdrPtr2 + 8L);

            byte[] data = MarshalingServices.UnamangedToManagedByteArray(unmanagedByteArray, offset, count);
            packet = new Packet(data, dateTime, dataLink);
            return(PacketCommunicatorReceiveResult.Ok);
        }
Example #2
0
 public static unsafe void GetPcapHeader(pcap_pkthdr *header, Packet packet)
 {
     PacketTimestamp.DateTimeToPcapTimestamp(packet.Timestamp, (timeval *)header);
     *(int *)((IntPtr)header + 12L) = packet.Length;
     *(int *)((IntPtr)header + 8L)  = packet.Length;
 }
Example #3
0
 static PacketTimestamp()
 {
     PacketTimestamp.Initialize();
 }
 internal unsafe PacketSampleStatistics(pcap_pkthdr *packetHeader, byte *packetData)
 {
     PacketTimestamp.PcapTimestampToDateTime((timeval *)packetHeader, out this._timestamp);
     this._acceptedPackets = (uint)*(int *)packetData;
     this._acceptedBytes   = (uint)*(int *)(packetData + 8L);
 }