Re: Parsing Packets
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Re: Parsing Packets




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Re: Parsing Packets  
Lev Walkin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-01-04 01:53 AM

chris wrote:

>
>
> Problem fixed:
>
>     packet += sizeof(struct ether_header);
>     iphdr = (struct ip *) packet;
>     printf("%02X packet captured; %d bytes\n", iphdr->ip_p, size);
>
> I guess it had something to do with precedence?
>


No, it does have to do with C basic pointer arithmetics.

If you have pointer to a type, adding a size to it WOULD NOT shift
that pointer to this many bytes:

struct ip *packet;
packet += 1;

In fact, the difference between the packet pointer and its previous
value will be the size of an (struct ip).

So, this code is invalid:

=== cut ===
iphdr = (struct ip *) packet + sizeof(struct ether_header);
=== cut ===

And must be rewritten as:


=== cut ===
iphdr = (struct ip *)(packet + sizeof(struct ether_header));
=== cut ===


--
Lev Walkin
vlm@lionet.info





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:23 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register