Beispiel #1
0
        /// <summary>
        /// Tries to parse a <see cref="NbNsNodeStatusResponse"/> from a buffer of bytes starting after <see cref="NbNsHeader.NETBIOS_HEADER_LENGTH"/> bytes
        /// </summary>
        /// <param name="header"><see cref="NbNsHeader"/> already parsed from the beginning of <see cref="buffer"/></param>
        /// <param name="buffer">Byte array containing the NbNsNodeStatusResponse</param>
        /// <param name="result">Parsed NbNsNodeStatusResponse if successful, else null</param>
        /// <returns><c>true</c> if parsing was successful, else <c>false</c></returns>
        /// <remarks>
        /// This method is only called from <see cref="NbNsPacketBase.TryParse"/>.
        /// </remarks>
        internal static bool TryParse(NbNsHeader header, byte[] buffer, out NbNsNodeStatusResponse result)
        {
            result = null;

            NbNsNodeStatusResponseResourceRecord rr;

            if (!NbNsNodeStatusResponseResourceRecord.TryParse(buffer, NbNsHeader.NETBIOS_HEADER_LENGTH, out rr))
            {
                return(false);
            }

            result = new NbNsNodeStatusResponse(header, rr);
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Tries to parse a Netbios Name Service packet from a buffer of bytes
        /// </summary>
        /// <param name="buffer">Byte array containing the NbNs packet</param>
        /// <param name="packet">Parsed NbNs packet if successful, else null</param>
        /// <returns><c>true</c> if parsing was successful, else <c>false</c></returns>
        /// <remarks>
        /// This method is the entry point for parsing Netbios Name Service packets. It returns an object of a class
        /// derived from <see cref="NbNsPacketBase"/>, which can then be casted based on <see cref="PacketType"/> to
        /// the respective derived class.
        /// </remarks>
        public static bool TryParse(byte[] buffer, out NbNsPacketBase packet)
        {
            packet = null;
            if (buffer == null || buffer.Length < NbNsHeader.NETBIOS_HEADER_LENGTH)
            {
                return(false);
            }

            NbNsHeader header;

            if (!NbNsHeader.TryParse(buffer, out header))
            {
                return(false);
            }

            if (header.Opcode == NbNsHeader.OpcodeSpecifier.Query && header.IsResponse == false && header.IsRecursionDesired == false)
            {
                // Must be a Netbios Node Status Request
                NbNsNodeStatusRequest result;
                if (!NbNsNodeStatusRequest.TryParse(header, buffer, out result))
                {
                    return(false);
                }
                packet = result;
            }
            else if (header.Opcode == NbNsHeader.OpcodeSpecifier.Query && header.IsRecursionDesired == false)
            {
                // Must be a Netbios Node Status Response
                NbNsNodeStatusResponse result;
                if (!NbNsNodeStatusResponse.TryParse(header, buffer, out result))
                {
                    return(false);
                }
                packet = result;
            }

            // ToDo: Parse Further Netbios Name Service packets

            return(true);
        }
    /// <summary>
    /// Tries to parse a <see cref="NbNsNodeStatusResponse"/> from a buffer of bytes starting after <see cref="NbNsHeader.NETBIOS_HEADER_LENGTH"/> bytes
    /// </summary>
    /// <param name="header"><see cref="NbNsHeader"/> already parsed from the beginning of <see cref="buffer"/></param>
    /// <param name="buffer">Byte array containing the NbNsNodeStatusResponse</param>
    /// <param name="result">Parsed NbNsNodeStatusResponse if successful, else null</param>
    /// <returns><c>true</c> if parsing was successful, else <c>false</c></returns>
    /// <remarks>
    /// This method is only called from <see cref="NbNsPacketBase.TryParse"/>.
    /// </remarks>
    internal static bool TryParse(NbNsHeader header, byte[] buffer, out NbNsNodeStatusResponse result)
    {
      result = null;

      NbNsNodeStatusResponseResourceRecord rr;
      if (!NbNsNodeStatusResponseResourceRecord.TryParse(buffer, NbNsHeader.NETBIOS_HEADER_LENGTH, out rr))
        return false;

      result = new NbNsNodeStatusResponse(header, rr);
      return true;
    }