ICMP套接字(Linux) [英] ICMP sockets (linux)

查看:79
本文介绍了ICMP套接字(Linux)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在IP协议下使用ICMP套接字?也许像这样:

Is it possible to use ICMP sockets under the IP protocol? Maybe something like:

socket(PF_INET, <type>, IPPROTO_ICMP)?

我应该在<中添加什么?类型>字段?我看到了一些使用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该命令(在根目录下).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆