diff options
Diffstat (limited to 'Emby.Server.Implementations/Networking')
5 files changed, 219 insertions, 315 deletions
diff --git a/Emby.Server.Implementations/Networking/IPNetwork/BigIntegerExt.cs b/Emby.Server.Implementations/Networking/IPNetwork/BigIntegerExt.cs index afb202fa3..447cbf403 100644 --- a/Emby.Server.Implementations/Networking/IPNetwork/BigIntegerExt.cs +++ b/Emby.Server.Implementations/Networking/IPNetwork/BigIntegerExt.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; namespace System.Net { @@ -7,7 +7,7 @@ namespace System.Net using System.Text; /// <summary> - /// Extension methods to convert <see cref="System.Numerics.BigInteger"/> + /// Extension methods to convert <see cref="BigInteger"/> /// instances to hexadecimal, octal, and binary strings. /// </summary> public static class BigIntegerExtensions @@ -17,7 +17,7 @@ namespace System.Net /// </summary> /// <param name="bigint">A <see cref="BigInteger"/>.</param> /// <returns> - /// A <see cref="System.String"/> containing a binary + /// A <see cref="string"/> containing a binary /// representation of the supplied <see cref="BigInteger"/>. /// </returns> public static string ToBinaryString(this BigInteger bigint) @@ -54,7 +54,7 @@ namespace System.Net /// </summary> /// <param name="bigint">A <see cref="BigInteger"/>.</param> /// <returns> - /// A <see cref="System.String"/> containing a hexadecimal + /// A <see cref="string"/> containing a hexadecimal /// representation of the supplied <see cref="BigInteger"/>. /// </returns> public static string ToHexadecimalString(this BigInteger bigint) @@ -67,7 +67,7 @@ namespace System.Net /// </summary> /// <param name="bigint">A <see cref="BigInteger"/>.</param> /// <returns> - /// A <see cref="System.String"/> containing an octal + /// A <see cref="string"/> containing an octal /// representation of the supplied <see cref="BigInteger"/>. /// </returns> public static string ToOctalString(this BigInteger bigint) @@ -122,28 +122,28 @@ namespace System.Net } /// <summary> - /// + /// /// Reverse a Positive BigInteger ONLY /// Bitwise ~ operator - /// + /// /// Input : FF FF FF FF /// Width : 4 - /// Result : 00 00 00 00 - /// - /// + /// Result : 00 00 00 00 + /// + /// /// Input : 00 00 00 00 /// Width : 4 - /// Result : FF FF FF FF - /// + /// Result : FF FF FF FF + /// /// Input : FF FF FF FF /// Width : 8 /// Result : FF FF FF FF 00 00 00 00 - /// - /// + /// + /// /// Input : 00 00 00 00 /// Width : 8 /// Result : FF FF FF FF FF FF FF FF - /// + /// /// </summary> /// <param name="input"></param> /// <param name="width"></param> @@ -165,4 +165,4 @@ namespace System.Net } } -}
\ No newline at end of file +} diff --git a/Emby.Server.Implementations/Networking/IPNetwork/IPAddressCollection.cs b/Emby.Server.Implementations/Networking/IPNetwork/IPAddressCollection.cs index 2b31a0a32..c5853135c 100644 --- a/Emby.Server.Implementations/Networking/IPNetwork/IPAddressCollection.cs +++ b/Emby.Server.Implementations/Networking/IPNetwork/IPAddressCollection.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using System.Collections.Generic; using System.Numerics; @@ -19,13 +19,7 @@ namespace System.Net #region Count, Array, Enumerator - public BigInteger Count - { - get - { - return this._ipnetwork.Total; - } - } + public BigInteger Count => this._ipnetwork.Total; public IPAddress this[BigInteger i] { @@ -33,10 +27,10 @@ namespace System.Net { if (i >= this.Count) { - throw new ArgumentOutOfRangeException("i"); + throw new ArgumentOutOfRangeException(nameof(i)); } byte width = this._ipnetwork.AddressFamily == Sockets.AddressFamily.InterNetwork ? (byte)32 : (byte)128; - IPNetworkCollection ipn = this._ipnetwork.Subnet(width); + var ipn = this._ipnetwork.Subnet(width); return ipn[i].Network; } } @@ -57,10 +51,7 @@ namespace System.Net #region IEnumerator<IPNetwork> Members - public IPAddress Current - { - get { return this[this._enumerator]; } - } + public IPAddress Current => this[this._enumerator]; #endregion @@ -76,10 +67,7 @@ namespace System.Net #region IEnumerator Members - object IEnumerator.Current - { - get { return this.Current; } - } + object IEnumerator.Current => this.Current; public bool MoveNext() { @@ -101,4 +89,4 @@ namespace System.Net #endregion } -}
\ No newline at end of file +} diff --git a/Emby.Server.Implementations/Networking/IPNetwork/IPNetwork.cs b/Emby.Server.Implementations/Networking/IPNetwork/IPNetwork.cs index 8d0fb7997..16f39daf7 100644 --- a/Emby.Server.Implementations/Networking/IPNetwork/IPNetwork.cs +++ b/Emby.Server.Implementations/Networking/IPNetwork/IPNetwork.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Net.Sockets; using System.Numerics; @@ -7,7 +7,7 @@ using System.Text.RegularExpressions; namespace System.Net { /// <summary> - /// IP Network utility class. + /// IP Network utility class. /// Use IPNetwork.Parse to create instances. /// </summary> public class IPNetwork : IComparable<IPNetwork> @@ -33,7 +33,7 @@ namespace System.Net { get { - BigInteger uintNetwork = this._ipaddress & this._netmask; + var uintNetwork = this._ipaddress & this._netmask; return uintNetwork; } } @@ -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 { @@ -86,7 +61,7 @@ namespace System.Net { int width = this._family == Sockets.AddressFamily.InterNetwork ? 4 : 16; - BigInteger uintBroadcast = this._network + this._netmask.PositiveReverse(width); + var uintBroadcast = this._network + this._netmask.PositiveReverse(width); return uintBroadcast; } } @@ -113,7 +88,7 @@ namespace System.Net { get { - BigInteger fisrt = this._family == Sockets.AddressFamily.InterNetworkV6 + var fisrt = this._family == Sockets.AddressFamily.InterNetworkV6 ? this._network : (this.Usable <= 0) ? this._network : this._network + 1; return IPNetwork.ToIPAddress(fisrt, this._family); @@ -127,7 +102,7 @@ namespace System.Net { get { - BigInteger last = this._family == Sockets.AddressFamily.InterNetworkV6 + var last = this._family == Sockets.AddressFamily.InterNetworkV6 ? this._broadcast : (this.Usable <= 0) ? this._network : this._broadcast - 1; return IPNetwork.ToIPAddress(last, this._family); @@ -147,8 +122,8 @@ namespace System.Net return this.Total; } byte[] mask = new byte[] { 0xff, 0xff, 0xff, 0xff, 0x00 }; - BigInteger bmask = new BigInteger(mask); - BigInteger usableIps = (_cidr > 30) ? 0 : ((bmask >> _cidr) - 1); + var bmask = new BigInteger(mask); + var usableIps = (_cidr > 30) ? 0 : ((bmask >> _cidr) - 1); return usableIps; } } @@ -162,7 +137,7 @@ namespace System.Net { int max = this._family == Sockets.AddressFamily.InterNetwork ? 32 : 128; - BigInteger count = BigInteger.Pow(2, (max - _cidr)); + var count = BigInteger.Pow(2, (max - _cidr)); return count; } } @@ -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; @@ -210,7 +179,7 @@ namespace System.Net /// <summary> /// 192.168.168.100 - 255.255.255.0 - /// + /// /// Network : 192.168.168.0 /// Netmask : 255.255.255.0 /// Cidr : 24 @@ -231,7 +200,7 @@ namespace System.Net /// <summary> /// 192.168.168.100/24 - /// + /// /// Network : 192.168.168.0 /// Netmask : 255.255.255.0 /// Cidr : 24 @@ -253,7 +222,7 @@ namespace System.Net /// <summary> /// 192.168.168.100 255.255.255.0 - /// + /// /// Network : 192.168.168.0 /// Netmask : 255.255.255.0 /// Cidr : 24 @@ -276,7 +245,7 @@ namespace System.Net /// <summary> /// 192.168.0.1/24 /// 192.168.0.1 255.255.255.0 - /// + /// /// Network : 192.168.0.0 /// Netmask : 255.255.255.0 /// Cidr : 24 @@ -303,7 +272,7 @@ namespace System.Net /// <summary> /// 192.168.168.100 - 255.255.255.0 - /// + /// /// Network : 192.168.168.0 /// Netmask : 255.255.255.0 /// Cidr : 24 @@ -329,7 +298,7 @@ namespace System.Net /// <summary> /// 192.168.168.100/24 - /// + /// /// Network : 192.168.168.0 /// Netmask : 255.255.255.0 /// Cidr : 24 @@ -354,7 +323,7 @@ namespace System.Net /// <summary> /// 192.168.0.1/24 /// 192.168.0.1 255.255.255.0 - /// + /// /// Network : 192.168.0.0 /// Netmask : 255.255.255.0 /// Cidr : 24 @@ -379,7 +348,7 @@ namespace System.Net /// <summary> /// 192.168.0.1/24 /// 192.168.0.1 255.255.255.0 - /// + /// /// Network : 192.168.0.0 /// Netmask : 255.255.255.0 /// Cidr : 24 @@ -409,7 +378,7 @@ namespace System.Net /// <summary> /// 192.168.168.100 - 255.255.255.0 - /// + /// /// Network : 192.168.168.0 /// Netmask : 255.255.255.0 /// Cidr : 24 @@ -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; @@ -520,7 +489,7 @@ namespace System.Net /// <summary> /// 192.168.168.100 255.255.255.0 - /// + /// /// Network : 192.168.168.0 /// Netmask : 255.255.255.0 /// Cidr : 24 @@ -538,7 +507,7 @@ namespace System.Net { if (tryParse == false) { - throw new ArgumentNullException("ipaddress"); + throw new ArgumentNullException(nameof(ipaddress)); } ipnetwork = null; return; @@ -548,15 +517,14 @@ namespace System.Net { if (tryParse == false) { - throw new ArgumentNullException("netmask"); + throw new ArgumentNullException(nameof(netmask)); } ipnetwork = null; return; } - BigInteger uintIpAddress = IPNetwork.ToBigInteger(ipaddress); - byte? cidr2 = null; - bool parsed = IPNetwork.TryToCidr(netmask, out cidr2); + var uintIpAddress = IPNetwork.ToBigInteger(ipaddress); + bool parsed = IPNetwork.TryToCidr(netmask, out var cidr2); if (parsed == false) { if (tryParse == false) @@ -568,7 +536,7 @@ namespace System.Net } byte cidr = (byte)cidr2; - IPNetwork ipnet = new IPNetwork(uintIpAddress, ipaddress.AddressFamily, cidr); + var ipnet = new IPNetwork(uintIpAddress, ipaddress.AddressFamily, cidr); ipnetwork = ipnet; return; @@ -578,7 +546,7 @@ namespace System.Net /// <summary> /// 192.168.168.100/24 - /// + /// /// Network : 192.168.168.0 /// Netmask : 255.255.255.0 /// Cidr : 24 @@ -596,7 +564,7 @@ namespace System.Net { if (tryParse == false) { - throw new ArgumentNullException("ipaddress"); + throw new ArgumentNullException(nameof(ipaddress)); } ipnetwork = null; return; @@ -646,8 +614,7 @@ namespace System.Net /// <returns></returns> public static BigInteger ToBigInteger(IPAddress ipaddress) { - BigInteger? uintIpAddress = null; - IPNetwork.InternalToBigInteger(false, ipaddress, out uintIpAddress); + IPNetwork.InternalToBigInteger(false, ipaddress, out var uintIpAddress); return (BigInteger)uintIpAddress; } @@ -661,8 +628,7 @@ namespace System.Net /// <returns></returns> public static bool TryToBigInteger(IPAddress ipaddress, out BigInteger? uintIpAddress) { - BigInteger? uintIpAddress2 = null; - IPNetwork.InternalToBigInteger(true, ipaddress, out uintIpAddress2); + IPNetwork.InternalToBigInteger(true, ipaddress, out var uintIpAddress2); bool parsed = (uintIpAddress2 != null); uintIpAddress = uintIpAddress2; return parsed; @@ -680,7 +646,7 @@ namespace System.Net { if (tryParse == false) { - throw new ArgumentNullException("ipaddress"); + throw new ArgumentNullException(nameof(ipaddress)); } uintIpAddress = null; return; @@ -712,9 +678,7 @@ namespace System.Net /// <returns></returns> public static BigInteger ToUint(byte cidr, AddressFamily family) { - - BigInteger? uintNetmask = null; - IPNetwork.InternalToBigInteger(false, cidr, family, out uintNetmask); + IPNetwork.InternalToBigInteger(false, cidr, family, out var uintNetmask); return (BigInteger)uintNetmask; } @@ -726,9 +690,7 @@ namespace System.Net /// <returns></returns> public static bool TryToUint(byte cidr, AddressFamily family, out BigInteger? uintNetmask) { - - BigInteger? uintNetmask2 = null; - IPNetwork.InternalToBigInteger(true, cidr, family, out uintNetmask2); + IPNetwork.InternalToBigInteger(true, cidr, family, out var uintNetmask2); bool parsed = (uintNetmask2 != null); uintNetmask = uintNetmask2; return parsed; @@ -751,7 +713,7 @@ namespace System.Net { if (tryParse == false) { - throw new ArgumentOutOfRangeException("cidr"); + throw new ArgumentOutOfRangeException(nameof(cidr)); } uintNetmask = null; return; @@ -761,7 +723,7 @@ namespace System.Net { if (tryParse == false) { - throw new ArgumentOutOfRangeException("cidr"); + throw new ArgumentOutOfRangeException(nameof(cidr)); } uintNetmask = null; return; @@ -785,7 +747,7 @@ namespace System.Net return; } - BigInteger mask = new BigInteger(new byte[] { + var mask = new BigInteger(new byte[] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -793,7 +755,7 @@ namespace System.Net 0x00 }); - BigInteger masked = cidr == 0 ? 0 : mask << (128 - cidr); + var masked = cidr == 0 ? 0 : mask << (128 - cidr); byte[] m = masked.ToByteArray(); byte[] bmask = new byte[17]; int copy = m.Length > 16 ? 16 : m.Length; @@ -843,8 +805,7 @@ namespace System.Net /// <returns></returns> public static byte ToCidr(IPAddress netmask) { - byte? cidr = null; - IPNetwork.InternalToCidr(false, netmask, out cidr); + IPNetwork.InternalToCidr(false, netmask, out var cidr); return (byte)cidr; } @@ -858,8 +819,7 @@ namespace System.Net /// <returns></returns> public static bool TryToCidr(IPAddress netmask, out byte? cidr) { - byte? cidr2 = null; - IPNetwork.InternalToCidr(true, netmask, out cidr2); + IPNetwork.InternalToCidr(true, netmask, out var cidr2); bool parsed = (cidr2 != null); cidr = cidr2; return parsed; @@ -872,13 +832,13 @@ namespace System.Net { if (tryParse == false) { - throw new ArgumentNullException("netmask"); + throw new ArgumentNullException(nameof(netmask)); } cidr = null; return; } - BigInteger? uintNetmask2 = null; - bool parsed = IPNetwork.TryToBigInteger(netmask, out uintNetmask2); + + bool parsed = IPNetwork.TryToBigInteger(netmask, out var uintNetmask2); /// 20180217 lduchosal /// impossible to reach code. @@ -889,10 +849,9 @@ namespace System.Net /// cidr = null; /// return; /// } - BigInteger uintNetmask = (BigInteger)uintNetmask2; + var uintNetmask = (BigInteger)uintNetmask2; - byte? cidr2 = null; - IPNetwork.InternalToCidr(tryParse, uintNetmask, netmask.AddressFamily, out cidr2); + IPNetwork.InternalToCidr(tryParse, uintNetmask, netmask.AddressFamily, out var cidr2); cidr = cidr2; return; @@ -962,7 +921,7 @@ namespace System.Net /// 20180217 lduchosal /// impossible to reach code, byte cannot be negative : - /// + /// /// if (cidr < 0) { /// if (tryParse == false) { /// throw new ArgumentOutOfRangeException("cidr"); @@ -976,14 +935,14 @@ namespace System.Net { if (tryParse == false) { - throw new ArgumentOutOfRangeException("cidr"); + throw new ArgumentOutOfRangeException(nameof(cidr)); } netmask = null; return; } - BigInteger mask = IPNetwork.ToUint(cidr, family); - IPAddress netmask2 = IPNetwork.ToIPAddress(mask, family); + var mask = IPNetwork.ToUint(cidr, family); + var netmask2 = IPNetwork.ToIPAddress(mask, family); netmask = netmask2; return; @@ -1021,7 +980,7 @@ namespace System.Net /// <returns></returns> public static uint BitsSet(IPAddress netmask) { - BigInteger uintNetmask = IPNetwork.ToBigInteger(netmask); + var uintNetmask = IPNetwork.ToBigInteger(netmask); uint bits = IPNetwork.BitsSet(uintNetmask, netmask.AddressFamily); return bits; } @@ -1042,9 +1001,9 @@ namespace System.Net if (netmask == null) { - throw new ArgumentNullException("netmask"); + throw new ArgumentNullException(nameof(netmask)); } - BigInteger uintNetmask = IPNetwork.ToBigInteger(netmask); + var uintNetmask = IPNetwork.ToBigInteger(netmask); bool valid = IPNetwork.InternalValidNetmask(uintNetmask, netmask.AddressFamily); return valid; } @@ -1073,7 +1032,7 @@ namespace System.Net 0x00 }); - BigInteger neg = ((~netmask) & (mask)); + var neg = ((~netmask) & (mask)); bool isNetmask = ((neg + 1) & neg) == 0; return isNetmask; @@ -1099,7 +1058,7 @@ namespace System.Net Array.Reverse(bytes2); byte[] sized = Resize(bytes2, family); - IPAddress ip = new IPAddress(sized); + var ip = new IPAddress(sized); return ip; } @@ -1145,7 +1104,7 @@ namespace System.Net if (ipaddress == null) { - throw new ArgumentNullException("ipaddress"); + throw new ArgumentNullException(nameof(ipaddress)); } if (AddressFamily != ipaddress.AddressFamily) @@ -1153,9 +1112,9 @@ namespace System.Net return false; } - BigInteger uintNetwork = _network; - BigInteger uintBroadcast = _broadcast; - BigInteger uintAddress = IPNetwork.ToBigInteger(ipaddress); + var uintNetwork = _network; + var uintBroadcast = _broadcast; + var uintAddress = IPNetwork.ToBigInteger(ipaddress); bool contains = (uintAddress >= uintNetwork && uintAddress <= uintBroadcast); @@ -1174,14 +1133,14 @@ namespace System.Net if (network2 == null) { - throw new ArgumentNullException("network2"); + throw new ArgumentNullException(nameof(network2)); } - BigInteger uintNetwork = _network; - BigInteger uintBroadcast = _broadcast; + var uintNetwork = _network; + var uintBroadcast = _broadcast; - BigInteger uintFirst = network2._network; - BigInteger uintLast = network2._broadcast; + var uintFirst = network2._network; + var uintLast = network2._broadcast; bool contains = (uintFirst >= uintNetwork && uintLast <= uintBroadcast); @@ -1203,14 +1162,14 @@ namespace System.Net if (network2 == null) { - throw new ArgumentNullException("network2"); + throw new ArgumentNullException(nameof(network2)); } - BigInteger uintNetwork = _network; - BigInteger uintBroadcast = _broadcast; + var uintNetwork = _network; + var uintBroadcast = _broadcast; - BigInteger uintFirst = network2._network; - BigInteger uintLast = network2._broadcast; + var uintFirst = network2._network; + var uintLast = network2._broadcast; bool overlap = (uintFirst >= uintNetwork && uintFirst <= uintBroadcast) @@ -1242,40 +1201,22 @@ 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 + /// return true if ipaddress is contained in /// IANA_ABLK_RESERVED1, IANA_BBLK_RESERVED1, IANA_CBLK_RESERVED1 /// </summary> /// <param name="ipaddress"></param> @@ -1285,7 +1226,7 @@ namespace System.Net if (ipaddress == null) { - throw new ArgumentNullException("ipaddress"); + throw new ArgumentNullException(nameof(ipaddress)); } return IPNetwork.IANA_ABLK_RESERVED1.Contains(ipaddress) @@ -1294,7 +1235,7 @@ namespace System.Net } /// <summary> - /// return true if ipnetwork is contained in + /// return true if ipnetwork is contained in /// IANA_ABLK_RESERVED1, IANA_BBLK_RESERVED1, IANA_CBLK_RESERVED1 /// </summary> /// <returns></returns> @@ -1356,7 +1297,7 @@ namespace System.Net { if (trySubnet == false) { - throw new ArgumentNullException("network"); + throw new ArgumentNullException(nameof(network)); } ipnetworkCollection = null; return; @@ -1367,7 +1308,7 @@ namespace System.Net { if (trySubnet == false) { - throw new ArgumentOutOfRangeException("cidr"); + throw new ArgumentOutOfRangeException(nameof(cidr)); } ipnetworkCollection = null; return; @@ -1395,9 +1336,9 @@ namespace System.Net /// <summary> /// Supernet two consecutive cidr equal subnet into a single one - /// 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.0.0/23 /// 10.1.0.0/16 + 10.0.0.0/16 = 10.0.0.0/15 - /// 192.168.0.0/24 + 192.168.0.0/25 = 192.168.0.0/24 + /// 192.168.0.0/24 + 192.168.0.0/25 = 192.168.0.0/24 /// </summary> /// <param name="network2"></param> /// <returns></returns> @@ -1410,9 +1351,9 @@ namespace System.Net /// <summary> /// Try to supernet two consecutive cidr equal subnet into a single one - /// 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.0.0/23 /// 10.1.0.0/16 + 10.0.0.0/16 = 10.0.0.0/15 - /// 192.168.0.0/24 + 192.168.0.0/25 = 192.168.0.0/24 + /// 192.168.0.0/24 + 192.168.0.0/25 = 192.168.0.0/24 /// </summary> /// <param name="network2"></param> /// <returns></returns> @@ -1438,7 +1379,7 @@ namespace System.Net { if (trySupernet == false) { - throw new ArgumentNullException("network1"); + throw new ArgumentNullException(nameof(network1)); } supernet = null; return; @@ -1448,7 +1389,7 @@ namespace System.Net { if (trySupernet == false) { - throw new ArgumentNullException("network2"); + throw new ArgumentNullException(nameof(network2)); } supernet = null; return; @@ -1477,8 +1418,8 @@ namespace System.Net return; } - IPNetwork first = (network1._network < network2._network) ? network1 : network2; - IPNetwork last = (network1._network > network2._network) ? network1 : network2; + var first = (network1._network < network2._network) ? network1 : network2; + var last = (network1._network > network2._network) ? network1 : network2; /// Starting from here : /// network1 and network2 have the same cidr, @@ -1492,16 +1433,16 @@ 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; } - BigInteger uintSupernet = first._network; + var uintSupernet = first._network; byte cidrSupernet = (byte)(first._cidr - 1); - IPNetwork networkSupernet = new IPNetwork(uintSupernet, first._family, cidrSupernet); + var networkSupernet = new IPNetwork(uintSupernet, first._family, cidrSupernet); if (networkSupernet._network != first._network) { if (trySupernet == false) @@ -1536,13 +1477,11 @@ 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) { - IPNetwork[] supernet; - InternalSupernet(false, ipnetworks, out supernet); + InternalSupernet(false, ipnetworks, out var supernet); return supernet; } @@ -1573,7 +1512,7 @@ namespace System.Net { if (trySupernet == false) { - throw new ArgumentNullException("ipnetworks"); + throw new ArgumentNullException(nameof(ipnetworks)); } supernet = null; return false; @@ -1585,9 +1524,9 @@ namespace System.Net return true; } - List<IPNetwork> supernetted = new List<IPNetwork>(); - List<IPNetwork> ipns = IPNetwork.Array2List(ipnetworks); - Stack<IPNetwork> current = IPNetwork.List2Stack(ipns); + var supernetted = new List<IPNetwork>(); + var ipns = IPNetwork.Array2List(ipnetworks); + var current = IPNetwork.List2Stack(ipns); int previousCount = 0; int currentCount = current.Count; @@ -1597,8 +1536,8 @@ namespace System.Net supernetted.Clear(); while (current.Count > 1) { - IPNetwork ipn1 = current.Pop(); - IPNetwork ipn2 = current.Peek(); + var ipn1 = current.Pop(); + var ipn2 = current.Peek(); IPNetwork outNetwork = null; bool success = ipn1.TrySupernet(ipn2, out outNetwork); @@ -1628,7 +1567,7 @@ namespace System.Net private static Stack<IPNetwork> List2Stack(List<IPNetwork> list) { - Stack<IPNetwork> stack = new Stack<IPNetwork>(); + var stack = new Stack<IPNetwork>(); list.ForEach(new Action<IPNetwork>( delegate (IPNetwork ipn) { @@ -1640,7 +1579,7 @@ namespace System.Net private static List<IPNetwork> Array2List(IPNetwork[] array) { - List<IPNetwork> ipns = new List<IPNetwork>(); + var ipns = new List<IPNetwork>(); ipns.AddRange(array); IPNetwork.RemoveNull(ipns); ipns.Sort(new Comparison<IPNetwork>( @@ -1684,22 +1623,20 @@ 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; - if (!IPAddress.TryParse(start, out startIP)) + if (!IPAddress.TryParse(start, out var startIP)) { throw new ArgumentException("start"); } - IPAddress endIP; - if (!IPAddress.TryParse(end, out endIP)) + if (!IPAddress.TryParse(end, out var endIP)) { throw new ArgumentException("end"); } @@ -1709,10 +1646,10 @@ namespace System.Net throw new NotSupportedException("MixedAddressFamily"); } - IPNetwork ipnetwork = new IPNetwork(0, startIP.AddressFamily, 0); + var ipnetwork = new IPNetwork(0, startIP.AddressFamily, 0); for (byte cidr = 32; cidr >= 0; cidr--) { - IPNetwork wideSubnet = IPNetwork.Parse(start, cidr); + var wideSubnet = IPNetwork.Parse(start, cidr); if (wideSubnet.Contains(endIP)) { ipnetwork = wideSubnet; @@ -1750,15 +1687,16 @@ namespace System.Net { if (tryWide == false) { - throw new ArgumentNullException("ipnetworks"); + throw new ArgumentNullException(nameof(ipnetworks)); } ipnetwork = null; return; } - IPNetwork[] nnin = Array.FindAll<IPNetwork>(ipnetworks, new Predicate<IPNetwork>( - delegate (IPNetwork ipnet) { + IPNetwork[] nnin = Array.FindAll(ipnetworks, new Predicate<IPNetwork>( + delegate (IPNetwork ipnet) + { return ipnet != null; } )); @@ -1775,19 +1713,19 @@ namespace System.Net if (nnin.Length == 1) { - IPNetwork ipn0 = nnin[0]; + var ipn0 = nnin[0]; ipnetwork = ipn0; return; } - Array.Sort<IPNetwork>(nnin); - IPNetwork nnin0 = nnin[0]; - BigInteger uintNnin0 = nnin0._ipaddress; + Array.Sort(nnin); + var nnin0 = nnin[0]; + var uintNnin0 = nnin0._ipaddress; - IPNetwork nninX = nnin[nnin.Length - 1]; - IPAddress ipaddressX = nninX.Broadcast; + var nninX = nnin[nnin.Length - 1]; + var ipaddressX = nninX.Broadcast; - AddressFamily family = ipnetworks[0]._family; + var family = ipnetworks[0]._family; foreach (var ipnx in ipnetworks) { if (ipnx._family != family) @@ -1796,10 +1734,10 @@ namespace System.Net } } - IPNetwork ipn = new IPNetwork(0, family, 0); + var ipn = new IPNetwork(0, family, 0); for (byte cidr = nnin0._cidr; cidr >= 0; cidr--) { - IPNetwork wideSubnet = new IPNetwork(uintNnin0, family, cidr); + var wideSubnet = new IPNetwork(uintNnin0, family, cidr); if (wideSubnet.Contains(ipaddressX)) { ipn = wideSubnet; @@ -1822,7 +1760,7 @@ namespace System.Net public string Print() { - StringWriter sw = new StringWriter(); + var sw = new StringWriter(); sw.WriteLine("IPNetwork : {0}", ToString()); sw.WriteLine("Network : {0}", Network); @@ -1841,13 +1779,13 @@ namespace System.Net #region TryGuessCidr /// <summary> - /// - /// Class Leading bits Default netmask - /// A (CIDR /8) 00 255.0.0.0 - /// A (CIDR /8) 01 255.0.0.0 - /// B (CIDR /16) 10 255.255.0.0 - /// C (CIDR /24) 11 255.255.255.0 - /// + /// + /// Class Leading bits Default netmask + /// A (CIDR /8) 00 255.0.0.0 + /// A (CIDR /8) 01 255.0.0.0 + /// B (CIDR /16) 10 255.255.0.0 + /// C (CIDR /24) 11 255.255.255.0 + /// /// </summary> /// <param name="ip"></param> /// <param name="cidr"></param> @@ -1868,7 +1806,7 @@ namespace System.Net cidr = 64; return true; } - BigInteger uintIPAddress = IPNetwork.ToBigInteger(ipaddress); + var uintIPAddress = IPNetwork.ToBigInteger(ipaddress); uintIPAddress = uintIPAddress >> 29; if (uintIPAddress <= 3) { @@ -1931,7 +1869,7 @@ namespace System.Net /** * Need a better way to do it - * + * #region TrySubstractNetwork public static bool TrySubstractNetwork(IPNetwork[] ipnetworks, IPNetwork substract, out IEnumerable<IPNetwork> result) { @@ -1973,7 +1911,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 +1932,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 +1950,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 +1961,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 +1980,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; } diff --git a/Emby.Server.Implementations/Networking/IPNetwork/IPNetworkCollection.cs b/Emby.Server.Implementations/Networking/IPNetwork/IPNetworkCollection.cs index 35cff88dc..7d3106624 100644 --- a/Emby.Server.Implementations/Networking/IPNetwork/IPNetworkCollection.cs +++ b/Emby.Server.Implementations/Networking/IPNetwork/IPNetworkCollection.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using System.Collections.Generic; using System.Numerics; @@ -11,22 +11,12 @@ namespace System.Net private byte _cidrSubnet; private IPNetwork _ipnetwork; - private byte _cidr - { - get { return this._ipnetwork.Cidr; } - } - private BigInteger _broadcast - { - get { return IPNetwork.ToBigInteger(this._ipnetwork.Broadcast); } - } - private BigInteger _lastUsable - { - get { return IPNetwork.ToBigInteger(this._ipnetwork.LastUsable); } - } - private BigInteger _network - { - get { return IPNetwork.ToBigInteger(this._ipnetwork.Network); } - } + private byte _cidr => this._ipnetwork.Cidr; + + private BigInteger _broadcast => IPNetwork.ToBigInteger(this._ipnetwork.Broadcast); + + private BigInteger _lastUsable => IPNetwork.ToBigInteger(this._ipnetwork.LastUsable); + private BigInteger _network => IPNetwork.ToBigInteger(this._ipnetwork.Network); #if TRAVISCI public #else @@ -38,7 +28,7 @@ namespace System.Net int maxCidr = ipnetwork.AddressFamily == Sockets.AddressFamily.InterNetwork ? 32 : 128; if (cidrSubnet > maxCidr) { - throw new ArgumentOutOfRangeException("cidrSubnet"); + throw new ArgumentOutOfRangeException(nameof(cidrSubnet)); } if (cidrSubnet < ipnetwork.Cidr) @@ -57,7 +47,7 @@ namespace System.Net { get { - BigInteger count = BigInteger.Pow(2, this._cidrSubnet - this._cidr); + var count = BigInteger.Pow(2, this._cidrSubnet - this._cidr); return count; } } @@ -68,14 +58,14 @@ namespace System.Net { if (i >= this.Count) { - throw new ArgumentOutOfRangeException("i"); + throw new ArgumentOutOfRangeException(nameof(i)); } - BigInteger last = this._ipnetwork.AddressFamily == Sockets.AddressFamily.InterNetworkV6 + var last = this._ipnetwork.AddressFamily == Sockets.AddressFamily.InterNetworkV6 ? this._lastUsable : this._broadcast; - BigInteger increment = (last - this._network) / this.Count; - BigInteger uintNetwork = this._network + ((increment + 1) * i); - IPNetwork ipn = new IPNetwork(uintNetwork, this._ipnetwork.AddressFamily, this._cidrSubnet); + var increment = (last - this._network) / this.Count; + var uintNetwork = this._network + ((increment + 1) * i); + var ipn = new IPNetwork(uintNetwork, this._ipnetwork.AddressFamily, this._cidrSubnet); return ipn; } } @@ -96,10 +86,7 @@ namespace System.Net #region IEnumerator<IPNetwork> Members - public IPNetwork Current - { - get { return this[this._enumerator]; } - } + public IPNetwork Current => this[this._enumerator]; #endregion @@ -115,10 +102,7 @@ namespace System.Net #region IEnumerator Members - object IEnumerator.Current - { - get { return this.Current; } - } + object IEnumerator.Current => this.Current; public bool MoveNext() { @@ -141,4 +125,4 @@ namespace System.Net #endregion } -}
\ No newline at end of file +} diff --git a/Emby.Server.Implementations/Networking/NetworkManager.cs b/Emby.Server.Implementations/Networking/NetworkManager.cs index 260d20e35..f4b9f84dc 100644 --- a/Emby.Server.Implementations/Networking/NetworkManager.cs +++ b/Emby.Server.Implementations/Networking/NetworkManager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -9,10 +9,9 @@ using System.Threading.Tasks; using MediaBrowser.Common.Net; using MediaBrowser.Model.Extensions; using MediaBrowser.Model.IO; -using Microsoft.Extensions.Logging; using MediaBrowser.Model.Net; using MediaBrowser.Model.System; -using System.Numerics; +using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.Networking { @@ -23,9 +22,11 @@ namespace Emby.Server.Implementations.Networking public event EventHandler NetworkChanged; public Func<string[]> LocalSubnetsFn { get; set; } - public NetworkManager(ILogger logger, IEnvironmentInfo environment) + public NetworkManager( + ILoggerFactory loggerFactory, + IEnvironmentInfo environment) { - Logger = logger; + Logger = loggerFactory.CreateLogger(nameof(NetworkManager)); // In FreeBSD these events cause a crash if (environment.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.BSD) @@ -114,7 +115,7 @@ namespace Emby.Server.Implementations.Networking .ToList(); } - private bool FilterIpAddress(IPAddress address) + private static bool FilterIpAddress(IPAddress address) { var addressString = address.ToString(); @@ -204,20 +205,18 @@ namespace Emby.Server.Implementations.Networking private Dictionary<string, List<string>> _subnetLookup = new Dictionary<string, List<string>>(StringComparer.Ordinal); private List<string> GetSubnets(string endpointFirstPart) { - List<string> subnets; - lock (_subnetLookup) { - if (_subnetLookup.TryGetValue(endpointFirstPart, out subnets)) + if (_subnetLookup.TryGetValue(endpointFirstPart, out var subnets)) { return subnets; } subnets = new List<string>(); - foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces()) + foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces()) { - foreach (UnicastIPAddressInformation unicastIPAddressInformation in adapter.GetIPProperties().UnicastAddresses) + foreach (var unicastIPAddressInformation in adapter.GetIPProperties().UnicastAddresses) { if (unicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork && endpointFirstPart == unicastIPAddressInformation.Address.ToString().Split('.')[0]) { @@ -228,7 +227,7 @@ namespace Emby.Server.Implementations.Networking subnet_Test++; } - var subnet_Match = String.Join(".", unicastIPAddressInformation.Address.ToString().Split('.').Take(subnet_Test).ToArray()); + var subnet_Match = string.Join(".", unicastIPAddressInformation.Address.ToString().Split('.').Take(subnet_Test).ToArray()); // TODO: Is this check necessary? if (adapter.OperationalStatus == OperationalStatus.Up) @@ -245,7 +244,7 @@ namespace Emby.Server.Implementations.Networking } } - private bool Is172AddressPrivate(string endpoint) + private static bool Is172AddressPrivate(string endpoint) { for (var i = 16; i <= 31; i++) { @@ -268,7 +267,7 @@ namespace Emby.Server.Implementations.Networking return IsAddressInSubnets(IPAddress.Parse(addressString), addressString, subnets); } - private bool IsAddressInSubnets(IPAddress address, string addressString, string[] subnets) + private static bool IsAddressInSubnets(IPAddress address, string addressString, string[] subnets) { foreach (var subnet in subnets) { @@ -296,11 +295,10 @@ namespace Emby.Server.Implementations.Networking { if (string.IsNullOrEmpty(endpoint)) { - throw new ArgumentNullException("endpoint"); + throw new ArgumentNullException(nameof(endpoint)); } - IPAddress address; - if (IPAddress.TryParse(endpoint, out address)) + if (IPAddress.TryParse(endpoint, out var address)) { var addressString = address.ToString(); @@ -349,8 +347,7 @@ namespace Emby.Server.Implementations.Networking } else if (resolveHost) { - Uri uri; - if (Uri.TryCreate(endpoint, UriKind.RelativeOrAbsolute, out uri)) + if (Uri.TryCreate(endpoint, UriKind.RelativeOrAbsolute, out var uri)) { try { @@ -380,7 +377,7 @@ namespace Emby.Server.Implementations.Networking return false; } - private Task<IPAddress[]> GetIpAddresses(string hostName) + private static Task<IPAddress[]> GetIpAddresses(string hostName) { return Dns.GetHostAddressesAsync(hostName); } @@ -436,7 +433,7 @@ namespace Emby.Server.Implementations.Networking .ToList(); } - private async Task<IEnumerable<IPAddress>> GetLocalIpAddressesFallback() + private static async Task<IEnumerable<IPAddress>> GetLocalIpAddressesFallback() { var host = await Dns.GetHostEntryAsync(Dns.GetHostName()).ConfigureAwait(false); @@ -462,7 +459,7 @@ namespace Emby.Server.Implementations.Networking public int GetRandomUnusedUdpPort() { - IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, 0); + var localEndPoint = new IPEndPoint(IPAddress.Any, 0); using (var udpClient = new UdpClient(localEndPoint)) { var port = ((IPEndPoint)(udpClient.Client.LocalEndPoint)).Port; @@ -480,7 +477,7 @@ namespace Emby.Server.Implementations.Networking return _macAddresses; } - private List<string> GetMacAddressesInternal() + private static List<string> GetMacAddressesInternal() { return NetworkInterface.GetAllNetworkInterfaces() .Where(i => i.NetworkInterfaceType != NetworkInterfaceType.Loopback) @@ -497,8 +494,9 @@ namespace Emby.Server.Implementations.Networking return physicalAddress.ToString(); } - catch (Exception ex) + catch (Exception) { + //TODO Log exception. return null; } }) @@ -522,11 +520,11 @@ namespace Emby.Server.Implementations.Networking /// <param name="endpointstring">The endpointstring.</param> /// <param name="defaultport">The defaultport.</param> /// <returns>IPEndPoint.</returns> - /// <exception cref="System.ArgumentException">Endpoint descriptor may not be empty.</exception> - /// <exception cref="System.FormatException"></exception> + /// <exception cref="ArgumentException">Endpoint descriptor may not be empty.</exception> + /// <exception cref="FormatException"></exception> private static async Task<IPEndPoint> Parse(string endpointstring, int defaultport) { - if (String.IsNullOrEmpty(endpointstring) + if (string.IsNullOrEmpty(endpointstring) || endpointstring.Trim().Length == 0) { throw new ArgumentException("Endpoint descriptor may not be empty."); @@ -536,7 +534,7 @@ namespace Emby.Server.Implementations.Networking (defaultport < IPEndPoint.MinPort || defaultport > IPEndPoint.MaxPort)) { - throw new ArgumentException(String.Format("Invalid default port '{0}'", defaultport)); + throw new ArgumentException(string.Format("Invalid default port '{0}'", defaultport)); } string[] values = endpointstring.Split(new char[] { ':' }); @@ -557,7 +555,7 @@ namespace Emby.Server.Implementations.Networking //could [a:b:c]:d if (values[0].StartsWith("[") && values[values.Length - 2].EndsWith("]")) { - string ipaddressstring = String.Join(":", values.Take(values.Length - 1).ToArray()); + string ipaddressstring = string.Join(":", values.Take(values.Length - 1).ToArray()); ipaddy = IPAddress.Parse(ipaddressstring); port = GetPort(values[values.Length - 1]); } @@ -569,11 +567,11 @@ namespace Emby.Server.Implementations.Networking } else { - throw new FormatException(String.Format("Invalid endpoint ipaddress '{0}'", endpointstring)); + throw new FormatException(string.Format("Invalid endpoint ipaddress '{0}'", endpointstring)); } if (port == -1) - throw new ArgumentException(String.Format("No port specified: '{0}'", endpointstring)); + throw new ArgumentException(string.Format("No port specified: '{0}'", endpointstring)); return new IPEndPoint(ipaddy, port); } @@ -585,16 +583,14 @@ namespace Emby.Server.Implementations.Networking /// </summary> /// <param name="p">The p.</param> /// <returns>System.Int32.</returns> - /// <exception cref="System.FormatException"></exception> + /// <exception cref="FormatException"></exception> private static int GetPort(string p) { - int port; - - if (!Int32.TryParse(p, out port) + if (!int.TryParse(p, out var port) || port < IPEndPoint.MinPort || port > IPEndPoint.MaxPort) { - throw new FormatException(String.Format("Invalid end point port '{0}'", p)); + throw new FormatException(string.Format("Invalid end point port '{0}'", p)); } return port; @@ -605,21 +601,20 @@ namespace Emby.Server.Implementations.Networking /// </summary> /// <param name="p">The p.</param> /// <returns>IPAddress.</returns> - /// <exception cref="System.ArgumentException"></exception> + /// <exception cref="ArgumentException"></exception> private static async Task<IPAddress> GetIPfromHost(string p) { var hosts = await Dns.GetHostAddressesAsync(p).ConfigureAwait(false); if (hosts == null || hosts.Length == 0) - throw new ArgumentException(String.Format("Host not found: {0}", p)); + throw new ArgumentException(string.Format("Host not found: {0}", p)); return hosts[0]; } public IpAddressInfo ParseIpAddress(string ipAddress) { - IpAddressInfo info; - if (TryParseIpAddress(ipAddress, out info)) + if (TryParseIpAddress(ipAddress, out var info)) { return info; } @@ -629,8 +624,7 @@ namespace Emby.Server.Implementations.Networking public bool TryParseIpAddress(string ipAddress, out IpAddressInfo ipAddressInfo) { - IPAddress address; - if (IPAddress.TryParse(ipAddress, out address)) + if (IPAddress.TryParse(ipAddress, out var address)) { ipAddressInfo = ToIpAddressInfo(address); return true; |
