public void GreIPv4Parsing()
        {
            var dev = new CaptureFileReaderDevice(NUnitSetupClass.CaptureDirectory + "gre_all_options.pcap");

            dev.Open();
            var rawCapture = dev.GetNextPacket();

            dev.Close();

            LinkLayers linkLayers = rawCapture.GetLinkLayers();

            if (linkLayers == LinkLayers.Ethernet)
            {
                Console.WriteLine("Linklayer is ethernet");
                // Linklayer
                Packet p = Packet.ParsePacket(linkLayers, rawCapture.Data);
                Assert.IsNotNull(p);

                // Ethernet
                EthernetPacket eth = p.Extract <EthernetPacket>();
                Assert.IsNotNull(eth);
                if (eth.Type == EthernetType.IPv4)
                {
                    Console.WriteLine("IPv4 inside ethernet");
                    // IPv4
                    IPv4Packet ipv4 = eth.Extract <IPv4Packet>();
                    Assert.IsNotNull(ipv4);
                    if (ipv4.Protocol == ProtocolType.Gre)
                    {
                        Console.WriteLine("GRE inside IPv4");
                        // Gre
                        GrePacket grep = ipv4.Extract <GrePacket>();
                        Assert.IsNotNull(grep);

                        // String output
                        Console.WriteLine(grep.ToString());

                        // Get header
                        if (grep.HasCheckSum)
                        {
                            Console.WriteLine("GRE has checksum flag");
                        }
                        if (grep.HasKey)
                        {
                            Console.WriteLine("GRE has key flag");
                        }
                        if (grep.HasReserved)
                        {
                            Console.WriteLine("GRE has reserved flag");
                        }
                        if (grep.HasSequence)
                        {
                            Console.WriteLine("GRE has sequence flag");
                        }

                        Assert.AreEqual(grep.Protocol, EthernetType.IPv4);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// BEAWARE Runns in parallel
        /// </summary>
        /// <param name="pmFrame"></param>
        /// <param name="parentPacket"></param>
        /// <returns></returns>
        public async Task CreateAndAddToMetaFramesVirtualFrame(PmFrameBase pmFrame, PmPacket parentPacket)
        {
            PmFrameVirtual virtualFrame = null;

            switch (pmFrame.IpProtocol)
            {
            case IPProtocolType.GRE:
                var gre = new GrePacket(new ByteArraySegment(pmFrame.L4Data()));
                virtualFrame = new PmFrameVirtual(pmFrame.PmCapture, pmFrame.FrameIndex, pmFrame.TimeStamp, pmFrame.IncludedLength, (pmFrame.L4Offset + gre.Header.Length));
                break;

            case IPProtocolType.IPV6:
                virtualFrame = new PmFrameVirtual(pmFrame.PmCapture, pmFrame.FrameIndex, pmFrame.TimeStamp, pmFrame.IncludedLength, (pmFrame.L4Offset));
                break;

            case IPProtocolType.UDP:
                var udp = new UdpPacket(new ByteArraySegment(pmFrame.L4Data()));
                //Port 3544 is used to communicate with Teredo Server. We need communication between host and Teredo Relay (temporarily solution)
                if (udp.DestinationPort == 3544 || udp.SourcePort == 3544)
                {
                    break;
                }

                virtualFrame = new PmFrameVirtual(pmFrame.PmCapture, pmFrame.FrameIndex, pmFrame.TimeStamp, pmFrame.IncludedLength,
                                                  (pmFrame.L4Offset + udp.Header.Length));
                break;
            }
            if (virtualFrame != null)
            {
                await this.PmMetaFramesBufferBlock.SendAsync(virtualFrame);
            }
        }