Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.2 KiB

  1. #pragma once
  2. #include "winsock2.h"
  3. #include <stllock.h>
  4. class CIpAddressMonitor
  5. /*
  6. This is a class to monitor the number of active networks on the local machine.
  7. It does so by using the Winsock 2.0 SIO_ADDRESS_LIST_CHANGE ioctl. Currently it
  8. only monitors IP addresses, but it could monitor other networks that conform to
  9. the Winsock model.
  10. */
  11. {
  12. public:
  13. CIpAddressMonitor();
  14. ~CIpAddressMonitor();
  15. typedef void (CALLBACK * LISTEN_CALLBACK_FN)( PVOID arg );
  16. HRESULT
  17. Listen(
  18. LISTEN_CALLBACK_FN fn,
  19. PVOID arg
  20. );
  21. void CancelListen();
  22. bool IsListening();
  23. long GetAddressCount();
  24. protected:
  25. CCritSec m_Mutex;
  26. long m_AddressCount;
  27. SOCKET m_ListenSocket;
  28. OVERLAPPED m_Overlapped;
  29. LISTEN_CALLBACK_FN m_CallbackFn;
  30. PVOID m_CallbackArg;
  31. //--------------------------------------------------------------------
  32. HRESULT CreateListenSocket();
  33. HRESULT UpdateAddressCount();
  34. static void CALLBACK
  35. ListenCompletionRoutine(
  36. IN DWORD dwError,
  37. IN DWORD cbTransferred,
  38. IN LPWSAOVERLAPPED lpOverlapped,
  39. IN DWORD dwFlags
  40. );
  41. };