this.windowSize = skbuf.get16(14);
final int checksum = skbuf.get16(16);
this.urgentPointer = skbuf.get16(18);
final IPv4Header ipHdr = (IPv4Header) skbuf.getNetworkLayerHeader();
this.tcpLength = ipHdr.getDataLength() - headerLength;
if (checksum == 0) {
log.debug("No checksum set");
this.checksumOk = true;
} else {
// Create the pseudo header for checksum calculation
final SocketBuffer phdr = new SocketBuffer(12);
phdr.insert(12);
ipHdr.getSource().writeTo(phdr, 0);
ipHdr.getDestination().writeTo(phdr, 4);
phdr.set(8, 0);
phdr.set(9, ipHdr.getProtocol());
phdr.set16(10, tcpLength + headerLength);
phdr.append(skbuf);
final int ccs2 = IPv4Utils.calcChecksum(phdr, 0, headerLength + tcpLength + 12);
this.checksumOk = (ccs2 == 0);
if (!checksumOk) {
log.debug("Found invalid TCP checksum 0x" + NumberUtils.hex(ccs2, 4) +
", tcpLength 0x" + NumberUtils.hex(tcpLength, 4) + ", ipDataLength 0x" +
NumberUtils.hex(ipHdr.getDataLength(), 4) + ", tcpHdrLen 0x" +
NumberUtils.hex(headerLength, 4));
}
}
}