예제 #1
0
        /// <summary>
        ///     Attempts to parse raw data into a structured packet
        /// </summary>
        /// <param name="buffer">Raw data to parse</param>
        /// <param name="tag">Parsed packet</param>
        /// <param name="count">The length of the packet in bytes</param>
        /// <param name="index">The index into the buffer at which the packet begins</param>
        /// <returns>True if parsing was successful, false if it is not.</returns>
        internal static bool TryParse(byte[] buffer, int index, int count, out SSIDTag tag)
        {
            try
            {
                if (count < MinimumParseableBytes)
                {
                    tag = null;
                    return(false);
                }

                using (var ms = new MemoryStream(buffer, index, count, false))
                {
                    using (var br = new BinaryReader(ms))
                    {
                        tag = new SSIDTag();
                        var tagType = br.ReadByte();
                        if (tagType != 0)
                        {
                            tag = null;
                            return(false);
                        }
                        tag.TagLength = br.ReadByte();
                        tag.SSIDBytes = br.ReadBytes(Math.Min(tag.TagLength, count - 2));
                        return(true);
                    }
                }
            }
            catch (Exception)
            {
                tag = null;
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        ///     Attempts to parse raw data into a structured packet
        /// </summary>
        /// <param name="buffer">Raw data to parse</param>
        /// <param name="tag">Parsed packet</param>
        /// <param name="count">The length of the packet in bytes</param>
        /// <param name="index">The index into the buffer at which the packet begins</param>
        /// <returns>True if parsing was successful, false if it is not.</returns>
        internal static bool TryParse(byte[] buffer, int index, int count, out SSIDTag tag)
        {
            try
            {
                if (count < MinimumParseableBytes)
                {
                    tag = null;
                    return false;
                }

                using (var ms = new MemoryStream(buffer, index, count, false))
                {
                    using (var br = new BinaryReader(ms))
                    {
                        tag = new SSIDTag();
                        var tagType = br.ReadByte();
                        if (tagType != 0)
                        {
                            tag = null;
                            return false;
                        }
                        tag.TagLength = br.ReadByte();
                        tag.SSIDBytes = br.ReadBytes(Math.Min(tag.TagLength, count - 2));
                        return true;
                    }
                }
            }
            catch (Exception)
            {
                tag = null;
                return false;
            }
        }