Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - NeX

Pages: [1]
1
C - C++ / [C, REQ] Netfilter re-calculating checksum [SOLVED!]
« on: June 27, 2012, 12:30:55 am »
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:
Code: [Select]

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:
Code: C
  1.  
  2.    ip_send_check(ip_header);
  3.      ip_header->check = csum((unsigned short *)ip_header, ip_header->ihl * 4);
  4.  
And this makes bad checksum (checked it with Wireshark)

Pages: [1]


Intern0t SoldierX py1337 SecurityOverride programisiai iExploit
Want to be here? Contact Ande, Bluechill or Kulverstukas on the forum or at IRC.