I didn't know where to put this... I hope it's in the right section..
Anyway, my issue is:
I'm working on a project where I need to change the destination IP address.. But when I do, I also need to re-calculate the checksum of the IP header.
Does anyone know a sufficient and a working way to do this? I'm using a function to calculate the checksum which I found it on the internet.
And, yes, I'm doing this in kernel space (kernel module)..
The function:
unsigned short csum(unsigned short *buf, int nwords){
unsigned long sum;
for(sum=0; nwords>0; nwords--)
sum += *buf++;
sum = (sum >> 16) + (sum &0xffff);
sum += (sum >> 16);
return ~sum;
}
How I calculate the checksum of the IP header:
ip_send_check(ip_header);
ip_header->check = csum((unsigned short *)ip_header, ip_header->ihl * 4);
And this makes bad checksum (checked it with Wireshark)