浏览代码

update: dns_client打印解析到的ip地址

Wendal Chen 3 年之前
父节点
当前提交
6c38627a9a
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7 1
      components/ethernet/common/dns_client.c

+ 7 - 1
components/ethernet/common/dns_client.c

@@ -1,3 +1,4 @@
+
 #include "luat_base.h"
 #include "luat_mcu.h"
 #include "luat_malloc.h"
@@ -152,6 +153,7 @@ int32_t dns_get_ip(dns_client_t *client, Buffer_Struct *buf, uint16_t answer_num
 
 	uint32_t ttl;
 	uint8_t error = 0;
+	PV_Union pvUn;
 
 	for(i = 0; i < answer_num; i++)
 	{
@@ -180,9 +182,13 @@ int32_t dns_get_ip(dns_client_t *client, Buffer_Struct *buf, uint16_t answer_num
 #ifdef LUAT_USE_LWIP
 			ip_addr.type = IPADDR_TYPE_V4;
 			ip_addr.u_addr.ip4.addr = BytesGetLe32(buf->Data + buf->Pos);
+			pvUn.u32 = ip_addr.u_addr.ip4.addr;
+			LLOGD("ipv4 result %s", ipaddr_ntoa(&ip_addr));
 #else
 			ip_addr.ipv4 = BytesGetLe32(buf->Data + buf->Pos);
 			ip_addr.is_ipv6 = 0;
+			pvUn.u32 = ip_addr.ipv4;
+			LLOGD("ipv4 result %d.%d.%d.%d", pvUn.u8[0], pvUn.u8[1], pvUn.u8[2], pvUn.u8[3] );
 #endif
 			buf->Pos += usTemp;
 			if (ttl > 0)
@@ -213,7 +219,7 @@ int32_t dns_get_ip(dns_client_t *client, Buffer_Struct *buf, uint16_t answer_num
 			memcpy(ip_addr.u_addr.ip6.addr, buf->Data + buf->Pos, sizeof( uint32_t ) * 4);
 //			ip_addr.u_addr.ip6.zone = 0;
 			ip_addr.type = IPADDR_TYPE_V6;
-//			LLOGI("%s", ipaddr_ntoa(&ip_addr));
+			LLOGI("ipv6 result %s", ipaddr_ntoa(&ip_addr));
 #else
 			memcpy(ip_addr.ipv6_u8_addr, buf->Data + buf->Pos, sizeof( uint32_t ) * 4);
 			ip_addr.is_ipv6 = 1;