ICMP 套接字 (linux) [英] ICMP sockets (linux)
问题描述
是否可以在IP协议下使用ICMP套接字?也许是这样的:
Is it possible to use ICMP sockets under the IP protocol? Maybe something like:
socket(PF_INET,
我应该在
字段中输入什么?我看到了一些使用 SOCK_RAW
的例子,但这不会阻止操作系统处理 IP 协议吗?
What should I put in the <type>
field? I saw some examples using SOCK_RAW
, but won't that prevent the OS from doing his job handling the IP protocol?
还有一件事.由于协议不涉及端口,操作系统如何知道他应该将 ICMP 数据报发送到哪个进程?
And another thing. How can the OS know to which process he should send the ICMP datagrams, since there are no ports involved with the protocol?
推荐答案
是的,这是可能的,因为 ping
命令执行 ICMP.
Yes it is possible, since the ping
command does ICMP.
要找出所涉及的系统调用,您可以strace
该命令(在 root 下).
To find out the syscalls involved, you can strace
that command (under root).
您还可以浏览该命令的源代码,例如Debian 的 ping
You could also glance into that command's source code, e.g. Debian's ping
还有 liboping 库可以帮助您...
And there is the liboping library to help you...
这篇关于ICMP 套接字 (linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!