There are few ways of doing this.
The classic Win32 way is to call GetNetworkConnectivityHint:
#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 ConnectionCost provide roughly the same information.
NL_ |
ConnectionCost |
|---|---|
ConnectivityLevel |
N/A |
ConnectivityCost |
NetworkCostType |
ApproachingDataLimit |
ApproachingDataLimit |
OverDataLimit |
OverDataLimit |
Roaming |
Roaming |
| N/A | BackgroundDataUsageRestricted |
The ConnectivityLevel is N/A for ConnectionCost 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 ConnectivityCost / NetworkCostType 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 ?