views:

50

answers:

2

My application is running on CentOS 5.5 I need to send raw packets using libpcap API:

pcap_inject() or pcap_sendpacket()

To the specific IP address How can I determinate MAC address belongs to a specific target?

A: 

In general, MAC addresses don't matter for remote targets. They are not routable; a router here at my office doesn't know the MAC addresses of network cards across the Internet. That's what IP addresses are for. Do you mean local only?

unwind
I need to send a raw Ethernet packets, in order to do it I need to fill Ethernet header that contains source and destination MACs.I'm looking for a way how can I programmatically ask to get MAC from ARP cache and if my MAC is not there to execute ARP request and return me the result.
Dima
+1  A: 

It looks like what you want is ioctl and SIOCGARP. That should let you query your arp cache. I'm assuming that the host in question is on your local network or all you're going to get is your router.

You can also read from /proc/net/arp, which seems easier. You'll need to get an arp request returned first but you'll be doing that whether your tool does it or some third-party makes the request.

Paul Rubel
How can I make an ARP request for host that is not in the ARP cache table? As I understanding, I can just ping the host, but maybe there is a formal API for ARP request?
Dima
Sending a datagram might be the easiest way, certainly easier than some ioctl type interactions.
Paul Rubel
See `man arping`
TomMD