jellyfin/MediaBrowser.Model/Net/IPData.cs
Bond_009 635d67d458 Revert "Use System.Net.IPNetwork"
This reverts commit 117d05d288da1d412159a29c0cb8d5c8259e48ae.
2023-11-14 21:16:33 +01:00

80 lines
2.3 KiB
C#

using System.Net;
using System.Net.Sockets;
using IPNetwork = Microsoft.AspNetCore.HttpOverrides.IPNetwork;
namespace MediaBrowser.Model.Net;
/// <summary>
/// Base network object class.
/// </summary>
public class IPData
{
/// <summary>
/// Initializes a new instance of the <see cref="IPData"/> class.
/// </summary>
/// <param name="address">The <see cref="IPAddress"/>.</param>
/// <param name="subnet">The <see cref="IPNetwork"/>.</param>
/// <param name="name">The interface name.</param>
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;
}
/// <summary>
/// Initializes a new instance of the <see cref="IPData"/> class.
/// </summary>
/// <param name="address">The <see cref="IPAddress"/>.</param>
/// <param name="subnet">The <see cref="IPNetwork"/>.</param>
public IPData(IPAddress address, IPNetwork? subnet)
: this(address, subnet, string.Empty)
{
}
/// <summary>
/// Gets or sets the object's IP address.
/// </summary>
public IPAddress Address { get; set; }
/// <summary>
/// Gets or sets the object's IP address.
/// </summary>
public IPNetwork Subnet { get; set; }
/// <summary>
/// Gets or sets the interface index.
/// </summary>
public int Index { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the network supports multicast.
/// </summary>
public bool SupportsMulticast { get; set; } = false;
/// <summary>
/// Gets or sets the interface name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets the AddressFamily of the object.
/// </summary>
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;
}
}
}
}