コード例 #1
0
ファイル: IpV4Datagram.cs プロジェクト: wayneYaw/sonarlint-vs
        internal static void WriteHeader(byte[] buffer, int offset,
                                         byte typeOfService, ushort identification,
                                         IpV4Fragmentation fragmentation,
                                         byte ttl, IpV4Protocol protocol, ushort?headerChecksum,
                                         IpV4Address source, IpV4Address destination,
                                         IpV4Options options, int payloadLength)
        {
            int headerLength = HeaderMinimumLength + options.BytesLength;

            buffer[offset + Offset.VersionAndHeaderLength] = (byte)((DefaultVersion << 4) + headerLength / 4);
            buffer[offset + Offset.TypeOfService]          = typeOfService;
            buffer.Write(offset + Offset.TotalLength, (ushort)(headerLength + payloadLength), Endianity.Big);
            buffer.Write(offset + Offset.Identification, identification, Endianity.Big);
            fragmentation.Write(buffer, offset + Offset.Fragmentation);
            buffer[offset + Offset.Ttl]      = ttl;
            buffer[offset + Offset.Protocol] = (byte)protocol;

            buffer.Write(offset + Offset.Source, source, Endianity.Big);
            buffer.Write(offset + Offset.Destination, destination, Endianity.Big);
            options.Write(buffer, offset + Offset.Options);

            ushort headerChecksumValue =
                headerChecksum == null
                    ? Sum16BitsToChecksum(Sum16Bits(buffer, offset, headerLength))
                    : headerChecksum.Value;

            buffer.Write(offset + Offset.HeaderChecksum, headerChecksumValue, Endianity.Big);
        }
コード例 #2
0
        internal static void WriteHeader(byte[] buffer, int offset, byte typeOfService, ushort identification, IpV4Fragmentation fragmentation, byte ttl, IpV4Protocol protocol, ushort?headerChecksum, IpV4Address source, IpV4Address destination, IpV4Options options, int payloadLength)
        {
            int length = 20 + options.BytesLength;

            buffer[offset]     = (byte)(64 + length / 4);
            buffer[offset + 1] = typeOfService;
            ByteArrayExtensions.Write(buffer, offset + 2, (ushort)(length + payloadLength), Endianity.Big);
            ByteArrayExtensions.Write(buffer, offset + 4, identification, Endianity.Big);
            fragmentation.Write(buffer, offset + 6);
            buffer[offset + 8] = ttl;
            buffer[offset + 9] = (byte)protocol;
            ByteArrayExtensions.Write(buffer, offset + 12, source, Endianity.Big);
            ByteArrayExtensions.Write(buffer, offset + 16, destination, Endianity.Big);
            options.Write(buffer, offset + 20);
            ushort?nullable = headerChecksum;
            ushort num      = !(nullable.HasValue ? new int?((int)nullable.GetValueOrDefault()) : new int?()).HasValue ? DataSegment.Sum16BitsToChecksum(DataSegment.Sum16Bits(buffer, offset, length)) : headerChecksum.Value;

            ByteArrayExtensions.Write(buffer, offset + 10, num, Endianity.Big);
        }