1
我與libpcap的學習從這個http://www.tcpdump.org/pcap.html,我已經用這個代碼碰到的問題:編程使用PCAP例如
struct sniff_ethernet {
u_char ether_dhost[ETHER_ADDR_LEN]; /* Destination host address */
u_char ether_shost[ETHER_ADDR_LEN]; /* Source host address */
u_short ether_type; /* IP? ARP? RARP? etc */
};
...
const struct sniff_ethernet *ethernet; /* The ethernet header */
ethernet = (struct sniff_ethernet*)(packet);
我越來越ether_type值與交換的字節。我認爲原因是我使用的是x86_64 little-endian機器,其中LSB在最低地址處,並且在數據包字節流中,ether_type MSB在LSB之前。問題是:是僅在大端機器上工作的示例代碼,還是我錯過了一些東西?
我不知道'ntohs()'它解決了我的問題,檢測802.1Q標記的幀,所以謝謝! –