+ /**
+ * Gets the ICMP sequence number of the current ICMP object instance
+ *
+ * @return short - seqNumber
+ */
+
+ public short getSequenceNumber() {
+ return BitBufferHelper.getShort(fieldValues.get(SEQNUMBER));
+ }
+
+ /**
+ * Gets the header size in bits
+ * @return The ICMP header size in bits
+ */
+ @Override
+ public int getHeaderSize() {
+ return 64;
+ }
+
+ /**
+ * Computes the ICMP checksum on the serialized ICMP message
+ *
+ * @param serialized
+ * The data stream
+ * @param start
+ * The byte index on the data stream from which the ICMP packet
+ * starts
+ * @return The checksum
+ */
+ short computeChecksum(byte[] data, int start) {
+ int sum = 0, carry = 0, finalSum = 0;
+ int wordData;
+ int end = start + this.getHeaderSize() / NetUtils.NumBitsInAByte;
+ if (rawPayload != null) {
+ end += rawPayload.length;
+ }
+ int checksumStartByte = start + getfieldOffset(CHECKSUM) / NetUtils.NumBitsInAByte;
+ int even = end & ~1;
+
+ for (int i = start; i < even; i = i + 2) {
+ // Skip, if the current bytes are checkSum bytes
+ if (i == checksumStartByte) {
+ continue;
+ }
+ wordData = ((data[i] << 8) & 0xFF00) + (data[i + 1] & 0xFF);
+ sum = sum + wordData;
+ }
+ if (even < end) {
+ // Add the last octet with zero padding.
+ wordData = (data[even] << 8) & 0xFF00;
+ sum = sum + wordData;
+ }
+
+ carry = sum >>> 16;
+ finalSum = (sum & 0xFFFF) + carry;
+ return (short) ~((short) finalSum & 0xFFFF);
+ }
+