|
|
本帖最后由 zhengwending 于 2026-10-19 12:17 编辑
嗯,,谢谢版主回复。。。net_config_eth_0开启了DNS,加了版主的回调char const *hosts[3] =
{
"www.baidu.com",
"www.qq.com",
};
static void dns_cbfunc (unsigned char event, unsigned char *ip)
{
switch (event)
{
/* 成功解析地址 */
case netDNSc_EventSuccess:
printf("%d.%d.%d.%d\n",ip[0],ip[1],ip[2],ip[3]);
break;
/* DNS记录数据库中不存在此地址 */
case netDNSc_EventNotResolved:
printf("Host Name does not exist in DNS record database.\n");
break;
/* 允许的DNS解析重试次数已经用完,仍无法解析,时间超时 */
case netDNSc_EventTimeout:
printf("DNS Resolver Timeout expired, Host Address not resolved.\n");
break;
/* DNS协议错误,收到无效或者被损坏的回复 */
case netDNSc_EventError:
printf("DNS Resolver Protocol Error, Host Address not resolved.\n");
return;
}
} 然后1分钟对一次时,if(time_count >= (1 * 60 * 1000 / 200)) //秒 -> 毫秒
{
printf("网址www.armfly.com的IP地址:");
netDNSc_GetHostByName ((uint8_t *)hosts[0],NET_ADDR_IP4, dns_cbfunc);
time_count = 0;
get_time();
} 直接就打印出来了 网址www.armfly.com的IP地址:SNTP请求已经发送成功
UNIX时间戳:1792403016 日期:2026/10/19 时间:09:43:36
0.0.53.0
网址www.armfly.com的IP地址:SNTP请求已经发送成功
UNIX时间戳:1792403076 日期:2026/10/19 时间:09:44:36
0.0.53.0
网址www.armfly.com的IP地址:SNTP请求已经发送成功
UNIX时间戳:1792403136 日期:2026/10/19 时间:09:45:36
0.0.53.0
关闭DNS就不行。。 使用的是静态IP。 版主再指点下? |
|