Hi.
 
I forgot one last thing:
how can you be sure that the captured packets are IP packets?
You have to check in the ethernet header that the "Ethertype" field value is 0x800.
 
The same question applies to TCP (you have to check the appropriate field in the IP header).
 
GV
 
 
----- Original Message -----
Sent: Friday, May 31, 2002 3:23 PM
Subject: Re: [WinPcap-users] (CLASS A&C PROBLEM AGAIN)code is here please have a look...

Hi.
 
First, it depends on how you declared the ethernet header.
Second, the IP header has not a fixed length (it is *usually* 20 bytes, but it's longer if it contains options).
Third, it is not safe to "printf("%s" payload)", since the payload is not a string, but rather a sequence of bytes.
Fourth, did you try windump (http://windump.polito.it)? If it works (i.e. it is able to decode packets), then there is an error in your code.
 
GV
----- Original Message -----
From: leo lion
Sent: Friday, May 31, 2002 3:01 PM
Subject: [WinPcap-users] (CLASS A&C PROBLEM AGAIN)code is here please have a look...

_________________________________________________

const struct sniff_ethernet *ethernet;
        const struct sniff_ip *ip;           
        const struct sniff_tcp *tcp;       
        const char *payload;               
        int size_ethernet = sizeof(struct sniff_ethernet);
        int size_ip = sizeof(struct sniff_ip);
        int size_tcp = sizeof(struct sniff_tcp);

         ethernet = (struct sniff_ethernet*)(packet);
        ip = (struct sniff_ip*)(packet + size_ethernet);
        tcp = (struct sniff_tcp*)(packet + size_ethernet + size_ip);
        payload = (u_char *)(packet + size_ethernet + size_ip + size_tcp);

 printf("Packet number %d has just been sniffed of length:%d\n", count,header->len);
 printf("\tFrom:    %s:%d\n", inet_ntoa(ip->ip_src), ntohs(tcp->th_sport));
 printf("\tTo:      %s:%d\n", inet_ntoa(ip->ip_dst), ntohs(tcp->th_dport));
 printf("\tPayload: %s\n", payload);

I GUESS THERE'S NOTHING WRONG WITH THE CODE but still it doesn't work..why...???



Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup

Reply via email to