Advertisement
bueddl

Untitled

Apr 27th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1.  43     void ip_packet::checksum(void *packet)
  2.  44     {
  3.  45         struct ip *ip_hdr = (struct ip*) packet;
  4.  46
  5.  47         uint16_t checksum = 0;
  6.  48         uint16_t *buffer;
  7.  49         for (int i = 0; i < ip_hdr->ip_len * 2; i++) {
  8.  50             buffer = (uint16_t*) ((char*) packet + i * sizeof (*buffer));
  9.  51             checksum += *buffer & 0xFFFF;
  10.  52         }
  11.  53         ip_hdr->ip_sum = checksum;
  12.  54     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement