private void _read()
        {
            _dstMac     = m_io.ReadBytes(6);
            _srcMac     = m_io.ReadBytes(6);
            _etherType1 = ((EtherTypeEnum)m_io.ReadU2be());
            if (EtherType1 == EtherTypeEnum.Ieee8021qTpid)
            {
                _tci = new TagControlInfo(m_io, this, m_root);
            }
            if (EtherType1 == EtherTypeEnum.Ieee8021qTpid)
            {
                _etherType2 = ((EtherTypeEnum)m_io.ReadU2be());
            }
            switch (EtherType)
            {
            case EtherTypeEnum.Ipv4: {
                __raw_body = m_io.ReadBytesFull();
                var io___raw_body = new KaitaiStream(__raw_body);
                _body = new Ipv4Packet(io___raw_body);
                break;
            }

            case EtherTypeEnum.Ipv6: {
                __raw_body = m_io.ReadBytesFull();
                var io___raw_body = new KaitaiStream(__raw_body);
                _body = new Ipv6Packet(io___raw_body);
                break;
            }

            default: {
                _body = m_io.ReadBytesFull();
                break;
            }
            }
        }
示例#2
0
        private void _read()
        {
            _dstMac    = m_io.ReadBytes(6);
            _srcMac    = m_io.ReadBytes(6);
            _etherType = ((EtherTypeEnum)m_io.ReadU2be());
            switch (EtherType)
            {
            case EtherTypeEnum.Ipv4: {
                __raw_body = m_io.ReadBytesFull();
                var io___raw_body = new KaitaiStream(__raw_body);
                _body = new Ipv4Packet(io___raw_body);
                break;
            }

            case EtherTypeEnum.Ipv6: {
                __raw_body = m_io.ReadBytesFull();
                var io___raw_body = new KaitaiStream(__raw_body);
                _body = new Ipv6Packet(io___raw_body);
                break;
            }

            default: {
                _body = m_io.ReadBytesFull();
                break;
            }
            }
        }
示例#3
0
        public void LoadAndParsePacket(string filename)
        {
            var packets = LoadPackets(filename);

            foreach (var packet in packets)
            {
                var         bytes        = packet.Data;
                var         etherType    = EthernetFrame.GetEtherType(bytes);
                var         etherPayload = EthernetFrame.GetPayloadBytes(bytes);
                Span <Byte> ipPayload;
                Span <Byte> sourceAddress;
                Span <Byte> destinAddress;
                switch (etherType)
                {
                case (ushort)EthernetFrame.EtherTypeEnum.Ipv4:
                {
                    sourceAddress = Ipv4Packet.GetSourceAddress(etherPayload);
                    destinAddress = Ipv4Packet.GetDestinationAddress(etherPayload);
                    ipPayload     = Ipv4Packet.GetPayloadBytes(etherPayload);
                    break;
                }

                case (ushort)EthernetFrame.EtherTypeEnum.Ipv6:
                {
                    sourceAddress = Ipv6Packet.GetSourceAddress(etherPayload);
                    destinAddress = Ipv6Packet.GetDestinationAddress(etherPayload);
                    ipPayload     = Ipv6Packet.GetPayloadBytes(etherPayload);
                    break;
                }
                }
            }
        }
示例#4
0
        /// <summary>
        /// Gets the key for Ethernet frame.
        /// </summary>
        /// <param name="frameBytes">Bytes that contains Ethernet frame.</param>
        /// <returns><see cref="FlowKey"/> for the provided Ethernet frame.</returns>
        public static FlowKey GetKeyForEthernetFrame(byte[] frameBytes)
        {
            var etherType    = EthernetFrame.GetEtherType(frameBytes);
            var etherPayload = EthernetFrame.GetPayloadBytes(frameBytes);

            Span <Byte> ipPayload     = stackalloc byte[0];
            var         protocol      = 0;
            Span <Byte> sourceAddress = stackalloc byte[4];
            Span <Byte> destinAddress = stackalloc byte[4];
            UInt16      sourcePort    = 0;
            UInt16      destinPort    = 0;

            switch (etherType)
            {
            case (ushort)EthernetFrame.EtherTypeEnum.Ipv4:
            {
                sourceAddress = Ipv4Packet.GetSourceAddress(etherPayload);
                destinAddress = Ipv4Packet.GetDestinationAddress(etherPayload);
                ipPayload     = Ipv4Packet.GetPayloadBytes(etherPayload);
                protocol      = Ipv4Packet.GetProtocol(etherPayload);
                break;
            }

            case (ushort)EthernetFrame.EtherTypeEnum.Ipv6:
            {
                sourceAddress = Ipv6Packet.GetSourceAddress(etherPayload);
                destinAddress = Ipv6Packet.GetDestinationAddress(etherPayload);
                ipPayload     = Ipv6Packet.GetPayloadBytes(etherPayload);
                protocol      = Ipv6Packet.GetProtocol(etherPayload);
                break;
            }

            default:
                break;
            }
            switch (protocol)
            {
            case 6:      // TCP
            {
                sourcePort = TcpSegment.GetSourcePort(ipPayload);
                destinPort = TcpSegment.GetDestinationPort(ipPayload);
                break;
            }

            case 17:     // UDP
            {
                sourcePort = UdpDatagram.GetSourcePort(ipPayload);
                destinPort = UdpDatagram.GetDestinationPort(ipPayload);
                break;
            }

            default:
                break;
            }
            // ok we have enough information for creating packet's flow key
            return(FlowKey.Create((byte)protocol, sourceAddress, sourcePort, destinAddress, destinPort));
        }
示例#5
0
        private void _read()
        {
            switch (Protocol)
            {
            case ProtocolEnum.Ipv6Nonxt: {
                _body = new NoNextHeader(m_io, this, m_root);
                break;
            }

            case ProtocolEnum.Ipv4: {
                _body = new Ipv4Packet(m_io);
                break;
            }

            case ProtocolEnum.Udp: {
                _body = new UdpDatagram(m_io);
                break;
            }

            case ProtocolEnum.Icmp: {
                _body = new IcmpPacket(m_io);
                break;
            }

            case ProtocolEnum.Hopopt: {
                _body = new OptionHopByHop(m_io, this, m_root);
                break;
            }

            case ProtocolEnum.Ipv6: {
                _body = new Ipv6Packet(m_io);
                break;
            }

            case ProtocolEnum.Tcp: {
                _body = new TcpSegment(m_io);
                break;
            }
            }
        }
示例#6
0
 public Ipv6Packet(KaitaiStream p__io, KaitaiStruct p__parent = null, Ipv6Packet p__root = null) : base(p__io)
 {
     m_parent = p__parent;
     m_root   = p__root ?? this;
     _read();
 }