I’ve done some more tests, it looks like the DNS for IPv6 is not set correct and the following gethostbyname does not work also:
with both IPv4 and IPv6 enabled in mbed_app.json:
IPv4 address is: 192.168.100.59
IPv6 local link is: fe80::280:e1ff:fe30:3a
gateway address is: 192.168.100.1
netmask is: 255.255.255.0
DNS IPv4: DNS 1: 192.168.100.1
DNS IPv4: DNS 2: 0.58.134.221
The DNS for index=0 is ok, the DNS for index=1 is not valid.
with only IPv6 enabled in mbed_app.json:
IPv4 address is: fe80::280:e1ff:fe30:3a
IPv6 local link is: fe80::280:e1ff:fe30:3a
get_gateway err: -3004
get_netmask err: -3004
DNS IPv6: DNS 1: 2001:4860:4860::8888
DNS IPv6: DNS 2: 80:e130:3a:86dd:6000:0:20:1
I get some ping reply from the first DNS, but on my pc the IPv6 DNS looks quite different:
fd00::464e:6dff:fe52:f02a
The second DNS looks like garbage, is not pingable.
Edit:
ok, the first DNS is a public google address and not my router.
int main() {
printf("Hello from " MBED_STRINGIFY(TARGET_NAME) "\n");
printf("Mbed OS version: %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
SocketAddress sockAddr;
volatile nsapi_error_t err;
// Bring up the ethernet interface
printf("UDP Socket example\n");
if (0 != net.connect()) {
printf("Error connecting\n");
return -1;
}
// Show the network address
net.get_ip_address(&sockAddr);
printf("IPv4 address is: %s\n", sockAddr.get_ip_address() ? sockAddr.get_ip_address() : "No IP");
net.get_ipv6_link_local_address(&sockAddr);
printf("IPv6 local link is: %s\n", sockAddr.get_ip_address() ? sockAddr.get_ip_address() : "No IP");
// get gateway
err = net.get_gateway(&sockAddr);
(err == NSAPI_ERROR_OK) ? printf("gateway address is: %s\n", sockAddr.get_ip_address()) : printf("get_gateway err: %d\n", err);
// get netmask
err = net.get_netmask(&sockAddr);
(err == NSAPI_ERROR_OK) ? printf("netmask is: %s\n", sockAddr.get_ip_address()) : printf("get_netmask err: %d\n", err);
int index = 0;
while(err == NSAPI_ERROR_OK) {
err = net.get_dns_server(index++, &sockAddr, "st0");
switch (sockAddr.get_ip_version()) {
case NSAPI_IPv4: printf("DNS IPv4: "); break;
case NSAPI_IPv6: printf("DNS IPv6: "); break;
default: printf ("DNS IPv unknown: ");
}
(err == NSAPI_ERROR_OK) ? printf("DNS %d: %s\n", index, sockAddr.get_ip_address()) : printf("get DNS err: %d\n", err);
}
UDPSocket sock;
sock.open(&net);
err = net.gethostbyname("sn-1.fritz.box", &sockAddr, NSAPI_IPv6, "st0");
sockAddr.set_port(8888);
(err == NSAPI_ERROR_OK) ? printf("remote address is: %s\n", sockAddr.get_ip_address()) : printf("gethostbyname err: %d\n", err);
}