diff --git a/src/protocolP2P/ProtocolP2PDatagram.java b/src/protocolP2P/ProtocolP2PDatagram.java index 079c0fd..cf2a02d 100644 --- a/src/protocolP2P/ProtocolP2PDatagram.java +++ b/src/protocolP2P/ProtocolP2PDatagram.java @@ -243,15 +243,33 @@ public class ProtocolP2PDatagram { this.hostR = hostR; } + /** Used to compute Checksum of a specific datagram + * @param datagram full datagram + * @return checksum + * @throws SizeError + */ + private int computeCheckSum(byte [] datagram) throws SizeError { + /* + * The checksum field is the 16 bit one’s complement of the one’s complement sum of all 16-bit words + * in the header and text. If a segment contains an odd number of header and text octets to be checksummed, + * the last octet is padded on the right with zeros to form a 16-bit word for checksum purposes. + * The pad is not transmitted as part of the segment. While computing the checksum, the checksum field + * itself is replaced with zeros. + */ int checksum = 0; - for (int i=CHECKSUM_POSITION+2; i