From eed85970011c8715566cf8bf0dc2a9bdd00fee1b Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 26 Sep 2020 18:09:01 +0530 Subject: [PATCH] DHCP options codee refactoring done. --- .../Dhcp/Options/DomainNameServerOption.cs | 17 ++++++++++------- .../Dhcp/Options/NetBiosNameServerOption.cs | 17 ++++++++++------- .../Options/NetworkTimeProtocolServersOption.cs | 17 ++++++++++------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/DnsServerCore/Dhcp/Options/DomainNameServerOption.cs b/DnsServerCore/Dhcp/Options/DomainNameServerOption.cs index 34ef27f6..f867ff7c 100644 --- a/DnsServerCore/Dhcp/Options/DomainNameServerOption.cs +++ b/DnsServerCore/Dhcp/Options/DomainNameServerOption.cs @@ -1,6 +1,6 @@ /* Technitium DNS Server -Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com) +Copyright (C) 2020 Shreyas Zare (shreyas@technitium.com) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,6 +17,7 @@ along with this program. If not, see . */ +using System.Collections.Generic; using System.IO; using System.Net; using TechnitiumLibrary.IO; @@ -27,13 +28,13 @@ namespace DnsServerCore.Dhcp.Options { #region variables - IPAddress[] _addresses; + ICollection _addresses; #endregion #region constructor - public DomainNameServerOption(IPAddress[] addresses) + public DomainNameServerOption(ICollection addresses) : base(DhcpOptionCode.DomainNameServer) { _addresses = addresses; @@ -52,10 +53,12 @@ namespace DnsServerCore.Dhcp.Options if ((s.Length % 4 != 0) || (s.Length < 4)) throw new InvalidDataException(); - _addresses = new IPAddress[s.Length / 4]; + IPAddress[] addresses = new IPAddress[s.Length / 4]; - for (int i = 0; i < _addresses.Length; i++) - _addresses[i] = new IPAddress(s.ReadBytes(4)); + for (int i = 0; i < addresses.Length; i++) + addresses[i] = new IPAddress(s.ReadBytes(4)); + + _addresses = addresses; } protected override void WriteOptionValue(Stream s) @@ -68,7 +71,7 @@ namespace DnsServerCore.Dhcp.Options #region properties - public IPAddress[] Addresses + public ICollection Addresses { get { return _addresses; } } #endregion diff --git a/DnsServerCore/Dhcp/Options/NetBiosNameServerOption.cs b/DnsServerCore/Dhcp/Options/NetBiosNameServerOption.cs index dba24824..6e84efb2 100644 --- a/DnsServerCore/Dhcp/Options/NetBiosNameServerOption.cs +++ b/DnsServerCore/Dhcp/Options/NetBiosNameServerOption.cs @@ -1,6 +1,6 @@ /* Technitium DNS Server -Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com) +Copyright (C) 2020 Shreyas Zare (shreyas@technitium.com) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,6 +17,7 @@ along with this program. If not, see . */ +using System.Collections.Generic; using System.IO; using System.Net; using TechnitiumLibrary.IO; @@ -27,13 +28,13 @@ namespace DnsServerCore.Dhcp.Options { #region variables - IPAddress[] _addresses; + ICollection _addresses; #endregion #region constructor - public NetBiosNameServerOption(IPAddress[] addresses) + public NetBiosNameServerOption(ICollection addresses) : base(DhcpOptionCode.NetBiosOverTcpIpNameServer) { _addresses = addresses; @@ -52,10 +53,12 @@ namespace DnsServerCore.Dhcp.Options if ((s.Length % 4 != 0) || (s.Length < 4)) throw new InvalidDataException(); - _addresses = new IPAddress[s.Length / 4]; + IPAddress[] addresses = new IPAddress[s.Length / 4]; - for (int i = 0; i < _addresses.Length; i++) - _addresses[i] = new IPAddress(s.ReadBytes(4)); + for (int i = 0; i < addresses.Length; i++) + addresses[i] = new IPAddress(s.ReadBytes(4)); + + _addresses = addresses; } protected override void WriteOptionValue(Stream s) @@ -68,7 +71,7 @@ namespace DnsServerCore.Dhcp.Options #region properties - public IPAddress[] Addresses + public ICollection Addresses { get { return _addresses; } } #endregion diff --git a/DnsServerCore/Dhcp/Options/NetworkTimeProtocolServersOption.cs b/DnsServerCore/Dhcp/Options/NetworkTimeProtocolServersOption.cs index 65e16abb..71ce20b3 100644 --- a/DnsServerCore/Dhcp/Options/NetworkTimeProtocolServersOption.cs +++ b/DnsServerCore/Dhcp/Options/NetworkTimeProtocolServersOption.cs @@ -1,6 +1,6 @@ /* Technitium DNS Server -Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com) +Copyright (C) 2020 Shreyas Zare (shreyas@technitium.com) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,6 +17,7 @@ along with this program. If not, see . */ +using System.Collections.Generic; using System.IO; using System.Net; using TechnitiumLibrary.IO; @@ -27,13 +28,13 @@ namespace DnsServerCore.Dhcp.Options { #region variables - IPAddress[] _addresses; + ICollection _addresses; #endregion #region constructor - public NetworkTimeProtocolServersOption(IPAddress[] addresses) + public NetworkTimeProtocolServersOption(ICollection addresses) : base(DhcpOptionCode.NetworkTimeProtocolServers) { _addresses = addresses; @@ -52,10 +53,12 @@ namespace DnsServerCore.Dhcp.Options if ((s.Length % 4 != 0) || (s.Length < 4)) throw new InvalidDataException(); - _addresses = new IPAddress[s.Length / 4]; + IPAddress[] addresses = new IPAddress[s.Length / 4]; - for (int i = 0; i < _addresses.Length; i++) - _addresses[i] = new IPAddress(s.ReadBytes(4)); + for (int i = 0; i < addresses.Length; i++) + addresses[i] = new IPAddress(s.ReadBytes(4)); + + _addresses = addresses; } protected override void WriteOptionValue(Stream s) @@ -68,7 +71,7 @@ namespace DnsServerCore.Dhcp.Options #region properties - public IPAddress[] Addresses + public ICollection Addresses { get { return _addresses; } } #endregion