Ejemplo n.º 1
0
        public string GetAttributeKeys(MessageSTUN message)
        {
            string attrKeys = "";

            foreach (KeyValuePair <STUNAttribute, object> entry in message.response)
            {
                string key = Enum.GetName(typeof(STUNAttribute), entry.Key);
                int    id  = (int)entry.Key;
                if (attrKeys.Length > 0)
                {
                    attrKeys += "\n";
                }
                object value    = entry.Value;
                string valueStr = "";
                if (value is string v)
                {
                    valueStr = v;
                }
                else if (value is byte[] b)
                {
                    valueStr = NetworkSerializer.ByteArrayToHexString(b);
                }
                else
                {
                    valueStr = value.ToString();
                }
                attrKeys += key + "(" + id.ToString("X") + ") = " + valueStr;
            }
            return(attrKeys);
        }
Ejemplo n.º 2
0
        private void LogAttribute(int index)
        {
            SignalingAttribute attr     = attributeTypes[index];
            string             valueStr = "";

            if (response.ContainsKey(attr))
            {
                object value = response[attr];

                if (value is string v)
                {
                    valueStr = v;
                }
                else if (value is byte[] b)
                {
                    valueStr = NetworkSerializer.ByteArrayToHexString(b);
                }
                else
                {
                    valueStr = value.ToString();
                }
            }
        }
Ejemplo n.º 3
0
        public void LogAttribute(int index)
        {
            STUNAttribute attr     = attributeTypes[index];
            string        valueStr = "";

            if (response.ContainsKey(attr))
            {
                object value = response[attr];

                if (value is string v)
                {
                    valueStr = v;
                }
                else if (value is byte[] b)
                {
                    valueStr = NetworkSerializer.ByteArrayToHexString(b);
                }
                else
                {
                    valueStr = value.ToString();
                }
            }
            Console.WriteLine("Write Attribute: " + Enum.GetName(typeof(STUNAttribute), attr) + " = " + valueStr);
        }
Ejemplo n.º 4
0
        public void WriteBytes(SignalingAttribute attr, byte[] bytes)
        {
            serializer.SetBufferLength(0);
            serializer.Write((byte)attr);
            serializer.Write((ushort)bytes.Length);
            serializer.Write(bytes);

            //pad to multiple of 4
            PadTo32Bits(bytes.Length, serializer);

            Console.WriteLine("Attribute: " + Enum.GetName(typeof(SignalingAttribute), attr) + " = " + NetworkSerializer.ByteArrayToHexString((byte[])bytes));
            response.Add(attr, bytes);
            attributeTypes.Add(attr);
            attributeBytes.Add(serializer.ToArray());
        }