There are few ways of doing this.
The classic Win32 way is to call GetÂNetworkÂConnectivityÂHint
:
#include <iphlpapi.h> NL_NETWORK_CONNECTIVITY_HINT connectivityHint{}; auto error = GetNetworkConnectivityHint(&connectivityHint); if (error != NO_ERROR) { /* handle the error somehow */ }
The NL_
contains information about the type of network you’re on. We’ll come back to this structure later.
The Windows Runtime way is a little different.
#include <winrt/Windows.Networking.Connectivity.h> auto connection = winrt::Windows::Networking::Connectivity:: NetworkInformation::GetInternetConnectionProfile(); if (!connection) { /* no internet connectivity */ } auto cost = connection.GetConnectionCost();
The NL_
and the ConnectionÂCost
provide roughly the same information.
NL_ |
ConnectionÂCost |
---|---|
ConnectivityÂLevel |
N/A |
ConnectivityÂCost |
NetworkÂCostÂType |
ApproachingÂDataÂLimit |
ApproachingÂDataÂLimit |
OverÂDataÂLimit |
OverÂDataÂLimit |
Roaming |
Roaming |
N/A | BackgroundÂDataÂUsageÂRestricted |
The ConnectivityÂLevel
is N/A for ConnectionÂCost
because the internet connection profile by definition has internet connectivity, so there’s no need for it to tell you.
The NL_
does not tell you whether background data usage is restricted.
The ConnectivityÂCost
/ NetworkÂCostÂType
tells you how much the network costs.
- Unknown: No information available
- Unrestricted: Unlimited
- Fixed: Can use up to a fixed limit
- Variable: Pay by usage
How does windows find out the information to implement these APIs? Is there some protocol for ISPs to communicate their billing policy ?