Programmatic use of ARP

微笑、不失礼 提交于 2019-12-23 03:10:53

问题


I have a need for some C or C++ code, compilable under Linux, to be able to take a list of IP addresses of some arbitrary number of remote hosts machines and obtain a ethernet MAC address for each one. These host machines may be on the same subnet or they could be on a different subnet behind a router. Its OK if the MAC address of some or all of the remote hosts is the address of the interface on the router. Ultimately, I want to hand off the IP address and MAC address to an FPGA who will use these pieces of information to format and send UDP/IP packets over ethernet to the hosts. Obviously, the FPGA will also be given its own MAC address and IP address to fill in the source MAC and source IP addresses in the packets.

Is there some code I can be pointed to that can create and broadcast ARP packets to these remote machines and receive back the ARP response packets such that the destination MAC addresses can be extracted?


回答1:


Part of what you want to do requires some raw socket programming.

http://mixter.void.ru/rawip.html

The source for the linux arp command will give the rest of what you need. Here's a link:

http://www.comp.nus.edu.sg/~cs4236/readings/out/html/arp_8c-source.html




回答2:


I recommend looking into arping which is doing a somewhat identical job. It takes IPs and MACs and tries to receive additional informationen. Or justs pings them.

http://freshmeat.net/projects/arping/



来源:https://stackoverflow.com/questions/2451737/programmatic-use-of-arp

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