问题描述
如何通过编程(C)知道给定接口的地址是 static 还是 dhcp 提供的地址?我可以看一下/var/db/dhclient.leases.<interface_name>
.有更好/更清洁的方法吗?我可以使用的任何ioctl
吗?
How can I programmingly (C) know if given interface has static address or one provided by dhcp? I can look at /var/db/dhclient.leases.<interface_name>
. Any better/cleaner way? any ioctl
I can use?
推荐答案
阅读/etc/rc.conf
.查找以ifconfig
开头的行,并查看其中哪些包含文本DHCP
.
Read /etc/rc.conf
. Look for lines starting with ifconfig
and see which of those contain the text DHCP
.
这不会捕获通过手动运行dhclient
重新配置的接口.假设租用文件允许您的程序读取它,则在这方面解析租用文件会更好.
This will not catch interfaces that were re-configured by running dhclient
manually. Parsing the leases file would work better in that respect, assuming its permessions allow your program to read it.
这篇关于FreeBSD:网络接口地址:dhcp或静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!