Arm Mbed OS support forum

Crash on gethostbyname if not main thread

Hi,

I’ve got an issue on using gethostbyname on ethernet interface. It’s crashing if used in the connected callback.
Is this function can be used inside a thread ?

ethernetInterface.set_blocking(false);
ethernetInterface.attach(&EthernetConnectionCallback);
ethernetInterface.set_dhcp(true);

ethernetInterface.connect();

void EthernetConnectionCallback(nsapi_event_t status, intptr_t param)
{
    if (status == NSAPI_EVENT_CONNECTION_STATUS_CHANGE)
    {
        switch (param)
        {
            case NSAPI_STATUS_GLOBAL_UP:
            {
                printf("==================================> Connected.\n");
                
                SocketAddress serverAddress;
                // ========= HERE IS CRASHING
                nsapi_error_t result = ethernetInterface.gethostbyname("myserver.com", &serverAddress);
                printf("gethostbyname result = %s => %d\n", "myserver.com", result);

            }
            break;
            default:
            break;
        }
    }
}

Thanks
Frédéric