private static ushort CalculateTransportChecksum(byte[] buffer, int offset, int headerLength, ushort transportLength, int transportChecksumOffset, bool isChecksumOptional, IpV4Address destination) { int offset1 = offset + headerLength + transportChecksumOffset + 2; ushort num = DataSegment.Sum16BitsToChecksum(DataSegment.Sum16Bits(buffer, offset + 12, 4) + DataSegment.Sum16Bits(destination) + (uint)buffer[offset + 9] + (uint)transportLength + DataSegment.Sum16Bits(buffer, offset + headerLength, transportChecksumOffset) + DataSegment.Sum16Bits(buffer, offset1, (int)transportLength - transportChecksumOffset - 2)); if ((int)num == 0 && isChecksumOptional) { return(ushort.MaxValue); } return(num); }
private static void WriteChecksum(byte[] buffer, int offset, int length) { ByteArrayExtensions.Write(buffer, offset + 2, DataSegment.Sum16BitsToChecksum(DataSegment.Sum16Bits(buffer, offset, length)), Endianity.Big); }
private ushort CalculateChecksum() { return(DataSegment.Sum16BitsToChecksum(DataSegment.Sum16Bits(this.Buffer, this.StartOffset, Math.Min(2, this.Length)) + DataSegment.Sum16Bits(this.Buffer, this.StartOffset + 2 + 2, this.Length - 2 - 2))); }
private static ushort CalculateChecksum(byte[] buffer, int offset, int length) { return(DataSegment.Sum16BitsToChecksum(DataSegment.Sum16Bits(buffer, offset, Math.Min(2, length)) + DataSegment.Sum16Bits(buffer, offset + 2 + 2, length - 2 - 2))); }
private ushort CalculateHeaderChecksum() { return(DataSegment.Sum16BitsToChecksum(DataSegment.Sum16Bits(this.Buffer, this.StartOffset, Math.Min(10, this.Length)) + DataSegment.Sum16Bits(this.Buffer, this.StartOffset + 10 + 2, this.RealHeaderLength - 10 - 2))); }
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); }