WinPCap を使用して、イーサネット ラベル (送信先アドレス、送信元アドレス、タイプ/長さフィールド) を取得して解析しようとしています。
私は主に WinPCap SDK からコピー/貼り付けしています。WinPCap パケット データ (pkt_data 内) を、宛先アドレス [6 バイト]、送信元アドレス [6 バイト]、タイプ/長さフィールド (short int)、およびパケット長 (int) を含む、ethernet という名前の構造体に格納しようとしています。
pkt_data は、最初の 6 バイトが宛先アドレス、次の 6 バイトが送信元アドレス、その後の 2 バイトがタイプ/長さフィールドとして並んでいると思いますが、よくわかりません。
この例で WinPCap が保存するラベルの正確なバイト順を知っている人はいますか?
/* 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));
}