[...] 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 include arping
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.
coreutils
and have a look atping
. gnu.org/software/coreutils – Jason Huping
is not in coreutils. – indiv