简体   繁体   English

socket.recvfrom() 返回的结果

[英]Results returned by socket.recvfrom()

I have this simple code in python-3.5:我在 python-3.5 中有这个简单的代码:

import socket
sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(3))
raw_data, addr = sock.recvfrom(65536)

recvfrom() returns data received on the socket in raw_data variable and a tuple in addr variable. recvfrom() 在 raw_data 变量中返回在套接字上接收到的数据,在 addr 变量中返回一个元组。

This returned tuple (addr) has 5 elements in it and I can't find the meaning of the different elements.这个返回的元组 (addr) 中有 5 个元素,我找不到不同元素的含义。

addr[0] contains the name of the interface on which raw_data was received. addr[0] 包含接收 raw_data 的接口的名称。

addr[1] contains the Ethertype received. addr[1] 包含收到的 Ethertype。

addr[4] contains the layer 2 address of the sender (as far as I understand). addr[4] 包含发送者的第 2 层地址(据我所知)。

What are the values contained in elements addr[2] and addr[3]?元素 addr[2] 和 addr[3] 中包含的值是什么?

It's been 5 years passed ) Have got your answer yet?已经5年过去了)有你的答案了吗? I've come across the same stuff only now... It's really hard to find an description of this.我现在才遇到同样的东西......真的很难找到关于这个的描述。 So everything I can say that the third one is somehow related to a sender address you see:所以我可以说第三个在某种程度上与你看到的发件人地址有关:

('eth0', 2048, 4, 1, b'RT\x00\x96\x9d\x16')
('eth0', 2054, 1, 1, b'\x00\x10t"\x82|')
('eth0', 2048, 0, 1, b'l;k`g0')

The fourth one is still the most mystic:) If you have already had an answer please share it here.第四个仍然是最神秘的:)如果您已经有了答案,请在这里分享。

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

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