getaddrinfo returning only IPv4 address

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

getaddrinfo returning only IPv4 address

antonio
Hi All,
I am using LWIP with LWIPv4/6 (dual-stack enabled).
I used getaddrinfo to resolve some domains, and I am only getting an IPv4.
However, with my .c application on my Laptop connected to the same AP, I get
two addresses

This is what I get when I use a c application on my Laptop.
./ip6 www.google.se
www.google.se: IPv4 = 216.58.211.131
www.google.se: IPv6 = 2a00:1450:400f:80c::2003

While my LWIP application I only get an IPv4, the IPv6 is zero bytes Only.
 dns_resolve www.google.fr
www.google.fr @
216.58.207.195/b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'  

Below is the piece of code where I return the addresses, where rsp is a
struct of type
struct rsp{
  u8_t status; //==0 if we got at least one address, else 1
  u8_t addrlen; //if addr=4 only IPv4 is present, addrlen=16(Only IPv6),
addrlen=20, both are present
  u8_t ipaddr[20]; //first 4 bytes for IPv4 and remaining 16 for IPv6
};
    rsp->addrlen = 0;
    memset(rsp->ipaddr, 0, sizeof rsp->ipaddr);
    for (cur = &addr_list[0]; cur != NULL; cur = cur->ai_next){
        if (cur->ai_family == AF_INET){
            ipaddr_ptr = &(((struct sockaddr_in *)cur->ai_addr)->sin_addr);
            if (rsp->addrlen == 0 || (rsp->addrlen == 16)){
                rsp->status  = 0;
                rsp->addrlen = rsp->addrlen + 4;
                memcpy(&rsp->ipaddr[0], ipaddr_ptr, 4);
            }
        }else if(cur->ai_family == AF_INET6 || cur->ai_family == AF_UNSPEC){
#if LWIP_IPV4 && LWIP_IPV6
            os_printf("%s: %d IPV6\n",__func__, __LINE__);
            ipaddr_ptr = &(((struct sockaddr_in6
*)cur->ai_addr)->sin6_addr);
            if (rsp->addrlen <= 4){
                rsp->status  = 0;
                rsp->addrlen = rsp->addrlen + 16;
                memcpy(&rsp->ipaddr[4], ipaddr_ptr, 16);
                os_printf("IPv6:%s\n", (char*)&rsp->ipaddr[4]);
            }

#endif
        }
        if (rsp->addrlen > 16)
            break;
    }





--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users