【发布时间】:2012-05-05 14:55:40
【问题描述】:
我正在尝试使用 IP_MTU 套接字选项读取我的 TCP 连接 的 MTU
根据安装在我的 Debian Etch 上的man 7 ip(我知道,它已经很老了,但现在不能更改它):
SYNOPSIS
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h> /* superset of previous */
[CUT]
IP_MTU Retrieve the current known path MTU of the current socket.
Only valid when the socket has been connected. Returns an integer.
Only valid as a getsockopt(2).
问题是上述套接字选项不存在于手册页命名的任何包含文件中。 (因此我的代码没有编译;))
相反,我发现它在 <linux/in.h> 中定义(grep 是你的朋友)
如果我尝试将<linux/in.h> 添加到我的源代码中,我会得到各种多重定义/重新声明编译错误。
有谁知道为什么标题中缺少上述参数以及如何解决该问题?
非常感谢
塞尔吉奥
【问题讨论】:
-
定义是否仅存在于
linux/in.h中?它不是出现在xxxxx/bits/in.h中吗?netinet/in.h似乎包含在bits文件夹下的in.h(至少在我的系统上)。您可以尝试仅查看预处理器输出(使用gcc的-E选项)& grep for "include" 以查看包含的文件并检查其中是否有定义。 -
似乎唯一定义它的文件是
linux/in.hvm-etch-dev32# grep -rn IP_MTU * bits/in.h:61:#define IP_MTU_DISCOVER 10 /* int; see below */ bits/in.h:67:/* IP_MTU_DISCOVER arguments. */ linux/in.h:67:#define IP_MTU_DISCOVER 10 linux/in.h:71:#define IP_MTU 14 linux/in.h:80:/* IP_MTU_DISCOVER values */ -
够奇怪的
bits/in.h似乎改为为 IPv6 定义 MTU 值:#define IPV6_MTU 24 -
这很奇怪...
bits.h中第 61 行和第 67 行之间的条目是什么?评论似乎表明这些是IP_MTU_DISCOVER的参数