コード例 #1
0
        /// <summary>
        /// Called by derived classes to initialize the <see cref="NbNsHeader"/> and the <see cref="PacketType"/> of a packet
        /// </summary>
        /// <param name="header"><see cref="NbNsHeader"/> of the packet</param>
        /// <param name="type"><see cref="PacketType"/> of the packet</param>
        protected NbNsPacketBase(NbNsHeader header, PacketTypes type)
        {
            PacketType = type;

            // The first packet segment is always the header; Further packet segments depend on the PacketType and are
            // added in the appropriate order by the constructors of derived classes.
            PacketSegments.Add(header);
        }
コード例 #2
0
ファイル: NbNsHeader.cs プロジェクト: pacificIT/MediaPortal-2
        /// <summary>
        /// Tries to parse a <see cref="NbNsHeader"/> from a buffer of bytes, starting at the first byte
        /// </summary>
        /// <param name="buffer">Byte array containing the NbNsHeader</param>
        /// <param name="header">Parsed NbNsHeader if successful, else null</param>
        /// <returns><c>true</c> if parsing was successful, else <c>false</c></returns>
        public static bool TryParse(byte[] buffer, out NbNsHeader header)
        {
            header = null;
            if (buffer == null || buffer.Length < NETBIOS_HEADER_LENGTH)
            {
                return(false);
            }

            header = new NbNsHeader(buffer);
            return(true);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
 /// <summary>
 /// Creates a new instance of <see cref="NbNsNodeStatusResponse"/> basedon the given <see cref="NbNsHeader"/> and <see cref="NbNsNodeStatusResponseResourceRecord"/>
 /// </summary>
 /// <param name="header"><see cref="NbNsHeader"/> to use for this <see cref="NbNsNodeStatusResponse"/></param>
 /// <param name="resourceRecord"><see cref="NbNsNodeStatusResponseResourceRecord"/> to use for this <see cref="NbNsNodeStatusResponse"/></param>
 public NbNsNodeStatusResponse(NbNsHeader header, NbNsNodeStatusResponseResourceRecord resourceRecord)
     : base(header, PacketTypes.NodeStatusResponse)
 {
     PacketSegments.Add(resourceRecord);
 }
コード例 #6
0
 /// <summary>
 /// Creates a new instance of <see cref="NbNsNodeStatusResponse"/> basedon the given <see cref="NbNsHeader"/> and <see cref="NbNsNodeStatusResponseResourceRecord"/>
 /// </summary>
 /// <param name="header"><see cref="NbNsHeader"/> to use for this <see cref="NbNsNodeStatusResponse"/></param>
 /// <param name="resourceRecord"><see cref="NbNsNodeStatusResponseResourceRecord"/> to use for this <see cref="NbNsNodeStatusResponse"/></param>
 public NbNsNodeStatusResponse(NbNsHeader header, NbNsNodeStatusResponseResourceRecord resourceRecord)
   : base(header, PacketTypes.NodeStatusResponse)
 {
   PacketSegments.Add(resourceRecord);
 }
コード例 #7
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;
    }
コード例 #8
0
    /// <summary>
    /// Called by derived classes to initialize the <see cref="NbNsHeader"/> and the <see cref="PacketType"/> of a packet
    /// </summary>
    /// <param name="header"><see cref="NbNsHeader"/> of the packet</param>
    /// <param name="type"><see cref="PacketType"/> of the packet</param>
    protected NbNsPacketBase(NbNsHeader header, PacketTypes type)
    {
      PacketType = type;

      // The first packet segment is always the header; Further packet segments depend on the PacketType and are
      // added in the appropriate order by the constructors of derived classes.
      PacketSegments.Add(header);
    }
コード例 #9
0
ファイル: NbNsHeader.cs プロジェクト: chekiI/MediaPortal-2
    /// <summary>
    /// Tries to parse a <see cref="NbNsHeader"/> from a buffer of bytes, starting at the first byte
    /// </summary>
    /// <param name="buffer">Byte array containing the NbNsHeader</param>
    /// <param name="header">Parsed NbNsHeader if successful, else null</param>
    /// <returns><c>true</c> if parsing was successful, else <c>false</c></returns>
    public static bool TryParse(byte[] buffer, out NbNsHeader header)
    {
      header = null;
      if (buffer == null || buffer.Length < NETBIOS_HEADER_LENGTH)
        return false;

      header = new NbNsHeader(buffer);
      return true;
    }