I'm trying to acquire and parse an ethernet label (dest address, source address, type/length field) using WinPCap.
I'm mostly copying/pasting from the WinPCap SDK. I am trying to store the WinPCap packet data (in pkt_data) in a struct named ethernet containing destination address [6 bytes], source address [6 bytes], type/length field (short int) and packet length (int).
I think that the pkt_data is lined up with the first 6 bytes as the destination address, the next 6 bytes as the source address, and the two after as the type/length field, but I'm not sure.
Does anyone know the exact byte order of the label that WinPCap stores in this example?
/* If device is open, acquire attributes from packet */
if( ( res = pcap_next_ex( fp, &header, &pkt_data)) >= 0)
{
if(res != 0)
{
/* Acquire the length of the capture */
ethernet->length = header->caplen;
/* Acquire destination MAC address */
for (i = 0; i < 6; i++)
ethernet->destAddress[i] = pkt_data[i];
/* Acquire source MAC address */
for ( i = 6; i < 12; i++ )
ethernet->srcAddress[i] = pkt_data[i];
/* Acquire etherType type/length designation field */
ethernet->type = ( pkt_data[12] | pkt_data[13] );
/* Acquire the remaining data of the packet */
for ( i = 14; (i < header->caplen + 1); i++ )
ethernet->data[i - 14] = pkt_data[i];
}
/* Device error: cannot read from packet */
else if(res == -1)
printf("Error reading the packets: %s\n", pcap_geterr(fp));
}