Example #1
0
        public MessageHeader(byte[] data)
        {
            MessageAttributes = new List <MessageAttribute> ();

            byte[] typeBytes = new byte[2];
            Array.Copy(data, typeBytes, 2);
            MessageType = (MessageType)Utility.TwoBytesToInteger(typeBytes);

            byte[] lengthBytes = new byte[2];
            Array.Copy(data, 2, lengthBytes, 0, 2);
            int length = Utility.TwoBytesToInteger(lengthBytes);

            int position = 20;

            while (position < length)
            {
                byte[] attributeTypeBytes = new byte [2];
                Array.Copy(data, position, attributeTypeBytes, 0, 2);
                MessageAttributeType attributeType = (MessageAttributeType)Utility.TwoBytesToInteger(attributeTypeBytes);
                position += 2;

                byte[] attributeLengthBytes = new byte [2];
                Array.Copy(data, position, attributeLengthBytes, 0, 2);
                int attributeLength = Utility.TwoBytesToInteger(attributeLengthBytes);
                position += 2;

                byte[] attributeData = new byte [attributeLength];
                Array.Copy(data, position, attributeData, 0, attributeLength);

                if (MessageAttribute.TypeTable.ContainsKey(attributeType) == true)
                {
                    Type             type      = MessageAttribute.TypeTable [attributeType];
                    MessageAttribute attribute = (MessageAttribute)Activator.CreateInstance(type, new object[] { attributeData });
                    MessageAttributes.Add(attribute);
                }


                position += attributeLength;
            }
        }
Example #2
0
        public AddressAttributeBase(MessageAttributeType type, byte[] data) : base(type)
        {
            byte[] familyBytes = new byte[1];
            Array.Copy(data, 1, familyBytes, 0, 1);

            if (familyBytes[0] != 0x01)
            {
                throw new Exception("Invalid network family!");
            }
            else
            {
                this.addressFamily = AddressFamily.InterNetwork;
            }

            byte[] portBytes = new byte [2];
            Array.Copy(data, 2, portBytes, 0, 2);
            this.port = Utility.TwoBytesToInteger(portBytes);

            byte[] addressBytes = new byte [4];
            Array.Copy(data, 4, addressBytes, 0, 4);
            this.address = new IPAddress(BitConverter.ToInt32(addressBytes, 0));
        }
Example #3
0
 public AddressAttributeBase(MessageAttributeType type) : base(type)
 {
 }
Example #4
0
 public MessageAttribute(MessageAttributeType type)
 {
     this.type = type;
 }
Example #5
0
 public MessageAttribute(MessageAttributeType type)
 {
     this.type = type;
 }