private int calculateChecksum ( ) { long sum = 0 ; for ( int i = 0 ; i < this . headers . capacity ( ) - 1 ; i += 2 ) { if ( i != 10 ) { sum += this . headers . getUnsignedShort ( i ) ; } } while ( sum >> 16 != 0 ) { sum = ( sum & 0xffff ) + ( sum >> 16 ) ; } return ( int ) ~ sum & 0xFFFF ; }
Algorithm adopted from RFC 1071 - Computing the Internet Checksum