| | 1 | | using System.Net; |
| | 2 | | using System.Net.Sockets; |
| | 3 | | using IPNetwork = Microsoft.AspNetCore.HttpOverrides.IPNetwork; |
| | 4 | |
|
| | 5 | | namespace MediaBrowser.Model.Net; |
| | 6 | |
|
| | 7 | | /// <summary> |
| | 8 | | /// Base network object class. |
| | 9 | | /// </summary> |
| | 10 | | public class IPData |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Initializes a new instance of the <see cref="IPData"/> class. |
| | 14 | | /// </summary> |
| | 15 | | /// <param name="address">The <see cref="IPAddress"/>.</param> |
| | 16 | | /// <param name="subnet">The <see cref="IPNetwork"/>.</param> |
| | 17 | | /// <param name="name">The interface name.</param> |
| | 18 | | public IPData(IPAddress address, IPNetwork? subnet, string name) |
| | 19 | | { |
| 207 | 20 | | Address = address; |
| 207 | 21 | | Subnet = subnet ?? (address.AddressFamily == AddressFamily.InterNetwork ? new IPNetwork(address, 32) : new IPNet |
| 207 | 22 | | Name = name; |
| 207 | 23 | | } |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// Initializes a new instance of the <see cref="IPData"/> class. |
| | 27 | | /// </summary> |
| | 28 | | /// <param name="address">The <see cref="IPAddress"/>.</param> |
| | 29 | | /// <param name="subnet">The <see cref="IPNetwork"/>.</param> |
| | 30 | | public IPData(IPAddress address, IPNetwork? subnet) |
| 34 | 31 | | : this(address, subnet, string.Empty) |
| | 32 | | { |
| 34 | 33 | | } |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// Gets or sets the object's IP address. |
| | 37 | | /// </summary> |
| | 38 | | public IPAddress Address { get; set; } |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// Gets or sets the object's IP address. |
| | 42 | | /// </summary> |
| | 43 | | public IPNetwork Subnet { get; set; } |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// Gets or sets the interface index. |
| | 47 | | /// </summary> |
| | 48 | | public int Index { get; set; } |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// Gets or sets a value indicating whether the network supports multicast. |
| | 52 | | /// </summary> |
| | 53 | | public bool SupportsMulticast { get; set; } = false; |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// Gets or sets the interface name. |
| | 57 | | /// </summary> |
| | 58 | | public string Name { get; set; } |
| | 59 | |
|
| | 60 | | /// <summary> |
| | 61 | | /// Gets the AddressFamily of the object. |
| | 62 | | /// </summary> |
| | 63 | | public AddressFamily AddressFamily |
| | 64 | | { |
| | 65 | | get |
| | 66 | | { |
| 159 | 67 | | if (Address.Equals(IPAddress.None)) |
| | 68 | | { |
| 0 | 69 | | return Subnet.Prefix.AddressFamily.Equals(IPAddress.None) |
| 0 | 70 | | ? AddressFamily.Unspecified |
| 0 | 71 | | : Subnet.Prefix.AddressFamily; |
| | 72 | | } |
| | 73 | | else |
| | 74 | | { |
| 159 | 75 | | return Address.AddressFamily; |
| | 76 | | } |
| | 77 | | } |
| | 78 | | } |
| | 79 | | } |