如何在C中将arp地址添加到/proc/net/arp中

发布于 2024-11-15 00:05:39 字数 121 浏览 4 评论 0原文

我想将 arp 绑定添加到 C 中的 /proc/net/arp 中。不允许写入文件,因此尝试以其他方式执行此操作。有什么建议吗?我已经知道 net-tools,但还没有尝试过

I would like to add arp bindings into /proc/net/arp in C. Writing into file is not allowed, so trying to do it some other way. Any suggestions? I already know about net-tools, but havent tryed yet

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇纵 2024-11-22 00:05:39

您需要使用 netlink 协议libnetlink。我建议查看 arp 命令的源代码,以了解它是如何执行的。

You will need to use the netlink protocol or libnetlink. I would recommend looking at the source for the arp command to see exactly how it does it.

給妳壹絲溫柔 2024-11-22 00:05:39

ip neigh add 可以做到这一点:

例如:

root@refactor:~# ip neigh show
192.168.1.1 dev wlan0 lladdr 00:1b:da:29:3a:87 REACHABLE
root@refactor:~# ip neigh add 192.168.1.2 dev wlan0 lladdr 00:1b:da:29:3a:89
root@refactor:~# ip neigh show
192.168.1.2 dev wlan0 lladdr 00:1b:da:29:3a:89 PERMANENT
192.168.1.1 dev wlan0 lladdr 00:1b:da:29:3a:87 REACHABLE

这是你想要做的吗?

如果您想直接在 C 中执行此操作,请查看 ip 工具的源代码,该工具是 iproute2 包的一部分。

ip neigh add can do this:

For example:

root@refactor:~# ip neigh show
192.168.1.1 dev wlan0 lladdr 00:1b:da:29:3a:87 REACHABLE
root@refactor:~# ip neigh add 192.168.1.2 dev wlan0 lladdr 00:1b:da:29:3a:89
root@refactor:~# ip neigh show
192.168.1.2 dev wlan0 lladdr 00:1b:da:29:3a:89 PERMANENT
192.168.1.1 dev wlan0 lladdr 00:1b:da:29:3a:87 REACHABLE

Is this what you want to do?

If you want to do this directly in C, look at the source of the ip tool, which is part of the iproute2 package.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文