icmp.h
确实是正确的标题。您可以查看的源代码
icmp.h
对于这些东西:
#define ICMP_ECHOREPLY 0 /* Echo Reply */
#define ICMP_DEST_UNREACH 3 /* Destination Unreachable */
#define ICMP_SOURCE_QUENCH 4 /* Source Quench */
#define ICMP_REDIRECT 5 /* Redirect (change route) */
#define ICMP_ECHO 8 /* Echo Request */
#define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */
#define ICMP_PARAMETERPROB 12 /* Parameter Problem */
#define ICMP_TIMESTAMP 13 /* Timestamp Request */
#define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */
#define ICMP_INFO_REQUEST 15 /* Information Request */
#define ICMP_INFO_REPLY 16 /* Information Reply */
#define ICMP_ADDRESS 17 /* Address Mask Request */
#define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */
这些是位定义(它在
man icmp
),所以你需要为你想要的选项设置相应的位,通常使用shift,使用
|
到
或
多个比特在一起。定义筛选器对象,然后设置数据字段
struct icmp_filter my_filter = {
1U << ICMP_ECHO |
1U << ICMP_TIME_EXCEEDED ...
};
等等,并使用以下命令将其传递给套接字选项
setsockopt
.