Sample code for 30+ languages & platforms
Unicode C

Resolve a Hostname to an IP Address

See more Socket/SSL/TLS Examples

Demonstrates Socket.DnsLookup, which resolves a hostname and returns one numeric IP address.

Background. A maxWaitMs of 0 waits indefinitely; a positive value bounds the wait. Resolved results may be served from Chilkat's process-wide DNS cache.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkSocketW.h>

void ChilkatSample(void)
    {
    HCkSocketW socket;
    const wchar_t *ipAddress;

    socket = CkSocketW_Create();

    //  Resolve a hostname to a numeric IP address, waiting up to 5 seconds.
    ipAddress = CkSocketW_dnsLookup(socket,L"example.com",5000);
    if (CkSocketW_getLastMethodSuccess(socket) == FALSE) {
        wprintf(L"%s\n",CkSocketW_lastErrorText(socket));
        CkSocketW_Dispose(socket);
        return;
    }

    wprintf(L"Resolved IP address: %s\n",ipAddress);


    CkSocketW_Dispose(socket);

    }