DhcpOption: removed ParseColonHexString() and using library method instead.

This commit is contained in:
Shreyas Zare
2023-05-20 17:59:31 +05:30
parent 96c3027b83
commit a02da4870d

View File

@@ -1,6 +1,6 @@
/*
Technitium DNS Server
Copyright (C) 2022 Shreyas Zare (shreyas@technitium.com)
Copyright (C) 2023 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
@@ -19,8 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
using DnsServerCore.Dhcp.Options;
using System;
using System.Globalization;
using System.IO;
using TechnitiumLibrary;
using TechnitiumLibrary.IO;
namespace DnsServerCore.Dhcp
@@ -129,7 +129,7 @@ namespace DnsServerCore.Dhcp
_code = code;
if (hexValue.Contains(':'))
_value = ParseColonHexString(hexValue);
_value = hexValue.ParseColonHexString();
else
_value = Convert.FromHexString(hexValue);
}
@@ -260,38 +260,6 @@ namespace DnsServerCore.Dhcp
}
}
protected static byte[] ParseColonHexString(string value)
{
int i;
int j = -1;
string strHex;
int b;
using (MemoryStream mS = new MemoryStream())
{
while (true)
{
i = value.IndexOf(':', j + 1);
if (i < 0)
i = value.Length;
strHex = value.Substring(j + 1, i - j - 1);
if (!int.TryParse(strHex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out b) || (b < byte.MinValue) || (b > byte.MaxValue))
throw new InvalidDataException("VendorSpecificInformation option data must be a colon (:) separated hex string.");
mS.WriteByte((byte)b);
if (i == value.Length)
break;
j = i;
}
return mS.ToArray();
}
}
#endregion
#region internal