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

标签 c linux sockets udp ttl

我想发送一个带有短 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/

相关文章:

sql - Gnome 的 libgda 和 SQL 注入(inject)

c - c 中的 rand() 出现问题

java - 为什么 BufferedReader 读取的行数多于 wc 命令检测到的大文件行数?

sockets - GNAT.Sockets获取MAC地址

iphone - 通过 wifi 与硬件设备进行短信通信的最佳方式

c - Linux 和 Windows 之间 fwrite 的不同行为

c - 在每个函数的开头应用断点

linux - 嵌入式linux子进程创建问题

java - 在没有 X11 的情况下编译 OpenJDK 7

java - 在 Internet 上部署 Java 聊天服务器(套接字)