我需要在C中直接处理以太网帧,我被以太网帧头中字段的顺序弄糊涂了。这是一个编程问题,所以请不要将其标记为非主题。
下图来自书"TCP/IP插图第1卷,第2版“第85页。

正如它所显示的,“长度或类型”字段位于"P/Q标记“字段之前(如果有)。
然而,在我接收到的帧被六转储后,我意识到我收到的帧在"P/Q标签“后面有”长度或类型“。见下文
0100 5e00 007b Destination MAC (multicast)
000f 5325 fb00 Source MAC
8100 Q-tagged frame. (802.1q standard uses it to denote VLAN).
0065 Prio (3 bits), CFI (1bit), VLAN ID(12 bit)
0800 EtherType (Type field)
4500 IP packet starts from here.问题1:这两个字段的顺序是什么?
问题2:如何正确检查以太网帧头的大小。需要知道IP数据包从哪里开始。
发布于 2014-11-24 23:00:00
这是教科书中的一个错误(仅在第二版,参见EJP的评论)。不仅我的代码显示Q标记位于"Length/Type“字段之前。还请参阅来自OpenOnload的以下开放源代码。
openonload-201405-u1/src/include/ci/net/ethernet.h
typedef struct ci_ether_hdr_s {
ci_uint8 ether_dhost[ETH_ALEN];
ci_uint8 ether_shost[ETH_ALEN];
ci_uint16 ether_type;
} ci_ether_hdr;
typedef struct {
ci_uint8 ether_dhost[ETH_ALEN]; /* destination eth addr */
ci_uint8 ether_shost[ETH_ALEN]; /* source ether addr */
ci_uint16 ether_vtype; /* vlan type field 0x8100 */
ci_uint16 ether_vtag; /* vlan tag */
ci_uint16 ether_type; /* packet type ID field */
} ci_ethhdr_vlan_t;https://stackoverflow.com/questions/27053273
复制相似问题