在Linux 2.6.21(glibc 2.3.5)上执行ARP和反向ARP [英] Doing ARP and Inverse ARP on Linux 2.6.21 (glibc 2.3.5)
问题描述
我需要在任意IP网络上存储对第三方设备的持久引用,其中设备的IP地址可以是静态的,也可以由DHCP随机分配.我不控制网络上的设备,也不能依靠现有的DNS或其他临时网络协议或与这些设备一起工作.
I need to store persistent reference to third party device on an arbitrary IP network where the IP address of the devices may be static or randomly assigned by DHCP. I don't control the devices on the network and I can't rely on DNS and other ad-hoc networking protocols existing or working with the devices.
因此,我被指示研究使用硬件地址和ARP.这将起作用,但是我不想重复代码.内核必须管理ARP表.在Windows上,您可以使用 GetIpNetTable 访问它
So I have been instructed to investigate using hardware addresses and ARP. This will work but I don't want to duplicate code. The kernel must manage an ARP table. On Windows you can access it using GetIpNetTable etc.
我希望有一个API可以回答这两个问题:
I am hoping there is an API to answer these two questions:
- 如何从IP转换为MAC地址? (ARP)
- 如何从MAC转换为IP地址? (InARP)
如果没有,那么我可能必须手动进行更多操作:
If not then I may have to do it more manually:
- 如何读取内核的ARP表?
- 如果我自己确定了映射,如何添加条目?
推荐答案
对于ARP:
您可以使用system("/usr/bin/arp -option_of_choice");并解析输出,但这是一个丑陋的破解. -不是我的推荐.
As for ARP:
You could use system("/usr/bin/arp -option_of_choice"); and parse the output, but that's an ugly hack. -- Not my recommendation.
查看/usr/include/linux/sockios.h-有关SIOCGARP,SIOCDARP和SIOCSARP的详细信息.这些是您可以用来在Linux上管理ARP表的ioctl.当然,您必须在套接字fd上执行这些ioctl.
以下是一些示例: SIOCGARP示例
我相信您也可以找到其他几种语言的其他示例.我假设您使用的是C.
Take a look at /usr/include/linux/sockios.h -- At the SIOCGARP, SIOCDARP, and SIOCSARP details. Those are ioctls that you can perform to manage the ARP table on linux. Of course, you'll have to perform these ioctls on a socket fd.
Here's some examples: SIOCGARP examples
I'm sure you can find many other examples in several other languages as well. As I'm assuming that you're using C.
至于RARP:
linux rarp手册页中的一句话:
该程序已过时.从2.3版开始,Linux内核不再
包含RARP支持.有关替代的RARP守护程序,请参见 ftp://ftp.demen-
tia.org/pub/net-tools"
因此,您必须在目标系统上安装rarpd.
As for RARP:
A quote from the linux rarp manpage:
" This program is obsolete. From version 2.3, the Linux kernel no longer
contains RARP support. For a replacement RARP daemon, see ftp://ftp.demen-
tia.org/pub/net-tools"
So you'll have to install rarpd on the target system.
这篇关于在Linux 2.6.21(glibc 2.3.5)上执行ARP和反向ARP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!