using System.Net;
using System.Net.Sockets;
using IPNetwork = Microsoft.AspNetCore.HttpOverrides.IPNetwork;
namespace MediaBrowser.Model.Net;
/// 
/// Base network object class.
/// 
public class IPData
{
    /// 
    /// Initializes a new instance of the  class.
    /// 
    /// The .
    /// The .
    /// The interface name.
    public IPData(IPAddress address, IPNetwork? subnet, string name)
    {
        Address = address;
        Subnet = subnet ?? (address.AddressFamily == AddressFamily.InterNetwork ? new IPNetwork(address, 32) : new IPNetwork(address, 128));
        Name = name;
    }
    /// 
    /// Initializes a new instance of the  class.
    /// 
    /// The .
    /// The .
    public IPData(IPAddress address, IPNetwork? subnet)
        : this(address, subnet, string.Empty)
    {
    }
    /// 
    /// Gets or sets the object's IP address.
    /// 
    public IPAddress Address { get; set; }
    /// 
    /// Gets or sets the object's IP address.
    /// 
    public IPNetwork Subnet { get; set; }
    /// 
    /// Gets or sets the interface index.
    /// 
    public int Index { get; set; }
    /// 
    /// Gets or sets a value indicating whether the network supports multicast.
    /// 
    public bool SupportsMulticast { get; set; } = false;
    /// 
    /// Gets or sets the interface name.
    /// 
    public string Name { get; set; }
    /// 
    /// Gets the AddressFamily of the object.
    /// 
    public AddressFamily AddressFamily
    {
        get
        {
            if (Address.Equals(IPAddress.None))
            {
                return Subnet.Prefix.AddressFamily.Equals(IPAddress.None)
                    ? AddressFamily.Unspecified
                    : Subnet.Prefix.AddressFamily;
            }
            else
            {
                return Address.AddressFamily;
            }
        }
    }
}