public static void Set(
            ref UDPHeader header,
            IPv4Address sourceAddress,
            ushort sourcePort,
            IPv4Address desAddress,
            ushort desPort,
            Span <byte> headerAndData)
        {
            header = new UDPHeader();

            header._SourcePort = Meth.AsBigEndian(sourcePort);

            header._DesPort = Meth.AsBigEndian(desPort);

            header._Length = Meth.AsBigEndian((ushort)headerAndData.Length);

            var per = new PseudoHeader(
                sourceAddress,
                desAddress,
                Protocol.UDP,
                (ushort)headerAndData.Length);


            header._Sum = Meth.AsBigEndian(Meth.CalculationHeaderChecksum(per, headerAndData));
        }
示例#2
0
        public static ushort CalculationHeaderChecksum(PseudoHeader pseudoHeader, Span <byte> buffer)
        {
            uint sum = AddStructSum(ref pseudoHeader);

            sum += AddSpanBytesSum(buffer);

            return(AsSum(sum));
        }
示例#3
0
        public static void Set(
            ref TCPHeader header,
            IPv4Address sourceAddress,
            ushort sourcePort,
            IPv4Address desAddress,
            ushort desPort,
            TCPFlag tcpFlag,
            ushort windowSize,
            uint sequenceNumber,
            uint acknowledgmentNumber,
            Span <byte> headerAndData)
        {
            header = new TCPHeader();

            header._SourcePort = Meth.AsBigEndian(sourcePort);

            header._DesPort = Meth.AsBigEndian(desPort);

            header._SequenceNumber = Meth.AsBigEndian(sequenceNumber);

            header._AcknowledgmentNumber = Meth.AsBigEndian(acknowledgmentNumber);

            header._WindowSize = Meth.AsBigEndian(windowSize);

            header._TCPHeader12_14._Byte_0 = (byte)(5 << 4);

            header._TCPHeader12_14._Byte_1 = (byte)tcpFlag;

            var ph = new PseudoHeader(
                sourceAddress,
                desAddress,
                Protocol.TCP,
                (ushort)headerAndData.Length);

            header._Checksum = Meth.AsBigEndian(Meth.CalculationHeaderChecksum(ph, headerAndData));
        }