// It is possible for an adapter to have multiple
// IPv4 addresses, gateways, and secondary WINS servers
// assigned to the adapter.
// Note that this sample code only prints out the
// first entry for the IP address/mask, gateway,
// and secondary WINS server for each adapter.
// Make an initial call to GetAdaptersInfo to get
// the necessary size into the ulOutBufLen variable
if (GetAdaptersInfo( pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen);
if (pAdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
return 1;
}
if ((dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
pAdapter = pAdapterInfo;
while (pAdapter) {
printf("\tAdapter Name: \t%s\n", pAdapter->AdapterName);
printf("\tAdapter Desc: \t%s\n", pAdapter->Description);
printf("\tAdapter Addr: \t");
for (UINT i = 0; i < pAdapter->AddressLength; i++) {
if (i == (pAdapter->AddressLength - 1))
printf("%.2X\n",(int)pAdapter->Address[i]);
else
printf("%.2X-",(int)pAdapter->Address[i]);
}
printf("\tIP Address: \t%s\n", pAdapter->IpAddressList.IpAddress.String);
printf("\tIP Mask: \t%s\n", pAdapter->IpAddressList.IpMask.String);
if (pAdapter->DhcpEnabled) {
printf("\tDHCP Enabled: Yes\n");
printf("\t\tDHCP Server: \t%s\n", pAdapter->DhcpServer.IpAddress.String);
printf("\tLease Obtained: ");
/* Display local time */
error = _localtime32_s(&newtime, &pAdapter->LeaseObtained);
if (error)
printf("\tInvalid Argument to _localtime32_s\n");
else {
// Convert to an ASCII representation
error = asctime_s(buffer, 32, &newtime);
if (error)
printf("Invalid Argument to asctime_s\n");
else
/* asctime_s returns the string terminated by \n\0 */
printf("%s", buffer);
}
printf("\tLease Expires: ");
error = _localtime32_s(&newtime, &pAdapter->LeaseExpires);
if (error)
printf("Invalid Argument to _localtime32_s\n");
else {
// Convert to an ASCII representation
error = asctime_s(buffer, 32, &newtime);
if (error)
printf("Invalid Argument to asctime_s\n");
else
/* asctime_s returns the string terminated by \n\0 */
printf("%s", buffer);
}
}
else
printf("\tDHCP Enabled: No\n");