//获取主机网络配置int GetNetConfigInfo ()
{
/* Declare and initialize variables */// 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, and gateway, and// the primary and secondary WINS server for each adapter.
PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter = NULL;
DWORD dwRetVal = 0;
UINT i;
/* variables used to print DHCP time info */struct tm newtime;
char buffer[32];
errno_t error;
char szLogBuffer[512]={
0};
ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO);
pAdapterInfo = (IP_ADAPTER_INFO *) MALLOC(sizeof (IP_ADAPTER_INFO));
if (pAdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
return1;
}
// Make an initial call to GetAdaptersInfo to get// the necessary size into the ulOutBufLen variableif (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");
return1;
}
}
if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) {
pAdapter = pAdapterInfo;
while (pAdapter) {
printf("ComboIndex: %d\n", pAdapter->ComboIndex);
printf("Adapter Name: %s\n", pAdapter->AdapterName);
printf("Adapter Desc: %s\n", pAdapter->Description);
printf("Adapter Addr: ");
for (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]);
}
}