Gethostbyname() question

I’ve started with an UDP example on a NUCLEO_F746ZG and it worked fine from the beginning:

The IP address and gateway comes over dhcp and the gethostbyname(“”) is working. Now I replace the address by a pc name in my LAN and I get an error -3009:

err = net.gethostbyname("", &sockAddr, NSAPI_IPv4);

finally, I got it only working by adding also the network name (which took also some time to figure it out):

err = net.gethostbyname("", &sockAddr, NSAPI_IPv4, "st0");

what is the reason for this? Also a


did not help. When I query the DNS, I get also my router IP as correct result.

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:
IPv6 local link is: fe80::280:e1ff:fe30:3a
gateway address is:
netmask is:
DNS IPv4: DNS 1:
DNS IPv4: DNS 2:

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:
The second DNS looks like garbage, is not pingable.

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
    printf("IPv4 address is: %s\n", sockAddr.get_ip_address() ? sockAddr.get_ip_address() : "No IP");
    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;;

    err = net.gethostbyname("", &sockAddr, NSAPI_IPv6, "st0");
    (err == NSAPI_ERROR_OK) ? printf("remote address is: %s\n", sockAddr.get_ip_address()) : printf("gethostbyname err: %d\n", err);