P
Pieter Claassen
Ok, I have something that works, but I don't understand why.
I use libpcap to get data of the wire and then initially I casted the
packet to ethernet, then marched along the memory in chunks of bytes for
the length of the ethernet header until I reached the IP header and so
forth...
So, I changed my code and now process the ethernet header after which I
pass the size of the the ethernet header to be deducted and a pointer to
the the location in the memory where the ethernet header starts like
handle_ip(ether_header_size,(void*)eptr);
The function that hanldes the ip has the following prototype:
void handle_ip(u_int32_t ether_hdr_size, void* eptr){
and I use the following function to crawl along the memory (in what I
assume to be byte sized chunks) to the IP header:
ip = (struct ip*)(eptr + ether_hdr_size);
My question is why does this work if I pass a void* in to the functions,
but not if I pass a pointer to a ether struct? I get garbage when I don't
do the void* cast.
Thanks for the help in advance.
Pieter
I use libpcap to get data of the wire and then initially I casted the
packet to ethernet, then marched along the memory in chunks of bytes for
the length of the ethernet header until I reached the IP header and so
forth...
So, I changed my code and now process the ethernet header after which I
pass the size of the the ethernet header to be deducted and a pointer to
the the location in the memory where the ethernet header starts like
handle_ip(ether_header_size,(void*)eptr);
The function that hanldes the ip has the following prototype:
void handle_ip(u_int32_t ether_hdr_size, void* eptr){
and I use the following function to crawl along the memory (in what I
assume to be byte sized chunks) to the IP header:
ip = (struct ip*)(eptr + ether_hdr_size);
My question is why does this work if I pass a void* in to the functions,
but not if I pass a pointer to a ether struct? I get garbage when I don't
do the void* cast.
Thanks for the help in advance.
Pieter