Exemplo n.º 1
0
        /*
         * Function: Rearrange
         * Description: Rearrange the buffer data into a temporary holding buffer to prepare for parsing
         */
        public byte Rearrange(CircularFrameBuffer cfb, bool skip = false)
        {
            //lock (cfb.PeekData)
            {
                IHL = (byte)((cfb.PeekData.Tdata1 >> 48) & 0x0f);

                data_0  = cfb.PeekData.Tdata1 >> 48;
                data_0 |= cfb.PeekData.Tdata2 << 16;
                data_1  = cfb.PeekData.Tdata2 >> 48;
                data_1 |= cfb.PeekData.Tdata3 << 16;
                data_2  = cfb.PeekData.Tdata3 >> 48;


                if (!cfb.CanAdvance())
                {
                    return(2);
                }

                cfb.AdvancePeek();


                if (IHL == 5)
                {
                    data_2 |= (cfb.PeekData.Tdata0 & 0xffff) << 16;
                }
                else
                {
                    data_2 |= cfb.PeekData.Tdata0 << 16;
                    if (IHL == 7)
                    {
                        data_3  = cfb.PeekData.Tdata0 >> 48;
                        data_3 |= (cfb.PeekData.Tdata1 & 0xffff) << 16;
                    }
                    else if (IHL == 8)
                    {
                        data_3  = cfb.PeekData.Tdata0 >> 48;
                        data_3 |= cfb.PeekData.Tdata1 << 16;
                    }
                }
            }

            return(0);
        }
Exemplo n.º 2
0
        /*
         * Function: WriteHeader
         * Description: Write the temporary buffer back into the main buffer.
         */
        public void WriteHeader(CircularFrameBuffer cfb, bool push, bool assembled = false)
        {
            if (!assembled)
            {
                AssembleHeader();
            }

            cfb.RewindPeek();
            //lock (cfb.PeekData)
            {
                cfb.PeekData.Tdata1 = (cfb.PeekData.Tdata1 & 0x0000ffffffffffff) | (data_0 << 48);
                cfb.PeekData.Tdata2 = (data_0 >> 16) | (data_1 << 48);
                cfb.PeekData.Tdata3 = (data_1 >> 16) | (data_2 << 48);

                cfb.UpdatePeek(cfb.PeekData);

                if (!push)
                {
                    cfb.AdvancePeek();
                }

                if (IHL == 5)
                {
                    cfb.PeekData.Tdata0 = (cfb.PeekData.Tdata0 & 0xffffffffffff0000) | (data_2 >> 16);
                }
                else if (IHL == 6)
                {
                    cfb.PeekData.Tdata0 = (cfb.PeekData.Tdata0 & 0xffff000000000000) | (data_2 >> 16);
                }
                else if (IHL == 7)
                {
                    cfb.PeekData.Tdata0 = (data_2 >> 16) | (data_3 << 48);
                    cfb.PeekData.Tdata1 = (cfb.PeekData.Tdata1 & 0xffffffffffff0000) | (data_3 >> 16);
                }
                else if (IHL == 8)
                {
                    cfb.PeekData.Tdata0 = (data_2 >> 16) | (data_3 << 48);
                    cfb.PeekData.Tdata1 = (cfb.PeekData.Tdata1 & 0xffff000000000000) | (data_3 >> 16);
                }
            }
        }
Exemplo n.º 3
0
        /*
         * Function: Parse
         * Description: Parse peeked data from buffer
         */
        public byte Parse(CircularFrameBuffer cfb, bool skip = false)
        {
            if (!skip)
            //lock (cfb.PeekData)
            {
                Version      = (byte)((cfb.PeekData.Tdata1 >> 52) & 0x0f);
                TrafficClass =
                    (byte)(((cfb.PeekData.Tdata1 >> 48) & 0x0f) | (((cfb.PeekData.Tdata1 >> 56) & 0x0f) << 4));

                PayloadLength = (uint)((cfb.PeekData.Tdata2 >> 16) & 0x00ffff);
                Protocol      = (byte)((cfb.PeekData.Tdata2 >> 32) & 0x00ff);
                HopLimit      = (byte)((cfb.PeekData.Tdata2 >> 40) & 0x00ff);

                SrcIp1        = (cfb.PeekData.Tdata2 >> 48) & 0x00ffff;
                SrcIp1       |= (cfb.PeekData.Tdata3 & 0x00ffffffffffff) << 16;
                _tmp_src_ip_2 = (cfb.PeekData.Tdata3 >> 48) & 0x00ffff;
            }

            if (!cfb.CanAdvance())
            {
                return(2);
            }

            cfb.AdvancePeek();

            //lock (cfb.PeekData)
            {
                SrcIp2   = _tmp_src_ip_2 | ((cfb.PeekData.Tdata0 & 0x00ffffffffffff) << 16);
                DestIp1  = (cfb.PeekData.Tdata0 >> 48) & 0x00ffff;
                DestIp1 |= (cfb.PeekData.Tdata1 & 0x00ffffffffffff) << 16;
                DestIp2  = (cfb.PeekData.Tdata1 >> 48) & 0x00ffff;
                DestIp2 |= (cfb.PeekData.Tdata2 & 0x00ffffffffffff) << 16;
            }

            return(0);
        }
Exemplo n.º 4
0
        /*
         * Function: ParseSplit
         * Description: A two-part parser to allow the first section of the packet to be parsed.
         */
        public byte ParseSplit(CircularFrameBuffer cfb, bool skip = false)
        {
            //lock (cfb.PeekData)
            {
                if (!skip)
                {
                    data_0  = cfb.PeekData.Tdata1 >> 48;
                    data_0 |= cfb.PeekData.Tdata2 << 16;
                    data_1  = cfb.PeekData.Tdata2 >> 48;
                    data_1 |= cfb.PeekData.Tdata3 << 16;
                    data_2  = cfb.PeekData.Tdata3 >> 48;

                    Version = (byte)((cfb.PeekData.Tdata1 >> 52) & 0x0f);
                    if (Version != 4)
                    {
                        DebugFunctions.push_interrupt(DebugFunctions.Errors.ILLEGAL_PACKET_FORMAT);
                    }
                    IHL = (byte)((cfb.PeekData.Tdata1 >> 48) & 0x0f);
                    if (IHL < 5 || IHL > 8)
                    {
                        DebugFunctions.push_interrupt(DebugFunctions.Errors.ILLEGAL_PACKET_FORMAT);
                    }
                    DSCP           = (byte)((cfb.PeekData.Tdata1 >> 58) & 0x3F);
                    ECN            = (byte)((cfb.PeekData.Tdata1 >> 56) & 0x3);
                    TotalLength    = (uint)(cfb.PeekData.Tdata2 & 0x00ffff);
                    Identification = (uint)((cfb.PeekData.Tdata2 >> 16) & 0x00ffff);
                    Flags          = (byte)((cfb.PeekData.Tdata2 >> 37) & 0x07);
                    FragmentOffset = (uint)((((cfb.PeekData.Tdata2 >> 32) & 0x01f) << 8) |
                                            ((cfb.PeekData.Tdata2 >> 40) & 0x0ff));
                    TTL            = (byte)((cfb.PeekData.Tdata2 >> 48) & 0x00ff);
                    Protocol       = (byte)((cfb.PeekData.Tdata2 >> 56) & 0x00ff);
                    HeaderChecksum = (uint)cfb.PeekData.Tdata3 & 0x00ffff;
                    SrcIp          = (cfb.PeekData.Tdata3 >> 16) & 0x00ffffffff;
                    _tmp_dest_ip   = (cfb.PeekData.Tdata3 >> 48) & 0x00ffff;
                }


                if (!cfb.CanAdvance())
                {
                    return(2);
                }

                cfb.AdvancePeek();

                if (IHL == 5)
                {
                    data_2 |= (cfb.PeekData.Tdata0 & 0xffff) << 16;
                }
                else if (IHL == 6)
                {
                    data_2 |= cfb.PeekData.Tdata0 << 16;
                    if (IHL == 7)
                    {
                        data_3  = cfb.PeekData.Tdata0 >> 48;
                        data_3 |= (cfb.PeekData.Tdata1 & 0xffff) << 16;
                    }
                    else if (IHL == 8)
                    {
                        data_3  = cfb.PeekData.Tdata0 >> 48;
                        data_3 |= cfb.PeekData.Tdata1 << 16;
                    }
                }

                DestIp = _tmp_dest_ip | ((cfb.PeekData.Tdata0 & 0x00ffff) << 16);
            }

            return(0);
        }