using System;
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
using Microsoft.AspNetCore.Http;
namespace MediaBrowser.Common.Net
{
///
/// Interface for the NetworkManager class.
///
public interface INetworkManager
{
///
/// Event triggered on network changes.
///
event EventHandler NetworkChanged;
///
/// Gets a value indicating whether IPv6 is enabled.
///
bool IsIpv6Enabled { get; }
///
/// Gets a value indicating whether IPv4 is enabled.
///
bool IsIpv4Enabled { get; }
///
/// Calculates the list of interfaces to use for Kestrel.
///
/// A List{IPData} object containing all the interfaces to bind.
/// If all the interfaces are specified, and none are excluded, it returns zero items
/// to represent any address.
/// When false, return or for all interfaces.
IReadOnlyList GetAllBindInterfaces(bool individualInterfaces = false);
///
/// Returns a list containing the loopback interfaces.
///
/// List{IPData}.
IReadOnlyList GetLoopbacks();
///
/// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo)
/// If no bind addresses are specified, an internal interface address is selected.
/// The priority of selection is as follows:-
///
/// The value contained in the startup parameter --published-server-url.
///
/// If the user specified custom subnet overrides, the correct subnet for the source address.
///
/// If the user specified bind interfaces to use:-
/// The bind interface that contains the source subnet.
/// The first bind interface specified that suits best first the source's endpoint. eg. external or internal.
///
/// If the source is from a public subnet address range and the user hasn't specified any bind addresses:-
/// The first public interface that isn't a loopback and contains the source subnet.
/// The first public interface that isn't a loopback. Priority is given to interfaces with gateways.
/// An internal interface if there are no public ip addresses.
///
/// If the source is from a private subnet address range and the user hasn't specified any bind addresses:-
/// The first private interface that contains the source subnet.
/// The first private interface that isn't a loopback. Priority is given to interfaces with gateways.
///
/// If no interfaces meet any of these criteria, then a loopback address is returned.
///
/// Interface that have been specifically excluded from binding are not used in any of the calculations.
///
/// Source of the request.
/// Optional port returned, if it's part of an override.
/// IP Address to use, or loopback address if all else fails.
string GetBindInterface(HttpRequest source, out int? port);
///
/// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo)
/// If no bind addresses are specified, an internal interface address is selected.
/// (See .
///
/// IP address of the request.
/// Optional port returned, if it's part of an override.
/// IP Address to use, or loopback address if all else fails.
string GetBindInterface(IPAddress source, out int? port);
///
/// Retrieves the bind address to use in system url's. (Server Discovery, PlayTo, LiveTV, SystemInfo)
/// If no bind addresses are specified, an internal interface address is selected.
/// (See .
///
/// Source of the request.
/// Optional port returned, if it's part of an override.
/// IP Address to use, or loopback address if all else fails.
string GetBindInterface(string source, out int? port);
///
/// Get a list of all the MAC addresses associated with active interfaces.
///
/// List of MAC addresses.
IReadOnlyList GetMacAddresses();
///
/// Returns true if the address is part of the user defined LAN.
/// The configuration option TrustIP6Interfaces overrides this functions behaviour.
///
/// IP to check.
/// True if endpoint is within the LAN range.
bool IsInLocalNetwork(string address);
///
/// Returns true if the address is part of the user defined LAN.
/// The configuration option TrustIP6Interfaces overrides this functions behaviour.
///
/// IP to check.
/// True if endpoint is within the LAN range.
bool IsInLocalNetwork(IPAddress address);
///
/// Attempts to convert the interface name to an IP address.
/// eg. "eth1", or "enp3s5".
///
/// Interface name.
/// Resultant object's ip addresses, if successful.
/// Success of the operation.
bool TryParseInterface(string intf, out List? result);
///
/// Returns all the internal bind interface addresses.
///
/// An internal list of interfaces addresses.
IReadOnlyList GetInternalBindAddresses();
///
/// Checks to see if has access.
///
/// IP Address of client.
/// True if has access, otherwise false.
bool HasRemoteAccess(IPAddress remoteIp);
}
}