简体   繁体   English

以太网类型0x0101不适用于原始套接字

[英]Ethernet type 0x0101 not working with raw socket

I tried to send a raw packet with ethernet type 0x0101 but it seems not to be working, if I use ethernet type 0x1000 it is working properly. 我试图发送一个以太网类型为0x0101的原始数据包但似乎没有工作,如果我使用以太网类型0x1000它正常工作。 Basically I open a raw socket: 基本上我打开一个原始套接字:

int sd = socket(AF_PACKET, SOCK_RAW | SOCK_CLOEXEC, htons(0x0101));
int r = sendmsg(sd, msgSend, 0);

accordingly with iana ethernet type 0101-01FF are experimental, so to my understating can be used for experiments. 相应地与IANA以太网类型0101-01FF是实验性的,所以我的低估可用于实验。

If I use 0x0101 tcpdump shows: 如果我使用0x0101 tcpdump显示:

00:00:01.001914 aa:00:00:2e:00:02 > 08:00:27:0b:ed:84, 802.3, length 257: LLC, dsap Null (0x00) Individual, ssap Null (0x00) Command, ctrl 0x0000: Information, send s0
        0x0000:  0000 0000 efbe adde aaaa db00 0000 0000  ................                                                                                              
        0x0010:  0000 0000 0000 0000 0000 0000 0000 0000  ................                                                                                              
        0x0020:  0000 0000 0000 0000 0000 0000 0000 0000  ................                                                                                              
        0x0030:  0000

while when I use 0x1000 is shows: 而当我使用0x1000时显示:

00:00:00.439876 aa:00:00:2e:00:02 > 08:00:27:0b:ed:84, ethertype Trail (0x1000), length 64:                                                                            
        0x0000:  0000 0000 efbe adde aaaa db00 0000 0000  ................                                                                                              
        0x0010:  0000 0000 0000 0000 0000 0000 0000 0000  ................                                                                                              
        0x0020:  0000 0000 0000 0000 0000 0000 0000 0000  ................                                                                                              
        0x0030:  0000 

What am I missing? 我错过了什么?

Tcpdump interprets the value 0x0101 in this position as Ethernet Frame Length . 0x0101将此位置的值0x0101解释为以太网 0x0101

Values smaller than 0x600 (1536 decimal) are assumed to be the frame length (parsed as Frametype IEEE 802.2 LLC) instead of the next protocol id (parsed as Frametype Ethernet II). 假设小于0x600(十进制1536)的值是帧长度(解析为帧类型IEEE 802.2 LLC)而不是下一个协议ID(解析为帧类型以太网II)。

Here you see, that tcpdump indeed interprets 0x101 (257 decimal) as the length: 在这里你看,tcpdump确实将0x101(十进制257)解释为长度:

00:00:01.001914 aa:00:00:2e:00:02 > 08:00:27:0b:ed:84, 802.3, length 257 : LLC, dsap Null (0x00) Individual, ssap Null (0x00) Command, ctrl 0x0000: Information, send s0 00:00:01.001914 aa:00:00:2e:00:02> 08:00:27:0b:ed:84,802.3, 长度257 :LLC,dsap Null(0x00)Individual,ssap Null(0x00)命令, ctrl 0x0000:信息,发送s0

But your frame should be correctly on-wire as you intended it. 但是您的框架应该按照您的意图正确联机。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM