in_cksum() for ip packets with multiple mbufs

kamal kc kamal_ckk at yahoo.com
Sun Oct 23 04:13:34 PDT 2005


> > i changed the ip_tos field of the struct ip and
> computed the checksum
> > by using in_cksum().
> >
> > when the packet uses only one mbuf the computed
> checksum is ok but
> > when the packet uses more than one mbuf then the
> computed checksum is
> > wrong.
> 
> Note that the IP header contains a checksum of the
> IP header only.
> 
> A common mistake is to calculate the checksum of
> data too, which results
> in an invalid IP header checksum.

ok i made this mistake to calculate the checksum
over the entire IP payload.

i corrected this and used the ip_hl field :::
   
/* the argument m is the (struct mbuf *) that 
 * contains the packet data
 */

void copy_the_memorybuffer(struct mbuf **m)
{  
   struct mbuf *mbuf_pointer=*m;
   struct mbuf **next_packet;
    
   next_packet=&mbuf_pointer;

   struct ip *my_ip_hdr;
   my_ip_hdr=mtod((*next_packet),struct ip *);
   my_ip_hdr->ip_tos=64;
   my_ip_hdr->ip_sum=0;
  
   my_ip_hdr->ip_sum=
       in_cksum((*next_packet),(my_ip_hdr->ip_hl<<2));
  .......
} 

but still it doesn't seem to work. and the problem
is still there.

i am really confused ..
 
> > eg. pinging with payload less than 1470 bytes is
> ok but with payload
> > greater than 1480 bytes does not work. (the error
> being bad checksum
> > --that i knew by capturing network packets by
> ethereal)
> >
> > is it a real problem or i have made some mistake.
> >
> > i put the code before the if_output() in the
> ip_output() function.
> 
> Show us the diff, if possible :)

sorry i did not understand what to show here.
does it mean to show the packet data captured by 
the ethereal..

thanks kamal



		
__________________________________ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com


More information about the freebsd-hackers mailing list