/// <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); }