红联Linux门户
Linux帮助

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

发布时间:2016-08-25 14:59:33来源:linux网站作者:于海平
对于通过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.
 
本文永久更新地址:http://www.linuxdiyf.com/linux/23616.html