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

2019-07-12 14:37发布

        对于通过wifi等移动网络联网的的嵌入式系统而言,当wifi环境发生变化(如连接新的wifi)时,DNS路由器地址很可能会被更新。在这种情况下,应用程序的DNS也要及时更新,不然应用程序的网络可能会不通,当通过http等协议访问服务器的时候,返回“couldn‘t resolve hostname”错误。        此时,通过如下函数可以更新应用程序的DNS配置。 #include #include #include 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. 其它,与网络地址相关的常用的函数:gethostbyname():获取指定的域名或者主机名对应的IP。
gethostbyaddr():获取指定IP地址对应的主机信息。
res_query()。