aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Networking/IPNetwork/IPNetwork.cs
diff options
context:
space:
mode:
authorErwin de Haan <EraYaN@users.noreply.github.com>2019-01-06 21:50:43 +0100
committerErwin de Haan <EraYaN@users.noreply.github.com>2019-01-10 20:38:53 +0100
commitec1f5dc317182582ebff843c9e8a4d5277405469 (patch)
tree6514de336cc9aa94becb3fbd767285dfa61d0b1b /Emby.Server.Implementations/Networking/IPNetwork/IPNetwork.cs
parent3d867c2c46cec39b669bb8647efef677f32b8a8d (diff)
Mayor code cleanup
Add Argument*Exceptions now use proper nameof operators. Added exception messages to quite a few Argument*Exceptions. Fixed rethorwing to be proper syntax. Added a ton of null checkes. (This is only a start, there are about 500 places that need proper null handling) Added some TODOs to log certain exceptions. Fix sln again. Fixed all AssemblyInfo's and added proper copyright (where I could find them) We live in *current year*. Fixed the use of braces. Fixed a ton of properties, and made a fair amount of functions static that should be and can be static. Made more Methods that should be static static. You can now use static to find bad functions! Removed unused variable. And added one more proper XML comment.
Diffstat (limited to 'Emby.Server.Implementations/Networking/IPNetwork/IPNetwork.cs')
-rw-r--r--Emby.Server.Implementations/Networking/IPNetwork/IPNetwork.cs142
1 files changed, 46 insertions, 96 deletions
diff --git a/Emby.Server.Implementations/Networking/IPNetwork/IPNetwork.cs b/Emby.Server.Implementations/Networking/IPNetwork/IPNetwork.cs
index 8d0fb7997..ba9cfff55 100644
--- a/Emby.Server.Implementations/Networking/IPNetwork/IPNetwork.cs
+++ b/Emby.Server.Implementations/Networking/IPNetwork/IPNetwork.cs
@@ -41,44 +41,19 @@ namespace System.Net
/// <summary>
/// Network address
/// </summary>
- public IPAddress Network
- {
- get
- {
-
- return IPNetwork.ToIPAddress(this._network, this._family);
- }
- }
+ public IPAddress Network => IPNetwork.ToIPAddress(this._network, this._family);
/// <summary>
/// Address Family
/// </summary>
- public AddressFamily AddressFamily
- {
- get
- {
- return this._family;
- }
- }
+ public AddressFamily AddressFamily => this._family;
- private BigInteger _netmask
- {
- get
- {
- return IPNetwork.ToUint(this._cidr, this._family);
- }
- }
+ private BigInteger _netmask => IPNetwork.ToUint(this._cidr, this._family);
/// <summary>
/// Netmask
/// </summary>
- public IPAddress Netmask
- {
- get
- {
- return IPNetwork.ToIPAddress(this._netmask, this._family);
- }
- }
+ public IPAddress Netmask => IPNetwork.ToIPAddress(this._netmask, this._family);
private BigInteger _broadcast
{
@@ -171,13 +146,7 @@ namespace System.Net
/// <summary>
/// The CIDR netmask notation
/// </summary>
- public byte Cidr
- {
- get
- {
- return this._cidr;
- }
- }
+ public byte Cidr => this._cidr;
#endregion
@@ -195,7 +164,7 @@ namespace System.Net
int maxCidr = family == Sockets.AddressFamily.InterNetwork ? 32 : 128;
if (cidr > maxCidr)
{
- throw new ArgumentOutOfRangeException("cidr");
+ throw new ArgumentOutOfRangeException(nameof(cidr));
}
this._ipaddress = ipaddress;
@@ -427,7 +396,7 @@ namespace System.Net
{
if (tryParse == false)
{
- throw new ArgumentNullException("ipaddress");
+ throw new ArgumentNullException(nameof(ipaddress));
}
ipnetwork = null;
return;
@@ -437,7 +406,7 @@ namespace System.Net
{
if (tryParse == false)
{
- throw new ArgumentNullException("netmask");
+ throw new ArgumentNullException(nameof(netmask));
}
ipnetwork = null;
return;
@@ -477,7 +446,7 @@ namespace System.Net
{
if (tryParse == false)
{
- throw new ArgumentNullException("network");
+ throw new ArgumentNullException(nameof(network));
}
ipnetwork = null;
return;
@@ -538,7 +507,7 @@ namespace System.Net
{
if (tryParse == false)
{
- throw new ArgumentNullException("ipaddress");
+ throw new ArgumentNullException(nameof(ipaddress));
}
ipnetwork = null;
return;
@@ -548,7 +517,7 @@ namespace System.Net
{
if (tryParse == false)
{
- throw new ArgumentNullException("netmask");
+ throw new ArgumentNullException(nameof(netmask));
}
ipnetwork = null;
return;
@@ -596,7 +565,7 @@ namespace System.Net
{
if (tryParse == false)
{
- throw new ArgumentNullException("ipaddress");
+ throw new ArgumentNullException(nameof(ipaddress));
}
ipnetwork = null;
return;
@@ -680,7 +649,7 @@ namespace System.Net
{
if (tryParse == false)
{
- throw new ArgumentNullException("ipaddress");
+ throw new ArgumentNullException(nameof(ipaddress));
}
uintIpAddress = null;
return;
@@ -751,7 +720,7 @@ namespace System.Net
{
if (tryParse == false)
{
- throw new ArgumentOutOfRangeException("cidr");
+ throw new ArgumentOutOfRangeException(nameof(cidr));
}
uintNetmask = null;
return;
@@ -761,7 +730,7 @@ namespace System.Net
{
if (tryParse == false)
{
- throw new ArgumentOutOfRangeException("cidr");
+ throw new ArgumentOutOfRangeException(nameof(cidr));
}
uintNetmask = null;
return;
@@ -872,7 +841,7 @@ namespace System.Net
{
if (tryParse == false)
{
- throw new ArgumentNullException("netmask");
+ throw new ArgumentNullException(nameof(netmask));
}
cidr = null;
return;
@@ -976,7 +945,7 @@ namespace System.Net
{
if (tryParse == false)
{
- throw new ArgumentOutOfRangeException("cidr");
+ throw new ArgumentOutOfRangeException(nameof(cidr));
}
netmask = null;
return;
@@ -1042,7 +1011,7 @@ namespace System.Net
if (netmask == null)
{
- throw new ArgumentNullException("netmask");
+ throw new ArgumentNullException(nameof(netmask));
}
BigInteger uintNetmask = IPNetwork.ToBigInteger(netmask);
bool valid = IPNetwork.InternalValidNetmask(uintNetmask, netmask.AddressFamily);
@@ -1145,7 +1114,7 @@ namespace System.Net
if (ipaddress == null)
{
- throw new ArgumentNullException("ipaddress");
+ throw new ArgumentNullException(nameof(ipaddress));
}
if (AddressFamily != ipaddress.AddressFamily)
@@ -1174,7 +1143,7 @@ namespace System.Net
if (network2 == null)
{
- throw new ArgumentNullException("network2");
+ throw new ArgumentNullException(nameof(network2));
}
BigInteger uintNetwork = _network;
@@ -1203,7 +1172,7 @@ namespace System.Net
if (network2 == null)
{
- throw new ArgumentNullException("network2");
+ throw new ArgumentNullException(nameof(network2));
}
BigInteger uintNetwork = _network;
@@ -1242,37 +1211,19 @@ namespace System.Net
/// 10.0.0.0/8
/// </summary>
/// <returns></returns>
- public static IPNetwork IANA_ABLK_RESERVED1
- {
- get
- {
- return _iana_ablock_reserved.Value;
- }
- }
+ public static IPNetwork IANA_ABLK_RESERVED1 => _iana_ablock_reserved.Value;
/// <summary>
/// 172.12.0.0/12
/// </summary>
/// <returns></returns>
- public static IPNetwork IANA_BBLK_RESERVED1
- {
- get
- {
- return _iana_bblock_reserved.Value;
- }
- }
+ public static IPNetwork IANA_BBLK_RESERVED1 => _iana_bblock_reserved.Value;
/// <summary>
/// 192.168.0.0/16
/// </summary>
/// <returns></returns>
- public static IPNetwork IANA_CBLK_RESERVED1
- {
- get
- {
- return _iana_cblock_reserved.Value;
- }
- }
+ public static IPNetwork IANA_CBLK_RESERVED1 => _iana_cblock_reserved.Value;
/// <summary>
/// return true if ipaddress is contained in
@@ -1285,7 +1236,7 @@ namespace System.Net
if (ipaddress == null)
{
- throw new ArgumentNullException("ipaddress");
+ throw new ArgumentNullException(nameof(ipaddress));
}
return IPNetwork.IANA_ABLK_RESERVED1.Contains(ipaddress)
@@ -1356,7 +1307,7 @@ namespace System.Net
{
if (trySubnet == false)
{
- throw new ArgumentNullException("network");
+ throw new ArgumentNullException(nameof(network));
}
ipnetworkCollection = null;
return;
@@ -1367,7 +1318,7 @@ namespace System.Net
{
if (trySubnet == false)
{
- throw new ArgumentOutOfRangeException("cidr");
+ throw new ArgumentOutOfRangeException(nameof(cidr));
}
ipnetworkCollection = null;
return;
@@ -1438,7 +1389,7 @@ namespace System.Net
{
if (trySupernet == false)
{
- throw new ArgumentNullException("network1");
+ throw new ArgumentNullException(nameof(network1));
}
supernet = null;
return;
@@ -1448,7 +1399,7 @@ namespace System.Net
{
if (trySupernet == false)
{
- throw new ArgumentNullException("network2");
+ throw new ArgumentNullException(nameof(network2));
}
supernet = null;
return;
@@ -1492,7 +1443,7 @@ namespace System.Net
{
if (trySupernet == false)
{
- throw new ArgumentOutOfRangeException("network");
+ throw new ArgumentOutOfRangeException(nameof(trySupernet), "TrySupernet was false while the first and last networks are not adjacent.");
}
supernet = null;
return;
@@ -1536,8 +1487,7 @@ namespace System.Net
/// 192.168.0.0/24 + 192.168.1.0/24 = 192.168.0.0/23
/// 192.168.0.0/24 + 192.168.1.0/24 + 192.168.2.0/24 + 192.168.3.0/24 = 192.168.0.0/22
/// </summary>
- /// <param name="ipnetworks"></param>
- /// <param name="supernet"></param>
+ /// <param name="ipnetworks">The IP networks</param>
/// <returns></returns>
public static IPNetwork[] Supernet(IPNetwork[] ipnetworks)
{
@@ -1573,7 +1523,7 @@ namespace System.Net
{
if (trySupernet == false)
{
- throw new ArgumentNullException("ipnetworks");
+ throw new ArgumentNullException(nameof(ipnetworks));
}
supernet = null;
return false;
@@ -1684,12 +1634,12 @@ namespace System.Net
if (string.IsNullOrEmpty(start))
{
- throw new ArgumentNullException("start");
+ throw new ArgumentNullException(nameof(start));
}
if (string.IsNullOrEmpty(end))
{
- throw new ArgumentNullException("end");
+ throw new ArgumentNullException(nameof(end));
}
IPAddress startIP;
@@ -1750,7 +1700,7 @@ namespace System.Net
{
if (tryWide == false)
{
- throw new ArgumentNullException("ipnetworks");
+ throw new ArgumentNullException(nameof(ipnetworks));
}
ipnetwork = null;
return;
@@ -1973,7 +1923,7 @@ namespace System.Net
#region IComparable<IPNetwork> Members
- public static Int32 Compare(IPNetwork left, IPNetwork right)
+ public static int Compare(IPNetwork left, IPNetwork right)
{
// two null IPNetworks are equal
if (ReferenceEquals(left, null) && ReferenceEquals(right, null)) return 0;
@@ -1994,12 +1944,12 @@ namespace System.Net
return result;
}
- public Int32 CompareTo(IPNetwork other)
+ public int CompareTo(IPNetwork other)
{
return Compare(this, other);
}
- public Int32 CompareTo(Object obj)
+ public int CompareTo(object obj)
{
// null is at less
if (obj == null) return 1;
@@ -2012,7 +1962,7 @@ namespace System.Net
{
throw new ArgumentException(
"The supplied parameter is an invalid type. Please supply an IPNetwork type.",
- "obj");
+ nameof(obj));
}
// perform the comparision
@@ -2023,17 +1973,17 @@ namespace System.Net
#region IEquatable<IPNetwork> Members
- public static Boolean Equals(IPNetwork left, IPNetwork right)
+ public static bool Equals(IPNetwork left, IPNetwork right)
{
return Compare(left, right) == 0;
}
- public Boolean Equals(IPNetwork other)
+ public bool Equals(IPNetwork other)
{
return Equals(this, other);
}
- public override Boolean Equals(Object obj)
+ public override bool Equals(object obj)
{
return Equals(this, obj as IPNetwork);
}
@@ -2042,22 +1992,22 @@ namespace System.Net
#region Operators
- public static Boolean operator ==(IPNetwork left, IPNetwork right)
+ public static bool operator ==(IPNetwork left, IPNetwork right)
{
return Equals(left, right);
}
- public static Boolean operator !=(IPNetwork left, IPNetwork right)
+ public static bool operator !=(IPNetwork left, IPNetwork right)
{
return !Equals(left, right);
}
- public static Boolean operator <(IPNetwork left, IPNetwork right)
+ public static bool operator <(IPNetwork left, IPNetwork right)
{
return Compare(left, right) < 0;
}
- public static Boolean operator >(IPNetwork left, IPNetwork right)
+ public static bool operator >(IPNetwork left, IPNetwork right)
{
return Compare(left, right) > 0;
}