Example #1
0
 /// <summary>
 /// Creates a new instance of <see cref="NbNsNodeStatusResponseResourceRecord"/> with the given <see cref="nodeNames"/> and <see cref="NbNsStatistics"/>
 /// </summary>
 /// <param name="rrName"><see cref="NbName"/> for this <see cref="NbNsNodeStatusResponseResourceRecord"/></param>
 /// <param name="nodeNames">List of <see cref="NbNsNodeName"/>s for this <see cref="NbNsNodeStatusResponseResourceRecord"/></param>
 /// <param name="statistics"><see cref="NbNsStatistics"/> for this <see cref="NbNsNodeStatusResponseResourceRecord"/></param>
 public NbNsNodeStatusResponseResourceRecord(NbName rrName, IEnumerable <NbNsNodeName> nodeNames, NbNsStatistics statistics)
     : base(RrTypeValue.NbStat, RrClassValue.In, 0)
 {
     RrName     = rrName;
     NodeNames  = new List <NbNsNodeName>(nodeNames);
     Statistics = statistics;
 }
        /// <summary>
        /// Tries to parse a <see cref="NbNsQuestionEntry"/> from a buffer of bytes
        /// </summary>
        /// <param name="buffer">Byte array containing the NbNsQuestionEntry</param>
        /// <param name="offset">Zero based offset in the buffer where the NbNsQuestionEntry starts</param>
        /// <param name="questionEntry">Parsed NbNsQuestionEntry if successful, else null</param>
        /// <returns><c>true</c> if parsing was successful, else <c>false</c></returns>
        public static bool TryParse(byte[] buffer, int offset, out NbNsQuestionEntry questionEntry)
        {
            questionEntry = null;
            NbName questionName;

            if (!NbName.TryParse(buffer, offset, out questionName))
            {
                return(false);
            }
            if (buffer.Length < offset + questionName.Length + 4)
            {
                return(false);
            }

            var questionType = (QuestionTypeSpecifier)BufferToUInt16(buffer, offset + questionName.Length);

            if (!Enum.IsDefined(typeof(QuestionTypeSpecifier), questionType))
            {
                return(false);
            }

            var questionClass = (QuestionClassSpecifier)BufferToUInt16(buffer, offset + questionName.Length + 2);

            if (!Enum.IsDefined(typeof(QuestionClassSpecifier), questionClass))
            {
                return(false);
            }

            questionEntry = new NbNsQuestionEntry(questionName, questionType);
            return(true);
        }
Example #3
0
        /// <summary>
        /// Tries to parse all the fields of a ResourceRecord except for the RDATA field
        /// </summary>
        /// <param name="buffer">Byte array containing the Resource Record</param>
        /// <param name="offset">Zero based offset in the buffer where the Resource Record starts</param>
        /// <returns><c>true</c> if parsing was successful, else <c>false</c></returns>
        /// <remarks>
        /// This method is called from derived classes in their TryParse method to parse the standard fields of
        /// every Resource Record. Only the RDATA field is different for each Resource Record and is therefore
        /// parsed by the specific TryParse methods of derived classes.
        /// </remarks>
        protected bool TryParse(byte[] buffer, int offset)
        {
            if (!NbName.TryParse(buffer, offset, out _rrName))
            {
                return(false);
            }
            var rrNameLength = _rrName.Length;

            if (buffer.Length < offset + rrNameLength + 2 + 2 + 4 + 2)
            {
                return(false);
            }

            RrType   = (RrTypeValue)BufferToUInt16(buffer, offset + rrNameLength + OFFSET_RR_TYPE);
            RrClass  = (RrClassValue)BufferToUInt16(buffer, offset + rrNameLength + OFFSET_RR_CLASS);
            Ttl      = BufferToUInt32(buffer, offset + rrNameLength + OFFSET_TTL);
            RdLength = BufferToUInt16(buffer, offset + rrNameLength + OFFSET_RD_LENGTH);

            return(buffer.Length >= offset + rrNameLength + 2 + 2 + 4 + 2 + RdLength);
        }
 /// <summary>
 /// Creates a new instance of <see cref="NbNsQuestionEntry"/> based on the given <see cref="questionName"/> and <see cref="questionType"/>
 /// </summary>
 /// <param name="questionName"><see cref="NbName"/> used for this object</param>
 /// <param name="questionType"><see cref="QuestionTypeSpecifier"/> used for this object</param>
 /// <remarks>
 /// <see cref="_questionClass"/> is always set to <see cref="QuestionClassSpecifier.In"/> as per NbNs spec.
 /// </remarks>
 public NbNsQuestionEntry(NbName questionName, QuestionTypeSpecifier questionType)
 {
     _questionName  = questionName;
     _questionType  = questionType;
     _questionClass = QuestionClassSpecifier.In;
 }