/// <summary> /// Gets the current cost of either a machine-wide internet connection, or the first-hop of routing to a specific destination on a /// connection. If destIPaddr is NULL, this method instead returns the cost of the network used for machine-wide Internet connectivity. /// </summary> /// <param name="destIPAddr"> /// The destination IPv4/IPv6 address. If <see langword="null"/>, this method will instead return the cost associated with the /// preferred connection used for machine Internet connectivity. /// </param> /// <returns>The cost of the connection.</returns> public static NLM_CONNECTION_COST GetConnectionCost(IPAddress destIPAddr = null) { var ptr = destIPAddr != null ? new SafeCoTaskMemHandle(destIPAddr.GetAddressBytes()) : SafeCoTaskMemHandle.Null; var cost = NLM_CONNECTION_COST.NLM_CONNECTION_COST_UNKNOWN; (costmgr ?? (costmgr = (INetworkCostManager)Manager))?.GetCost(out cost, (IntPtr)ptr); return(cost); }
/// <summary> /// Gets the data plan status for either a machine-wide internet connection , or the first-hop of routing to a specific destination /// on a connection. If an IPv4/IPv6 address is not specified, this method returns the data plan status of the connection used for /// machine-wide Internet connectivity. /// </summary> /// <param name="destIPAddr"> /// The destination IPv4/IPv6 address. If <see langword="null"/>, this method will instead return the data plan status of the /// connection used for machine-wide Internet connectivity. /// </param> /// <returns> /// An NLM_DATAPLAN_STATUS structure that describes the data plan status associated with a connection used to route to a destination. /// If destIPAddr specifies a tunnel address, the first available data plan status in the interface stack is returned. /// </returns> public static NLM_DATAPLAN_STATUS GetConnectionDataPlanStatus(IPAddress destIPAddr = null) { var ptr = destIPAddr != null ? new SafeCoTaskMemHandle(destIPAddr.GetAddressBytes()) : SafeCoTaskMemHandle.Null; var cost = new NLM_DATAPLAN_STATUS(); (costmgr ?? (costmgr = (INetworkCostManager)Manager))?.GetDataPlanStatus(out cost, (IntPtr)ptr); return(cost); }
/// <summary> /// Gets the data plan status for either a machine-wide internet connection , or the first-hop of routing to a specific destination /// on a connection. If an IPv4/IPv6 address is not specified, this method returns the data plan status of the connection used for /// machine-wide Internet connectivity. /// </summary> /// <param name="destIPAddr"> /// The destination IPv4/IPv6 address. If <see langword="null"/>, this method will instead return the data plan status of the /// connection used for machine-wide Internet connectivity. /// </param> /// <returns> /// An NLM_DATAPLAN_STATUS structure that describes the data plan status associated with a connection used to route to a destination. /// If destIPAddr specifies a tunnel address, the first available data plan status in the interface stack is returned. /// </returns> public static NLM_DATAPLAN_STATUS GetConnectionDataPlanStatus(IPAddress destIPAddr = null) { var addr = NLM_SOCKADDR.FromIPAddress(destIPAddr); var cost = new NLM_DATAPLAN_STATUS(); (costmgr ?? (costmgr = (INetworkCostManager)Manager))?.GetDataPlanStatus(out cost, addr); return(cost); }
/// <summary> /// Gets the current cost of either a machine-wide internet connection, or the first-hop of routing to a specific destination on a /// connection. If destIPaddr is NULL, this method instead returns the cost of the network used for machine-wide Internet connectivity. /// </summary> /// <param name="destIPAddr"> /// The destination IPv4/IPv6 address. If <see langword="null"/>, this method will instead return the cost associated with the /// preferred connection used for machine Internet connectivity. /// </param> /// <returns>The cost of the connection.</returns> public static NLM_CONNECTION_COST GetConnectionCost(IPAddress destIPAddr = null) { var addr = NLM_SOCKADDR.FromIPAddress(destIPAddr); var cost = NLM_CONNECTION_COST.NLM_CONNECTION_COST_UNKNOWN; (costmgr ?? (costmgr = (INetworkCostManager)Manager))?.GetCost(out cost, addr); return(cost); }
public MeteredNetworkManager(ISyncthingManager syncthingManager, INetworkCostManager costManager) { this.syncthingManager = syncthingManager; this.costManager = costManager; // We won't know whether or not Syncthing supports this until it loads if (this.costManager.IsSupported) { this.syncthingManager.StateChanged += this.SyncthingStateChanged; this.syncthingManager.DataLoaded += this.DataLoaded; this.syncthingManager.Devices.DevicePaused += this.DevicePaused; this.syncthingManager.Devices.DeviceResumed += this.DeviceResumed; this.syncthingManager.Devices.DeviceConnected += this.DeviceConnected; this.syncthingManager.Devices.DeviceDisconnected += this.DeviceDisconnected; this.costManager.NetworkCostsChanged += this.NetworkCostsChanged; this.costManager.NetworksChanged += this.NetworksChanged; } }
public static void OneTimeSetup() { mgr = new INetworkListManager(); coster = new INetworkCostManager(); }