发送ICMP的ping [英] Sending ICMP ping
问题描述
有关ICMP ping请求(echo请求),我需要获得目标的MAC地址?我想学习如何使用原始套接字用C实现这一点,但无法理解怎么去目的地的MAC地址。
任何帮助是AP preciated。
谢谢你。
[...]我需要获得目标的MAC地址?
块引用>没有你不应该在大多数情况下。
从该名男子页
原材料(7)
(我的重点):
原始套接字允许在用户空间中实现新的IPv4协议。原始套接字接收或发送原始数据包的不包括链路层报头
块引用>这是唯一合乎逻辑的,因为你可能会
平
-ing东西不在同一子网,在这种情况下,MAC地址将路由器的MAC地址。要证明这一点,这里的部分源$ C $ C为
平
- 我第一个在谷歌找到。需要注意的是它不试图找到目的地MAC地址请注意,有些UNIX
平
程序做各种有趣的东西。有些版本,例如让你欺骗传出的源IP。有些版本包括的arping
功能。在这些情况下,他们将在一个较低的水平(在链路层),在这种情况下将需要的原始消息头被注入的东西。For ICMP ping request (echo request) do I need to get the MAC address of the destination ? I am trying to learn how to implement this in C using raw sockets but can not understand how to get the MAC address of the destination.
Any help is appreciated. Thanks.
解决方案[...] do I need to get the MAC address of the destination ?
No you shouldn't, in most cases.
From the man-page of
raw(7)
(my emphasis):Raw sockets allow new IPv4 protocols to be implemented in user space. A raw socket receives or sends the raw datagram not including link level headers.
This is only logical, because you might be
ping
-ing something not on the same subnet, in which case the MAC address would be the MAC address of the router.To prove the point, here's some source code for an old BSD version of
ping
- first one I found on Google. Note that it doesn't attempt to find the destination MAC address.Note that some UNIX
ping
programs do all sorts of fun stuff. Some versions for instance allow you to spoof the outgoing source IP. Some versions includearping
functionality. In these cases they will be injecting things at a lower level (at the link level), in which case you will need raw headers.这篇关于发送ICMP的ping的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!