2008-06-23 21:51:52     problems about "struct iphdr *ip"

Document created by Aaronwu Employee on Aug 6, 2013
Version 1Show Document
  • View in full screen mode

2008-06-23 21:51:52     problems about "struct iphdr *ip"

edward jiang (CHINA)

Message: 57744   



i have a question.it occured when i used the platform BF537 and uclinux kernel version :


In network programs,i declared a varible "struct iphdr *ip",then i used it as "ip->protocol" or "ip->ihl" ,it worked well.but when

i used its member ip->daddr or ip->saddr,my programs panic.strace shows that it is killed by a SIGIO  signal.

(by the way ,my program went very well in linux platform,like redhat.)


i checked through all the uclinux kernel files,but i can not find the definition of "struct iphdr",which is very important for my debugging.

dose anybody know where it is? or dose anybody know what may be the point of my promblem?


thanks a lot for your help.




2008-06-23 23:17:42     Re: problems about "struct iphdr *ip"

Mike Frysinger (UNITED STATES)

Message: 57746   


you can preprocess things with -E and it'll show you where all the structures come from


if you want assistance with code, post the piece that is failing and the full error message




2008-06-24 03:24:59     Re: problems about "struct iphdr *ip"

edward jiang (CHINA)

Message: 57752   



thanks for your advice.i finished a test as follows: firstly,we have got a raw ip packet in varible "buff",&buff[0]

is the beginning of the eth head.accorrding to TCP/IP protocol,we know that &buff[14] is the beginning of our ip head,which is verified by checking our bf537 memory. when we wanted to use the ip head,i used it as the form

   struct ip* ippack;

   ippack=(struct ip*)(buff+14);

so we can refered ip head like ippack->protocol;but my programs panic just because of the two lines;i am confused what caused that happen?below is a part of the function causing the problem



int ip_recv(unsigned char *buff,int flag,int recv_len,struct ip* ippack)


  struct ip* ippack;

         void * ipbuffer;


        // here,buff is the start of our eth head.,buff+14 is our start of ip head;

        ipbuffer=buff;//it works well,but we do not need this ,we need ip head.



        ipbuffer=buff+14;//when we get the ip head as the form

        ippack =(struct ip*)ipbuffer;  //



ippack=(struct ip*)(buff+14);//it panic too,


//now the condition is we can not convert address buf+14 into (struct ip),how can i fix it?



thanks a lot for your help?





2008-06-24 03:59:47     Re: problems about "struct iphdr *ip"

Mike Frysinger (UNITED STATES)

Message: 57758   


that code is full of alignment issues.  you cannot do unaligned loads on the Blackfin as is documented in many places.  if it works on another Linux system, it's either because you're using an older compiler or it supports unaligned loads or both.


you need to create local storage and use memmove() to copy the data out of the buffer and into the local storage.