C
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 C Downloads
#include <C_CkSocket.h>
void ChilkatSample(void)
{
HCkSocket socket;
const char *ipAddress;
socket = CkSocket_Create();
// Resolve a hostname to a numeric IP address, waiting up to 5 seconds.
ipAddress = CkSocket_dnsLookup(socket,"example.com",5000);
if (CkSocket_getLastMethodSuccess(socket) == FALSE) {
printf("%s\n",CkSocket_lastErrorText(socket));
CkSocket_Dispose(socket);
return;
}
printf("Resolved IP address: %s\n",ipAddress);
CkSocket_Dispose(socket);
}