示例#1
0
        /// <summary>
        /// read struct from bytes. All sub class override this to unmarshal itself.
        /// </summary>
        /// <param name="start">the start to read bytes</param>
        /// <param name="packetBytes">the bytes of struct</param>
        /// <returns>the read result, if success, return true.</returns>
        protected override bool ReadStructFromBytes(
            byte[] packetBytes,
            int start
            )
        {
            NEGOTIATE_MESSAGE negotiate = new NEGOTIATE_MESSAGE();

            negotiate.NegotiateFlags    = (NegotiateTypes)NlmpUtility.BytesToStruct <uint>(packetBytes, ref start);
            negotiate.DomainNameFields  = NlmpUtility.BytesToStruct <MESSAGE_FIELDS>(packetBytes, ref start);
            negotiate.WorkstationFields = NlmpUtility.BytesToStruct <MESSAGE_FIELDS>(packetBytes, ref start);
            negotiate.Version           = NlmpUtility.BytesToStruct <VERSION>(packetBytes, ref start);

            int currentIndex = 0;

            while (currentIndex != start)
            {
                currentIndex = start;
                if (negotiate.DomainNameFields.Len != 0 && negotiate.DomainNameFields.BufferOffset == start)
                {
                    negotiate.DomainName = NlmpUtility.ReadBytes(
                        packetBytes, ref start, negotiate.DomainNameFields.Len);
                    continue;
                }
                else if (negotiate.WorkstationFields.Len != 0 && negotiate.WorkstationFields.BufferOffset == start)
                {
                    negotiate.WorkstationName = NlmpUtility.ReadBytes(
                        packetBytes, ref start, negotiate.WorkstationFields.Len);
                    continue;
                }
                else
                {
                    break;
                }
            }

            this.payload = negotiate;

            return(true);
        }
        /// <summary>
        /// copy constructor.
        /// </summary>
        public NlmpNegotiatePacket(
            NlmpNegotiatePacket stackPacket
            )
            : base(stackPacket)
        {
            this.payload = stackPacket.payload;

            if (stackPacket.payload.DomainName != null)
            {
                this.payload.DomainName = new byte[stackPacket.payload.DomainName.Length];
                Array.Copy(
                    stackPacket.payload.DomainName, this.payload.DomainName, stackPacket.payload.DomainName.Length
                    );
            }

            if (stackPacket.payload.WorkstationName != null)
            {
                this.payload.WorkstationName = new byte[stackPacket.payload.WorkstationName.Length];
                Array.Copy(
                    stackPacket.payload.WorkstationName, this.payload.WorkstationName,
                    stackPacket.payload.WorkstationName.Length);
            }
        }
示例#3
0
        /// <summary>
        /// copy constructor.
        /// </summary>
        public NlmpNegotiatePacket(
            NlmpNegotiatePacket stackPacket
            )
            : base(stackPacket)
        {
            this.payload = stackPacket.payload;

            if (stackPacket.payload.DomainName != null)
            {
                this.payload.DomainName = new byte[stackPacket.payload.DomainName.Length];
                Array.Copy(
                    stackPacket.payload.DomainName, this.payload.DomainName, stackPacket.payload.DomainName.Length
                    );
            }

            if (stackPacket.payload.WorkstationName != null)
            {
                this.payload.WorkstationName = new byte[stackPacket.payload.WorkstationName.Length];
                Array.Copy(
                    stackPacket.payload.WorkstationName, this.payload.WorkstationName,
                    stackPacket.payload.WorkstationName.Length);
            }
        }
        /// <summary>
        /// read struct from bytes. All sub class override this to unmarshal itself.
        /// </summary>
        /// <param name="start">the start to read bytes</param>
        /// <param name="packetBytes">the bytes of struct</param>
        /// <returns>the read result, if success, return true.</returns>
        protected override bool ReadStructFromBytes(
            byte[] packetBytes,
            int start
            )
        {
            NEGOTIATE_MESSAGE negotiate = new NEGOTIATE_MESSAGE();

            negotiate.NegotiateFlags = (NegotiateTypes)NlmpUtility.BytesToStruct<uint>(packetBytes, ref start);
            negotiate.DomainNameFields = NlmpUtility.BytesToStruct<MESSAGE_FIELDS>(packetBytes, ref start);
            negotiate.WorkstationFields = NlmpUtility.BytesToStruct<MESSAGE_FIELDS>(packetBytes, ref start);
            negotiate.Version = NlmpUtility.BytesToStruct<VERSION>(packetBytes, ref start);

            int currentIndex = 0;
            while (currentIndex != start)
            {
                currentIndex = start;
                if (negotiate.DomainNameFields.Len != 0 && negotiate.DomainNameFields.BufferOffset == start)
                {
                    negotiate.DomainName = NlmpUtility.ReadBytes(
                        packetBytes, ref start, negotiate.DomainNameFields.Len);
                    continue;
                }
                else if (negotiate.WorkstationFields.Len != 0 && negotiate.WorkstationFields.BufferOffset == start)
                {
                    negotiate.WorkstationName = NlmpUtility.ReadBytes(
                        packetBytes, ref start, negotiate.WorkstationFields.Len);
                    continue;
                }
                else
                {
                    break;
                }
            }

            this.payload = negotiate;

            return true;
        }