ParameterRequestListOption.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Technitium DNS Server
  3. Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com)
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. using System.IO;
  16. namespace DnsServerCore.Dhcp.Options
  17. {
  18. class ParameterRequestListOption : DhcpOption
  19. {
  20. #region variables
  21. DhcpOptionCode[] _optionCodes;
  22. #endregion
  23. #region constructor
  24. public ParameterRequestListOption(DhcpOptionCode[] optionCodes)
  25. : base(DhcpOptionCode.ParameterRequestList)
  26. {
  27. _optionCodes = optionCodes;
  28. }
  29. public ParameterRequestListOption(Stream s)
  30. : base(DhcpOptionCode.ParameterRequestList, s)
  31. { }
  32. #endregion
  33. #region protected
  34. protected override void ParseOptionValue(Stream s)
  35. {
  36. if (s.Length < 1)
  37. throw new InvalidDataException();
  38. _optionCodes = new DhcpOptionCode[s.Length];
  39. int optionCode;
  40. for (int i = 0; i < _optionCodes.Length; i++)
  41. {
  42. optionCode = s.ReadByte();
  43. if (optionCode < 0)
  44. throw new EndOfStreamException();
  45. _optionCodes[i] = (DhcpOptionCode)optionCode;
  46. }
  47. }
  48. protected override void WriteOptionValue(Stream s)
  49. {
  50. foreach (DhcpOptionCode optionCode in _optionCodes)
  51. s.WriteByte((byte)optionCode);
  52. }
  53. #endregion
  54. #region properties
  55. public DhcpOptionCode[] OptionCodes
  56. { get { return _optionCodes; } }
  57. #endregion
  58. }
  59. }