VOID __stdcall KprNetworkInterfaceCallback(PVOID context, PMIB_IPINTERFACE_ROW interfaceRow, MIB_NOTIFICATION_TYPE notificationType) { int ip; FskErr err = kFskErrNone; IP_ADAPTER_INFO *adapters = NULL; DWORD result; DWORD size = 15000; IP_ADAPTER_INFO *adapter; IP_ADDR_STRING *address; for (ip = 0; ip < 3; ip++) { err = FskMemPtrNew(size, &adapters); result = GetAdaptersInfo(adapters, &size); if (ERROR_BUFFER_OVERFLOW == result) { FskMemPtrDispose(adapters); adapters = NULL; } else break; } if (ERROR_SUCCESS == result) { for (adapter = adapters ; NULL != adapter ; adapter = adapter->Next) { for (address = &adapter->IpAddressList; address; address = address->Next) { if (FskStrLen(address->IpAddress.String) == 0) continue; FskNetStringToIPandPort(address->IpAddress.String, &ip, NULL); if (0x7f000001 != ip) KprNetworkInterfaceMark(ip, adapter->AdapterName); } } KprNetworkInterfaceSweep(); } FskMemPtrDispose(adapters); }
// --------------------------------------------------------------------- static FskErr sFskNetInterfaceEnumerate(FskNetInterfaceRecord **interfaceList) { DWORD bytes, result; FskNetInterfaceRecord *nir; IP_ADAPTER_INFO *adapters = NULL, *pAdapter; FskErr err = kFskErrNone; *interfaceList = NULL; result = GetAdaptersInfo(NULL, &bytes); if (result == ERROR_NO_DATA) return kFskErrNetworkInterfaceError; if (( ERROR_SUCCESS != result ) && (ERROR_BUFFER_OVERFLOW != result)) return kFskErrNetworkInterfaceError; FskMemPtrNew(bytes, (FskMemPtr*)&adapters); result = GetAdaptersInfo(adapters, &bytes); if ( ERROR_SUCCESS != result ) BAIL(kFskErrNetworkInterfaceError); for (pAdapter = adapters ; NULL != pAdapter ; pAdapter = pAdapter->Next){ const IP_ADDR_STRING* ip = &pAdapter->IpAddressList; // NOTE: there may be more than one IP per interface - this does not handle that case FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation,"Network Adapter %s", ip->IpAddress.String); // check for ppp, 0.0.0.0, etc. if (pAdapter->Type == IF_TYPE_PPP) continue; if (FskStrCompare("0.0.0.0", ip->IpAddress.String) == 0) continue; FskMemPtrNewClear(sizeof(FskNetInterfaceRecord), (FskMemPtr*)&nir); if (nir) { UInt32 j; nir->name = FskStrDoCopy(pAdapter->AdapterName); if (6 == pAdapter->AddressLength) { for(j = 0; j < pAdapter->AddressLength; j++) nir->MAC[j] = pAdapter->Address[j]; } FskNetStringToIPandPort(ip->IpAddress.String, &nir->ip, NULL); FskNetStringToIPandPort(ip->IpMask.String, &nir->netmask, NULL); nir->status = 1; FskListAppend((FskList *)interfaceList, nir); } } // add loop back I/F to total number of IP addresses FskMemPtrNewClear(sizeof(FskNetInterfaceRecord), (FskMemPtr*)&nir); if (nir) { int j; nir->name = FskStrDoCopy("localhost"); for(j = 0; j < 6; j++) nir->MAC[j] = 0; nir->ip = FskNetMakeIP(127,0,0,1); nir->netmask = 0xff000000; nir->status = 1; FskListAppend((FskList *)interfaceList, nir); } bail: FskMemPtrDispose(adapters); return err; }