how to determinate destination MAC address

时光怂恿深爱的人放手 提交于 2019-12-02 15:52:58

问题


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?


回答1:


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.




回答2:


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?



来源:https://stackoverflow.com/questions/4012921/how-to-determinate-destination-mac-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!