为什么协议必须以大端顺序发送到套接字函数而其余参数不是?
Why protocol must be sent to the socket function in big-endiannes order and the rest of the parameters not?
我在 python 中使用套接字库的套接字方法,它看起来像这样:
socket.socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None)
现在我看到了一些使用该方法来过滤以太网数据包的方法,它看起来像这样:
import socket
ETH_P_ALL = 3
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(ETH_P_ALL))
s.close()
我想知道文档中的哪个地方说 proto 参数必须用于网络字节序 (big)。
以及为什么只有 proto 参数而不是其余参数。
为什么不是这个:
s = socket.socket(socket.htons(socket.AF_PACKET), socket.htons(socket.SOCK_RAW), socket.htons(ETH_P_ALL))
谢谢。
I want to know where in the documentation it says that the proto parameter must be used in network endiannes ( big )
来自man 7 packet:
packet_socket = socket(AF_PACKET, int socket_type, int protocol);
... protocol is the IEEE
802.3 protocol number in network byte order. See the
include file for a list of allowed protocols.
When protocol is set to htons(ETH_P_ALL), then all protocols are
received.
我在 python 中使用套接字库的套接字方法,它看起来像这样:
socket.socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None)
现在我看到了一些使用该方法来过滤以太网数据包的方法,它看起来像这样:
import socket
ETH_P_ALL = 3
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(ETH_P_ALL))
s.close()
我想知道文档中的哪个地方说 proto 参数必须用于网络字节序 (big)。 以及为什么只有 proto 参数而不是其余参数。 为什么不是这个:
s = socket.socket(socket.htons(socket.AF_PACKET), socket.htons(socket.SOCK_RAW), socket.htons(ETH_P_ALL))
谢谢。
I want to know where in the documentation it says that the proto parameter must be used in network endiannes ( big )
来自man 7 packet:
packet_socket = socket(AF_PACKET, int socket_type, int protocol);
... protocol is the IEEE 802.3 protocol number in network byte order. See the include file for a list of allowed protocols. When protocol is set to htons(ETH_P_ALL), then all protocols are received.