Question

I tried to get the address info in to structred addrinfo **result .

but I get the below error for the code

error in getaddrinfo: Address family for hostname not supported

code

error = getaddrinfo("fe80::4e80:93ff:fe33:13ff%wlan0", NULL, NULL, &result);
if (error != 0)
{
    fprintf(stderr, "error in getaddrinfo: %s\n", gai_strerror(error));
    exit(EXIT_FAILURE);
}

I am able to ping this address $ping6 fe80::4e80:93ff:fe33:13ff%wlan0

Here is the ifconfig details

wlan0     Link encap:Ethernet  HWaddr 4c:80:93:33:13:ff  
          inet addr:192.168.43.188  Bcast:192.168.43.255  Mask:255.255.255.0
          inet6 addr: fe80::4e80:93ff:fe33:13ff/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1985 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2748 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:950126 (950.1 KB)  TX bytes:684317 (684.3 K

this works when I tried for the IPv4 but I need get the getaddrinfo for ipv6

Était-ce utile?

La solution

When you give NULL as hints, getaddrinfo will automatically use AI_ADDRCONFIG. Usually you'd want that flag set, but when connecting to a link local address is the one case where you don't want it.

I'm guessing you don't have a global IPv6 address configured and AI_ADDRCONFIG therefore selects only IPv4, not IPv6. Providing proper hints is the way to avoid this.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top