class TCP extends BasePacket {

	private static short checksum(byte[] message, int length, int offset) {
		// Sum consecutive 16-bit words.

		int sum = 0;

		while (offset < length - 1) {

			sum += (int) integralFromBytes(message, offset, 2);

			offset += 2;
		}

		if (offset == length - 1) {

			sum += (message[offset] >= 0 ? message[offset]
					: message[offset] ^ 0xffffff00) << 8;
		}

		// Add upper 16 bits to lower 16 bits.

		sum = (sum >>> 16) + (sum & 0xffff);

		// Add carry

		sum += sum >>> 16;

		// Ones complement and truncate.

		return (short) ~sum;
	}

}