Hi, I'm working on a project where I'm parsing pcap files to check network statistics. However, I've come across a problem, the ethernet type seems to be coming up as random numbers. Here's some code snippets
#define ETH_ALEN 6
#pragma pack(1)
struct ether_header
{
u_char ether_dhost[ETH_ALEN]; /* destination eth addr */
u_char ether_shost[ETH_ALEN]; /* source ether addr */
u_short ether_type; /* packet type ID field */
};
...
struct ether_header *eptr;
while (packet = pcap_next(handle,&header))
{
eptr = (struct ether_header *)packet;
printf("ether type = %x\n", ntohs(eptr->ether_type));
}
The output I'm getting for this bit of code is something along the lines of
ether type = 3430
ether type = 230
ether type = 8f6
ether type = 3a34
ether type = 413f
ether type = 3848
ether type = 230
ether type = 3c9c
ether type = 3c9c
ether type = 4552
ether type = ffff
ether type = 230
Can anybody shed some light on what the problem here might be? I've tried with and without the pragma packing as well as attempting to access the data directly (with some pointer manipulation), none of which seems to work.
Thanks for any help