Exemple #1
0
 public void WriteTo(Stream stream)
 {
     foreach (string label in this)
     {
         if (label.Length == 0)
         {
             break;
         }
         byte[] bytes = Encoding.UTF8.GetBytes(label);
         //labels.Add(new KeyValuePair<byte[], byte>(bytes, (byte)bytes.Length));
         //totalLength += (ushort)(bytes.Length + 1);
         stream.WriteByte((byte)bytes.Length);
         BinaryHelper.Write(stream, bytes);
     }
     stream.WriteByte(0);
 }
Exemple #2
0
        internal static ResponseData Get(BinaryReader reader)
        {
            ushort byteCount         = BinaryHelper.ReadUInt16(reader);
            UnknownResponseData data = new UnknownResponseData();

            if (byteCount > 0)
            {
                data.Bytes = reader.ReadBytes(byteCount);
            }
            else
            {
                data.Bytes = new byte[0];
            }

            return(data);
        }
Exemple #3
0
        public static Question FromBytes(byte[] bytes, ref int index)
        {
            Question q = new Question();

            q.DomainName = DomainName.FromBytes(bytes, ref index);
            ushort s;

            BinaryHelper.FromBytes(bytes, index, out s);
            index += 2;
            q.Type = (QType)s;
            BinaryHelper.FromBytes(bytes, index, out s);
            q.Class = (QClass)s;
            index  += 2;

            return(q);
        }
Exemple #4
0
        public override void WriteTo(Stream writer)
        {
            ushort length = 0;
            List <KeyValuePair <byte[], byte> > bytes = new List <KeyValuePair <byte[], byte> >();

            foreach (KeyValuePair <string, string> kvp in Properties)
            {
                byte[] kvpBytes = Encoding.UTF8.GetBytes(kvp.Key + "=" + kvp.Value);
                bytes.Add(new KeyValuePair <byte[], byte>(kvpBytes, (byte)kvpBytes.Length));
                //writer.Write((byte)kvpBytes.Length);
                //writer.Write(kvpBytes);
                length += (ushort)kvpBytes.Length;
                length++;
            }
            BinaryHelper.Write(writer, length);
            foreach (var properties in bytes)
            {
                writer.WriteByte(properties.Value);
                BinaryHelper.Write(writer, properties.Key);
            }
        }
Exemple #5
0
 public override void WriteTo(Stream writer)
 {
     BinaryHelper.Write(writer, DomainName.GetByteCount());
     DomainName.WriteTo(writer);
 }
Exemple #6
0
 public override void WriteTo(Stream writer)
 {
     byte[] address = Address.GetAddressBytes();
     BinaryHelper.Write(writer, (ushort)address.Length);
     BinaryHelper.Write(writer, address);
 }
Exemple #7
0
 public override void WriteTo(Stream writer)
 {
     BinaryHelper.Write(writer, ((ushort)Encoding.UTF8.GetByteCount(CNAME)));
     BinaryHelper.Write(writer, Encoding.UTF8.GetBytes(CNAME));
 }
Exemple #8
0
 public byte[] GetBytes()
 {
     return(BinaryHelper.GetBytes(this));
 }
Exemple #9
0
 public void WriteTo(Stream stream)
 {
     DomainName.WriteTo(stream);
     BinaryHelper.Write(stream, (ushort)Type);
     BinaryHelper.Write(stream, (ushort)Class);
 }