1. in IPPacket:
method protected int onesCompSum(byte[] bytes, int
start, int len)
The method mising the one-compilent on the checksum
sum = ~sum & 0xffff ;
currenlty returning the wrong check sum.
c code from stevens:
unsigned short ip_cksum(unsigned short *addr,int len)
{
int nleft = len;
int sum = 0;
unsigned short *w = addr;
unsigned short answer = 0;
while (nleft>1)
{
sum+=*w++;
nleft-=2;
}
if (nleft == 1 )
{
*(unsigned char *) (&answer) = *(unsigned
char *) w;
sum += answer;
}
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
answer = ~sum;
return(answer);
}
2.the checksum can be any 16 bit number and not just
0xffff as in method
/**
* Check if the IP packet is valid, checksum-wise.
*/
public boolean isValidChecksum()
Logged In: NO
my email ronybary@yahoo.com
Logged In: YES
user_id=1262793
Originator: NO
The problem is twofold.
1. The ipChecksum() method only computes the ones-complement sum, whereas the method in Stevens computes the ones-complement of the ones-complement sum.
2. The result in either case is 16 bits with no sign extension. The Stevens result should be compared to 0; the ipChecksum() result should be complemented and compared to zero, but in fact it is compared to -1 in 32 bits, i.e. 0xffffffff, which can never succeed, as the upper 16 bits can never be set.
NB the Stevens method has a bug too! The final odd byte if any should be left-shifted 8 before addition.
Logged In: YES
user_id=1262793
Originator: NO
This has been addressed in the forthcoming release 2.0.