FreeBSD:网络接口地址:dhcp或静态 [英] FreeBSD: network interface address: dhcp or static

查看:112
本文介绍了FreeBSD:网络接口地址:dhcp或静态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过编程(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或静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆