Unicode C
Unicode C
Get Local Network Adapter Addresses
See more Socket/SSL/TLS Examples
Demonstrates Socket.GetAdaptersAddresses, which populates a JsonObject with information about local network adapters, including IPv4 addresses, IPv6 addresses, and MAC addresses.
Tip: Code to parse the returned JSON can be generated with Chilkat's online tool at https://tools.chilkat.io/jsonParse.
Background. This provides a portable way to enumerate the host's network interfaces and their addresses.
Chilkat Unicode C Downloads
#include <C_CkSocketW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkSocketW socket;
HCkJsonObjectW json;
const wchar_t *jsonStr;
success = FALSE;
socket = CkSocketW_Create();
// Populate a JsonObject with information about the local network adapters, including IPv4 addresses,
// IPv6 addresses, and MAC addresses.
json = CkJsonObjectW_Create();
success = CkSocketW_GetAdaptersAddresses(socket,json);
if (success == FALSE) {
wprintf(L"%s\n",CkSocketW_lastErrorText(socket));
CkSocketW_Dispose(socket);
CkJsonObjectW_Dispose(json);
return;
}
CkJsonObjectW_putEmitCompact(json,FALSE);
jsonStr = CkJsonObjectW_emit(json);
wprintf(L"%s\n",jsonStr);
// JSON parsing code for this result can be generated at Chilkat's online tool:
// https://tools.chilkat.io/jsonParse
CkSocketW_Dispose(socket);
CkJsonObjectW_Dispose(json);
}