Skip to content

Instantly share code, notes, and snippets.

@ssrlive
Created November 4, 2020 10:55
Show Gist options
  • Save ssrlive/0a86f78f3fd2f02461358bb273f7fb80 to your computer and use it in GitHub Desktop.
Save ssrlive/0a86f78f3fd2f02461358bb273f7fb80 to your computer and use it in GitHub Desktop.
monitor windows network status
#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <windows.h>
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
void main()
{
OVERLAPPED overlap;
DWORD ret;
HANDLE hand = NULL;
overlap.hEvent = WSACreateEvent();
ret = NotifyAddrChange(&hand, &overlap);
if (ret != NO_ERROR)
{
if (WSAGetLastError() != WSA_IO_PENDING)
{
printf("NotifyAddrChange error...%d\n", WSAGetLastError());
return;
}
}
if ( WaitForSingleObject(overlap.hEvent, INFINITE) == WAIT_OBJECT_0 )
printf("IP Address table changed..\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment