您的位置:首页 > 运维架构 > Linux

嵌入式linux系统重新加载DNS配置

2016-06-12 11:14 726 查看
对于通过wifi等移动网络联网的的嵌入式系统而言,当wifi环境发生变化(如连接新的wifi)时,DNS路由器地址很可能会被更新。在这种情况下,应用程序的DNS也要及时更新,不然应用程序的网络可能会不通,当通过http等协议访问服务器的时候,返回“couldn‘t resolve hostname”错误。

此时,通过如下函数可以更新应用程序的DNS配置。

#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>

res_init();


函数说明如下:

The  res_init()  function  reads the configuration files (see resolv.conf(5)) to get the default domain name, search order and name server address(es).  If no
server is given, the local host is tried.  If no domain is given, that associated with the local host is used.  It can  be  overridden  with  the  environment
variable LOCALDOMAIN.  res_init() is normally executed by the first call to one of the other functions.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: