1

I need to capture Network interface changes i.e. network connect/disconnect events in a C++ based Windows service. The Windows API function NotifyIpInterfaceChange() does capture all the needed events, but the issue is that it also captures/fires many more "dummy"(events which are not related to any network interface changes) events. And the number of extra events captured do not have any difference in the values of MIB_IPINTERFACE_ROW parameters.

As per this it seems that the event is raised for changes in network speed, but there is no information about the threshold of speed changes, nor the speed changes can be checked in the event raised.

There is no consistent pattern ( in terms of the number of extra events, time of this events or a specific network connection which fires this extra events) which can be used for further troubleshooting

Function which registers the callback on Windows Service start -

bool NetworkInterfaceHelper::initNotification(PVOID Callback,PVOID CallerContext,HANDLE NotificationHandle) {
    PIPINTERFACE_CHANGE_CALLBACK interfaceChangeCallback = (PIPINTERFACE_CHANGE_CALLBACK)Callback;
    return 
        NotifyIpInterfaceChange(
            TARGET_FAMILIY, 
            interfaceChangeCallback, 
            CallerContext, 
            INITIAL_NOTIFICATION,
            &NotificationHandle
        ) == NO_ERROR;
}

I understand that there might be alternative method(s) of detecting network interface changes using C++, but I need to fix this, if possible, using the existing code-base. I have referred I need a event to detect Internet connect/disconnect, but that will need a code re-write which is not desirable, if there is a fix available for the current use case.

Environment: Windows-7 64-bit and Windows 10 64-bit. C++ Windows service. Visual Studio 2017 Community edition. Windows SDK Version 10.0.16299.0

Sanjay Karia
  • 309
  • 1
  • 3
  • 13

1 Answers1

0

Filter/differentiate them in the callback function(MIB_IPINTERFACE_ROW.connected).

The NotifyIpInterfaceChange function:

registers to be notified for changes to all IP interfaces, IPv4 interfaces, or IPv6 interfaces on a local computer.

Drake Wu
  • 6,927
  • 1
  • 7
  • 30