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

本文介绍了当WiFi环境变化时,嵌入式系统的DNS配置如何更新以确保网络连通性。详细解释了res_init()函数的作用及使用方法,并列举了其他网络地址相关函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        对于通过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.

其它,与网络地址相关的常用的函数:

gethostbyname():获取指定的域名或者主机名对应的IP。
gethostbyaddr():获取指定IP地址对应的主机信息。

res_query()。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值