DnsResourceRecordInfo.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. Technitium DNS Server
  3. Copyright (C) 2020 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;
  16. using System.Collections.Generic;
  17. using System.IO;
  18. using TechnitiumLibrary.Net.Dns;
  19. namespace DnsServerCore.Dns.ResourceRecords
  20. {
  21. class DnsResourceRecordInfo
  22. {
  23. #region variables
  24. bool _disabled;
  25. IReadOnlyList<DnsResourceRecord> _glueRecords;
  26. #endregion
  27. #region constructor
  28. public DnsResourceRecordInfo()
  29. { }
  30. public DnsResourceRecordInfo(BinaryReader bR)
  31. {
  32. switch (bR.ReadByte()) //version
  33. {
  34. case 1:
  35. _disabled = bR.ReadBoolean();
  36. break;
  37. case 2:
  38. _disabled = bR.ReadBoolean();
  39. int count = bR.ReadByte();
  40. if (count > 0)
  41. {
  42. DnsResourceRecord[] glueRecords = new DnsResourceRecord[count];
  43. for (int i = 0; i < glueRecords.Length; i++)
  44. glueRecords[i] = new DnsResourceRecord(bR.BaseStream);
  45. _glueRecords = glueRecords;
  46. }
  47. break;
  48. default:
  49. throw new InvalidDataException("DnsResourceRecordInfo format version not supported.");
  50. }
  51. }
  52. #endregion
  53. #region public
  54. public void WriteTo(BinaryWriter bW)
  55. {
  56. bW.Write((byte)2); //version
  57. bW.Write(_disabled);
  58. if (_glueRecords == null)
  59. {
  60. bW.Write((byte)0);
  61. }
  62. else
  63. {
  64. bW.Write(Convert.ToByte(_glueRecords.Count));
  65. foreach (DnsResourceRecord glueRecord in _glueRecords)
  66. glueRecord.WriteTo(bW.BaseStream);
  67. }
  68. }
  69. #endregion
  70. #region properties
  71. public bool Disabled
  72. {
  73. get { return _disabled; }
  74. set { _disabled = value; }
  75. }
  76. public IReadOnlyList<DnsResourceRecord> GlueRecords
  77. {
  78. get { return _glueRecords; }
  79. set { _glueRecords = value; }
  80. }
  81. #endregion
  82. }
  83. }