如何在没有root权限的情况下,在Linux上的C语言中从UDP数据包中获取超出ttl的错误消息



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

设置UDP socket选项:

复制自(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错误消息。