gpt4 book ai didi

c - 如何在没有 root 权限的情况下从 Linux 上的 C 中的 UDP 数据包中取回超过 TTL 的错误消息?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:14:25 25 4
gpt4 key购买 nike

我想发送一个带有短 TTL 值的 UDP 数据包,并在没有 root 权限的情况下取回超过 TTL 的错误消息。我该怎么做?

最佳答案

设置 UDP 套接字选项:

复制自(http://www.codeforge.com/read/3605/tracepath.c__html)

on = IP_PMTUDISC_DO; // sets the Don't-Fragment flag

setsockopt(fd, SOL_IP, IP_MTU_DISCOVER, &on, sizeof(on)); // Set or receive the Path MTU Discovery setting for a socket. When enabled, Linux will perform Path MTU Discovery

setsockopt(fd, SOL_IP, IP_RECVERR, &on, sizeof(on)); // Enable extended reliable error message passing. When enabled on a datagram socket, all generated errors will be queued in a per-socket error queue.

// When the user receives an error from a socket operation, the errors can be received by calling recvmsg(2) with the MSG_ERRQUEUE flag set.

setsockopt(fd, SOL_IP, IP_RECVTTL, &on, sizeof(on)); // When this flag is set, pass a IP_TTL control message with the time to live field of the received packet as a byte. Not supported for SOCK_STREAM sockets.

看来我可以从那里以 sock_extended_err 结构的形式获取 TTL_Exceeded 错误消息。

关于c - 如何在没有 root 权限的情况下从 Linux 上的 C 中的 UDP 数据包中取回超过 TTL 的错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32380821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com