示例#1
0
        public override void CalculateCheckSum(byte[] srcIP, byte[] dstIP)
        {
            int pHeaderLen = (12) + HeaderLength + data.Length;

            if ((pHeaderLen & 1) != 0)
            {
                pHeaderLen += 1;
            }
            byte[] headerSegment = new byte[pHeaderLen];
            byte[] nullBytes     = new byte[2];

            Utils.memcpy(ref headerSegment, 0, srcIP, 0, 4);
            Utils.memcpy(ref headerSegment, 4, dstIP, 0, 4);
            //[8] = 0
            headerSegment[9] = 0x11;
            Utils.memcpy(ref headerSegment, 10, BitConverter.GetBytes(NO_Length), 0, 2);
            //Pseudo Header added

            //Rest of data is normal neader+data
            Utils.memcpy(ref headerSegment, 12, BitConverter.GetBytes(NO_srcPort), 0, 2);
            Utils.memcpy(ref headerSegment, 14, BitConverter.GetBytes(NO_dstPort), 0, 2);
            Utils.memcpy(ref headerSegment, 16, BitConverter.GetBytes(NO_Length), 0, 2);
            Utils.memcpy(ref headerSegment, 18, nullBytes, 0, 2); //zero out csum

            Utils.memcpy(ref headerSegment, 20, data, 0, data.Length);

            Checksum = IPPacket.InternetChecksum(headerSegment); //For performance, we can set this to = zero
            Console.Error.WriteLine();
        }
示例#2
0
        public override bool VerifyCheckSum(byte[] srcIP, byte[] dstIP)
        {
            int pHeaderLen = (12) + HeaderLength + data.Length;

            if ((pHeaderLen & 1) != 0)
            {
                //Console.Error.WriteLine("OddSizedPacket");
                pHeaderLen += 1;
            }

            byte[] headerSegment = new byte[pHeaderLen];

            Utils.memcpy(ref headerSegment, 0, srcIP, 0, 4);
            Utils.memcpy(ref headerSegment, 4, dstIP, 0, 4);
            //[8] = 0
            headerSegment[9] = 0x11;
            Utils.memcpy(ref headerSegment, 10, BitConverter.GetBytes(NO_Length), 0, 2);
            //Pseudo Header added

            //Rest of data is normal neader+data
            Utils.memcpy(ref headerSegment, 12, BitConverter.GetBytes(NO_srcPort), 0, 2);
            Utils.memcpy(ref headerSegment, 14, BitConverter.GetBytes(NO_dstPort), 0, 2);
            Utils.memcpy(ref headerSegment, 16, BitConverter.GetBytes(NO_Length), 0, 2);
            Utils.memcpy(ref headerSegment, 18, BitConverter.GetBytes(NO_csum), 0, 2);

            Utils.memcpy(ref headerSegment, 20, data, 0, data.Length);

            UInt16 CsumCal = IPPacket.InternetChecksum(headerSegment);

            //Console.Error.WriteLine("UDP Checksum Good = " + (CsumCal == 0));
            return(CsumCal == 0);
        }
示例#3
0
        public override bool VerifyCheckSum(byte[] srcIP, byte[] dstIP)
        {
            int pHeaderLen = ((Length));

            if ((pHeaderLen & 1) != 0)
            {
                //Console.Error.WriteLine("OddSizedPacket");
                pHeaderLen += 1;
            }

            byte[] headerSegment = new byte[pHeaderLen];
            Utils.memcpy(ref headerSegment, 0, GetBytes(), 0, Length);

            UInt16 CsumCal = IPPacket.InternetChecksum(headerSegment);

            //Console.Error.WriteLine("IMCP Checksum Good = " + (CsumCal == 0));
            return(CsumCal == 0);
        }
示例#4
0
        public override void CalculateCheckSum(byte[] srcIP, byte[] dstIP)
        {
            int pHeaderLen = ((Length));

            if ((pHeaderLen & 1) != 0)
            {
                //Console.Error.WriteLine("OddSizedPacket");
                pHeaderLen += 1;
            }

            byte[] headerSegment = new byte[pHeaderLen];
            Utils.memcpy(ref headerSegment, 0, GetBytes(), 0, Length);

            byte[] nullcsum = new byte[2];
            Utils.memcpy(ref headerSegment, 2, nullcsum, 0, 2);

            Checksum = IPPacket.InternetChecksum(headerSegment);
        }