NSRecordInfo.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. Technitium DNS Server
  3. Copyright (C) 2024 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.ResourceRecords;
  19. namespace DnsServerCore.Dns.ResourceRecords
  20. {
  21. class NSRecordInfo : GenericRecordInfo
  22. {
  23. #region variables
  24. IReadOnlyList<DnsResourceRecord> _glueRecords;
  25. #endregion
  26. #region constructor
  27. public NSRecordInfo()
  28. { }
  29. public NSRecordInfo(BinaryReader bR)
  30. : base(bR)
  31. { }
  32. #endregion
  33. #region protected
  34. protected override void ReadExtendedRecordInfoFrom(BinaryReader bR)
  35. {
  36. byte version = bR.ReadByte();
  37. switch (version)
  38. {
  39. case 0: //no extended info
  40. break;
  41. case 1:
  42. int count = bR.ReadByte();
  43. if (count > 0)
  44. {
  45. DnsResourceRecord[] glueRecords = new DnsResourceRecord[count];
  46. for (int i = 0; i < glueRecords.Length; i++)
  47. glueRecords[i] = new DnsResourceRecord(bR.BaseStream);
  48. _glueRecords = glueRecords;
  49. }
  50. break;
  51. default:
  52. throw new InvalidDataException("NSRecordInfo format version not supported.");
  53. }
  54. }
  55. protected override void WriteExtendedRecordInfoTo(BinaryWriter bW)
  56. {
  57. bW.Write((byte)1); //version
  58. if (_glueRecords is 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 IReadOnlyList<DnsResourceRecord> GlueRecords
  72. {
  73. get { return _glueRecords; }
  74. set
  75. {
  76. if ((value is null) || (value.Count == 0))
  77. _glueRecords = null;
  78. else
  79. _glueRecords = value;
  80. }
  81. }
  82. #endregion
  83. }
  84. }