2021-11-08 04:47 PM
I have LwIP running on STM32+Cellular modem. The network is fine for IPV4. Now I am enabling IPV6.
I can see my IPV6 address assigned with my IPV4.
However, when I use lwip_getaddrinfo to have DNS query, but lwip_getaddrinfo return failed.
Any hints are really appreciate.
thanks
The code is like below:
const char * googleDNS1="2001:4860:4860::8888";
const char * googleDNS2="2001:4860:4860::8844";
ip6_addr_t addrV6_1, addrV6_2;
int ret1=ip6addr_aton(googleDNS1,&addrV6_1 );
int ret2=ip6addr_aton(googleDNS2,&addrV6_2 );
printf("DNS convert returns %d, %d\r\n", ret1, ret2);
ip_addr_t dns_addr1,dns_addr2 ;
dns_addr1.type=IPADDR_TYPE_V6;
memcpy(&(dns_addr1.u_addr.ip6), &addrV6_1, sizeof(addrV6_1));
dns_setserver(0, &dns_addr1);//google IPV6 primary, 2001:4860:4860::8888
dns_addr2.type=IPADDR_TYPE_V6;
memcpy(&(dns_addr2.u_addr.ip6), &addrV6_2, sizeof(addrV6_2));
dns_setserver(1, &dns_addr2);//google IPV6 primary, 2001:4860:4860::8888
PRINT_PPPOSIF(" our6_ipaddr = %s", ip6addr_ntoa(netif_ip6_addr(pppif, 0)))
///////////////////////////////////////////////////////////////////////////////////////////////////////
memset( &hints, 0, sizeof( hints ) );
hints.ai_family = AF_INET6; /* IPv4 or IPv6 records (don't care). */
hints.ai_socktype = SOCK_STREAM; /* Connection-oriented byte stream. */
hints.ai_protocol = IPPROTO_TCP; /* TCP transport layer protocol only. */
char ports[5];
itoa(port, ports, 10);
int aiErr=0;
if ( ( aiErr = lwip_getaddrinfo( pHostName,
ports,
&hints,
&res ) ) != 0 )
{
DBGLOG(DBG_SUBSYS_IOT_UTILITIES, LOG_ERR, "lwip_getaddrinfo %d", aiErr);
}
tcpSocket = com_socket(res->ai_family,
res->ai_socktype,
res->ai_protocol);
if(tcpSocket<0)
{
DBGLOG(DBG_SUBSYS_IOT_UTILITIES, LOG_ERR, "com_socket return %d, retrying...\r\n",
tcpSocket);
}
if (tcpSocket >= 0)
{
socketStatus = com_connect( tcpSocket, res->ai_addr, res->ai_addrlen);
}
The log is like below:
netif_ip6_addr_set: netif address being changed
netif: IPv6 address 0 of interface pp set to FE80::A817:214E:1443:4B29/0x0hx
netif_ip6_addr_set_state: netif address state being changed
netif: IPv6 address 0 of interface pp set to FE80::A817:214E:1443:4B29/0x0hx
10.234 ppposif UTILS:
10.234 ppposif UTILS: our_ipaddr = 10.215.35.38
10.257 ppposif UTILS: his_ipaddr = 10.64.64.64
10.257 ppposif UTILS: netmask = 255.255.255.255
10.257 ppposif UTILS: dns1 = 2001:4860:4860::8888
10.257 ppposif UTILS: dns2 = 2001:4860:4860::8844
DNS convert returns 1, 1
10.277 ppposif UTILS: our6_ipaddr = FE80::A817:214E:1443:4B29
dns_enqueue: "a2l4ym2rlvj63k-ats.iot.ap-southeast-2.amazonaws.com": use DNS entry 0
udp_bind(ipaddr = 0.0.0.0, port = 62509)
udp_bind: bound to 0.0.0.0, port 62509)
dns_enqueue: "a2l4ym2rlvj63k-ats.iot.ap-southeast-2.amazonaws.com": use DNS pcb 0
dns_send: dns_servers[0] "a2l4ym2rlvj63k-ats.iot.ap-southeast-2.amazonaws.com": request
pbuf_alloc(length=69)
pbuf_alloc(length=69) == 0x24012420
sending DNS request ID 36047 for name "a2l4ym2rlvj63k-ats.iot.ap-southeast-2.amazonaws.com" to server 0
udp_send
pbuf_add_header: old 0x2401247c new 0x24012474 (8)
udp_send: added header in given pbuf 0x24012420
udp_send: sending datagram of length 77
udp_send: UDP packet length 77
inet_chksum_pseudo(): checksumming pbuf 0x24012420 (has next 0)
inet_chksum_pseudo(): pbuf chain lwip_chksum()=c2e5
udp_send: UDP checksum 0x3d1a
udp_send: ip_output_if (,,,,0x11,)
pbuf_add_header: old 0x24012474 new 0x2401244c (40)
ip6_output_if: pp0
netif->output_ip6()
lwip_netconn_do_gethostbyname returns,-5
dns_tmr: dns_check_entries
dns_send: dns_servers[0] "a2l4ym2rlvj63k-ats.iot.ap-southeast-2.amazonaws.com": request
pbuf_alloc(length=69)
pbuf_alloc(length=69) == 0x24012420
sending DNS request ID 36047 for name "a2l4ym2rlvj63k-ats.iot.ap-southeast-2.amazonaws.com" to server 0
udp_send
pbuf_add_header: old 0x2401247c new 0x24012474 (8)
udp_send: added header in given pbuf 0x24012420
udp_send: sending datagram of length 77
udp_send: UDP packet length 77
inet_chksum_pseudo(): checksumming pbuf 0x24012420 (has next 0)
inet_chksum_pseudo(): pbuf chain lwip_chksum()=c2e5
udp_send: UDP checksum 0x3d1a
udp_send: ip_output_if (,,,,0x11,)
pbuf_add_header: old 0x24012474 new 0x2401244c (40)
ip6_output_if: pp0