static DWORD HandleFlushNeighborsMessage (flush_neighbors_message_t *msg) { typedef NETIOAPI_API (*FlushIpNetTable2Fn) (ADDRESS_FAMILY, NET_IFINDEX); static FlushIpNetTable2Fn flush_fn = NULL; if (msg->family == AF_INET) return FlushIpNetTable (msg->iface.index); if (!flush_fn) { HMODULE iphlpapi = GetModuleHandle (TEXT("iphlpapi.dll")); if (iphlpapi == NULL) return GetLastError (); flush_fn = (FlushIpNetTable2Fn) GetProcAddress (iphlpapi, "FlushIpNetTable2"); if (!flush_fn) { if (GetLastError () == ERROR_PROC_NOT_FOUND) return WSAEPFNOSUPPORT; else return GetLastError (); } } return flush_fn (msg->family, msg->iface.index); }
DWORD InterfaceUtils::ADD(const char *addrString, const char *maskString) { ULONG NTEContext; printf("%d\n", FlushIpNetTable(INTERNET_IFACE_INDEX)); BOOLEAN gotArpResponse = FALSE; //try 5 times for (unsigned int i = 0; i < 2; i++) { if (InterfaceSendARP(addrString) == NO_ERROR) { gotArpResponse = TRUE; break; } Sleep(500); } if (!gotArpResponse) { if (InterfaceAddIPAddress(addrString, maskString, INTERNET_IFACE_INDEX, &NTEContext) == NO_ERROR) { AddEntry(NTEContext); return NO_ERROR; } } return -1; }