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标记的帧,所以谢谢! –