Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个程序来找出哪个网络接口最适合连接到指定的目标地址。
现在,我可以通过netlink套接字 API 获取路由表,但其中似乎没有网络掩码信息。我阅读了 的手册rtnetlink,在所有rtattr项目中,没有网络掩码信息,只是RTA_DST, RTA_SRC, RTA_GATEWAY... 定义。
netlink
rtnetlink
rtattr
RTA_DST
RTA_SRC
RTA_GATEWAY
那么,如何查看路由表中的网络掩码信息呢?就像我们在route -n输出中看到的一样。
route -n
非常感谢。
关联的前缀长度RTA_DST在 的rtm_dst_len字段中rtmsg,而不是在rtattr. (我猜是因为它是一个固定大小的字段,不像RTA_DST,它的大小因家庭而异。)
rtm_dst_len
rtmsg