Is there a way to get the destination MAC address, if the destination IP is known, using ANSI C? I would preferably do it with a system call so the kernel deals with it all and I can take advantage of the ARP cache. I know I can build and send my own ARP request, but then I would not have the caching functionality etc unless I implement it myself so it feels like letting the kernel handling it is the way to go.
What I decided to do was to send my own ARP packets and caching it internaly in my application. If the destination is outside my local network I parse /proc/net/route
and extract the gateway for the given interface and send an arp packet to the gateway to get it's macaddress (since that is the destination macaddress of packets destined outside the local network).