OptionOverloadOption.cs 1.9 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. enum OptionOverloadValue : byte
  19. {
  20. FileFieldUsed = 1,
  21. SnameFieldUsed = 2,
  22. BothFieldsUsed = 3
  23. }
  24. class OptionOverloadOption : DhcpOption
  25. {
  26. #region variables
  27. OptionOverloadValue _value;
  28. #endregion
  29. #region constructor
  30. public OptionOverloadOption(OptionOverloadValue value)
  31. : base(DhcpOptionCode.OptionOverload)
  32. {
  33. _value = value;
  34. }
  35. public OptionOverloadOption(Stream s)
  36. : base(DhcpOptionCode.OptionOverload, s)
  37. { }
  38. #endregion
  39. #region protected
  40. protected override void ParseOptionValue(Stream s)
  41. {
  42. if (s.Length != 1)
  43. throw new InvalidDataException();
  44. int value = s.ReadByte();
  45. if (value < 0)
  46. throw new EndOfStreamException();
  47. _value = (OptionOverloadValue)value;
  48. }
  49. protected override void WriteOptionValue(Stream s)
  50. {
  51. s.WriteByte((byte)_value);
  52. }
  53. #endregion
  54. #region properties
  55. public OptionOverloadValue Value
  56. { get { return _value; } }
  57. #endregion
  58. }
  59. }