检测 IP 是静态的还是从 busybox 上的 DHCP 获取

发布于 2024-08-08 00:06:56 字数 96 浏览 3 评论 0原文

我正在研究运行 BusyBox 的嵌入式设备。
系统使用 ip 命令获取其地址。 我想从我的 C 程序中找出设备是否 ip 静态或从 DHCP 服务器接收。我该怎么做?

I am working on embedded device who run BusyBox.
The system is getting its address by using the ip command.
I want to figure out from my C program whether the device
ip static or received from DHCP server. How do I do that?

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

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

发布评论

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

评论(4

夏夜暖风 2024-08-15 00:06:56

我不知道您的用户如何与您的嵌入式系统交互。但在我们的(相同的组件)上,我们有 CLI,可以在每个接口的 SHM 结构 (db) 中注册所选的 DHCP/STATIC 类型设置。

本质上,您需要跟踪接口的 IP 是如何设置的。

I don't know how your users interact with your embedded system. But on ours (same components) we have CLI that registers the chosen DHCP/STATIC type setting in a SHM struct (db) per interface.

Essentially, you need to keep track of how the IP of an interface was set.

怪我鬧 2024-08-15 00:06:56

dumpleases 命令应该显示当前的租约。我想如果你可以确定你有一个IP地址,但没有租约,那么该地址就是静态的。

The dumpleases command is supposed to show the current leases. I guess if you can determine that you have an IP address, but no lease, then the address is static.

酒解孤独 2024-08-15 00:06:56

看看 这个问题 并检查 IFF_DYNAMIC 标志 - 当 DHCP 在接口上处于活动状态时可能会设置该标志。

Take a look at this question and check the IFF_DYNAMIC flag - that may be set when DHCP is active on an interface.

转角预定愛 2024-08-15 00:06:56

如果你控制环境,我建议设置一个 env 变量,或者在设置 IP 地址时在可以统计的地方创建一个标志文件。

If you control the enviroment, I suggest setting an env variable, or creating a flag file somewhere you can stat, when the IP adress is set.

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