Exemple #1
0
        public static List <byte> IPDataEncode(IPPacket ip)
        {
            List <byte> ret = ip.ToArray();

            ret.Insert(0, 0x21);
            ret.Insert(0, 0x00);
            ret.Insert(0, 0x03);
            ret.Insert(0, 0xff);
            return(PPPDataEncode(ret, true));
        }
Exemple #2
0
        public static IPPacket MakeIPPacket(List <byte> RxList, int start)
        {
            IPPacket ip = new IPPacket();

            ip.Version        = BytesOP.GetHighNibble(RxList[start]);
            ip.HeaderLength   = BytesOP.GetLowNibble(RxList[start]);
            ip.TypeOfService  = RxList[start + 1];
            ip.TotalLength    = BytesOP.MakeShort(RxList[start + 2], RxList[start + 3]);
            ip.Identification = BytesOP.MakeShort(RxList[start + 4], RxList[start + 5]);
            ip.Flags          = (byte)(RxList[start + 6] >> 5);
            ip.FragmentOffset = (ushort)(RxList[start + 6] & 0x1f + RxList[start + 7]);
            ip.TimeToLive     = RxList[start + 8];
            ip.Protocol       = RxList[start + 9];
            ip.HeaderVerify   = BytesOP.MakeShort(RxList[start + 10], RxList[start + 11]);
            for (int i = 0; i < 4; i++)
            {
                ip.SourceAddress[i]      = RxList[12 + start + i];
                ip.DastinationAddress[i] = RxList[16 + start + i];
            }
            int DataStart = 20;

            if (ip.HeaderLength > 5)
            {
                ip.Options = new List <byte>();
                for (int i = 0; i < ((ip.HeaderLength - 5) * 4); i++)
                {
                    ip.Options.Add(RxList[22 + i]);
                }
                DataStart += ((ip.HeaderLength - 5) * 4);
            }
            switch (ip.Protocol)
            {
            case 0x06:    //tcp
                ip.oProtocolContent = new TCPPacket();
                TCPPacket tcp = (TCPPacket)ip.oProtocolContent;
                tcp.SourcePort       = BytesOP.MakeShort(RxList[start + DataStart], RxList[start + DataStart + 1]);
                tcp.DastinationPort  = BytesOP.MakeShort(RxList[start + DataStart + 2], RxList[start + DataStart + 3]);
                tcp.InitialSeqNumber = BytesOP.MakeInt(RxList[start + DataStart + 4],
                                                       RxList[start + DataStart + 5],
                                                       RxList[start + DataStart + 6],
                                                       RxList[start + DataStart + 7]);
                tcp.AckSeqNumber = BytesOP.MakeInt(RxList[start + DataStart + 8],
                                                   RxList[start + DataStart + 9],
                                                   RxList[start + DataStart + 10],
                                                   RxList[start + DataStart + 11]);
                tcp.DataOffset  = BytesOP.GetHighNibble(RxList[start + DataStart + 12]);
                tcp.TCPFlags    = (byte)(RxList[start + DataStart + 13] & 0x3f);
                tcp.Window      = BytesOP.MakeShort(RxList[start + DataStart + 14], RxList[start + DataStart + 15]);
                tcp.CheckSum    = BytesOP.MakeShort(RxList[start + DataStart + 16], RxList[start + DataStart + 17]);
                tcp.UrgentPoint = BytesOP.MakeShort(RxList[start + DataStart + 18], RxList[start + DataStart + 19]);
                if (tcp.DataOffset > 5)
                {
                    tcp.TCPOptions = new List <byte>();
                    for (int i = 0; i < ((tcp.DataOffset - 5) * 4); i++)
                    {
                        tcp.TCPOptions.Add(RxList[start + DataStart + 20 + i]);
                    }
                }
                int count = ip.TotalLength - ip.HeaderLength * 4 - tcp.DataOffset * 4;
                tcp.Datas = new List <byte>();
                for (int i = 0; i < count; i++)
                {
                    tcp.Datas.Add(RxList[start + DataStart + tcp.DataOffset * 4 + i]);
                }
                break;
            }
            return(ip);
        }