我没有在内核中找到任何文档/说明,要求以网络字节顺序将 netlink 消息中的 16/32-bit
值传递给内核。所以我的问题是在填充网络链接消息时是否必须使用 htonl
/htons
函数。有这样的要求吗?
最佳答案
根据 this article这可以在每个属性的基础上进行控制
There are two special flags which may be present in netlink attributes, though I have yet to encounter them in my work.
NLA_F_NESTED: specifies a nested attribute; used as a hint for parsing. Doesn’t always appear to be used, even if nested attributes are present. NLA_F_NET_BYTEORDER: attribute data is stored in network byte order (big endian) instead of host endianness
UPD:看起来 native (小)字节序在某些情况下不能很好地工作:我得到 errno 4097
试图使用它传递 IPSET CREATE 超时。网络字节顺序工作正常。
关于linux - netlink 和大端格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43370845/