Supports the parsing of Dns Packets.

This is a very naive implementation and lacks support for services other than address lookup (Type=A) and pointer look up (Type=Ptr). Because I haven't found a service that used inverse querying for name look up, only pointer look up is implemented.

Exceptions will not occur when parsing byte arrays, only when attempting to create from scratch new packets with unsupported Types.

A Dns packet ... 1 1 1 1 1 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | ID | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |QR| Opcode |AA|TC|RD|RA| Z | RCODE | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | QDCOUNT | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | ANCOUNT | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | NSCOUNT | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | ARCOUNT | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | | QueryS / / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | | RESPONSES / / +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ Field Description ID identification - client generated, do not change QR query / reply, client sends 0, server replies 1 Opcode 0 for query, 1 inverse query AA Authoritative answer - True when there is a mapping TC Truncation - ignored - 0 RD Recursion desired RA Recursion availabled ZReserved - must be 0 RCODE ignored, stands for error code - 0 QDCOUNT questions - should be 1 ANCOUNT answers - should be 0 until we answer! NSCOUNT name server records - somewhat supported, but I can't find a reason why it needs to be so I've left in ZoneAuthority code in case it is ever needed! ARCOUNT additional records - unsupported
Inheritance: Brunet.DataPacket
Beispiel #1
0
        /**
         * <summary>Creates a response from the parameter fields with RData being
         * a memory chunk.  This is for MDns which supports caching</summary>
         * <param name="Name">The name resolved.</param>
         * <param name="Type">The query type.</param>
         * <param name="Class">The network type.</param>
         * <param name="CacheFlush">Flush the dns cache in the client.</param>
         * <param name="Ttl">How long to hold the result in the local dns cache.</param>
         * <param name="RData">RData in String format.</param>
         */
        public Response(string name, DnsPacket.Types type, DnsPacket.Classes class_type,
                        bool cache_flush, int ttl, String rdata)
        {
            Name       = name;
            Class      = class_type;
            Ttl        = ttl;
            Type       = type;
            CacheFlush = cache_flush;
            RData      = rdata;

            if (Type == DnsPacket.Types.A || Type == DnsPacket.Types.AAAA)
            {
                NameBlob  = DnsPacket.HostnameStringToMemBlock(Name);
                RDataBlob = DnsPacket.IPStringToMemBlock(RData);
            }
            else if (Type == DnsPacket.Types.Ptr)
            {
                if (DnsPacket.StringIsIP(Name))
                {
                    NameBlob = DnsPacket.PtrStringToMemBlock(Name);
                }
                else
                {
                    NameBlob = DnsPacket.HostnameStringToMemBlock(Name);
                }
                RDataBlob = DnsPacket.HostnameStringToMemBlock(RData);
            }
            else
            {
                throw new Exception("Invalid Query Type: " + Type + "!");
            }

            RdLength = (short)RDataBlob.Length;
            // 2 for Type + 2 for Class + 4 for Ttl + 2 for RdLength
            byte[] data = new byte[10];
            int    idx  = 0;

            data[idx++] = (byte)((((int)Type) >> 8) & 0xFF);
            data[idx++] = (byte)(((int)Type) & 0xFF);

            byte cf = 0x80;

            if (!CacheFlush)
            {
                cf = 0x00;
            }

            data[idx++] = (byte)(((((int)Class) >> 8) & 0x7F) | cf);
            data[idx++] = (byte)(((int)Class) & 0xFF);
            data[idx++] = (byte)((Ttl >> 24) & 0xFF);
            data[idx++] = (byte)((Ttl >> 16) & 0xFF);
            data[idx++] = (byte)((Ttl >> 8) & 0xFF);
            data[idx++] = (byte)(Ttl & 0xFF);
            data[idx++] = (byte)((RdLength >> 8) & 0xFF);
            data[idx]   = (byte)(RdLength & 0xFF);

            _icpacket = new CopyList(NameBlob, MemBlock.Reference(data), RDataBlob);
        }
Beispiel #2
0
    /// <summary>Look up a hostname given a Dns request in the form of IPPacket
    /// </summary>
    /// <param name="in_ip">An IPPacket containing the Dns request</param>
    /// <returns>An IPPacket containing the results</returns>
    public virtual IPPacket LookUp(IPPacket in_ip)
    {
      UdpPacket in_udp = new UdpPacket(in_ip.Payload);
      DnsPacket in_dns = new DnsPacket(in_udp.Payload);
      ICopyable out_dns = null;
      string qname = string.Empty;
      bool invalid_qtype = false;

      try {
        string qname_response = String.Empty;
        qname = in_dns.Questions[0].QName;
        DnsPacket.Types type = in_dns.Questions[0].QType;

        if(type == DnsPacket.Types.A || type == DnsPacket.Types.AAAA) {
          qname_response = AddressLookUp(qname);
        } else if(type == DnsPacket.Types.Ptr) {
          qname_response = NameLookUp(qname);
        } else {
          invalid_qtype = true;
        }

        if(qname_response == null) {
          throw new Exception("Unable to resolve");
        }

        Response response = new Response(qname, in_dns.Questions[0].QType,
            in_dns.Questions[0].QClass, 1800, qname_response);
        //Host resolver will not accept if recursive is not available 
        //when it is desired
        DnsPacket res_packet = new DnsPacket(in_dns.ID, false,
            in_dns.Opcode, true, in_dns.RD, in_dns.RD,
            in_dns.Questions, new Response[] {response}, null, null);

        out_dns = res_packet.ICPacket;
      } catch(Exception e) {
        bool failed_resolve = false;
        // The above resolver failed, let's see if another resolver works
        if(_forward_queries) {
          try {
            out_dns = Resolve(_name_server, (byte[]) in_dns.Packet);
          } catch(Exception ex) {
            e = ex;
            failed_resolve = true;
          }
        }

        if(!_forward_queries || failed_resolve) {
          ProtocolLog.WriteIf(IpopLog.Dns, "Failed to resolve: " + qname + "\n\t" + e.Message);
          out_dns = DnsPacket.BuildFailedReplyPacket(in_dns, !invalid_qtype);
        }
      }

      UdpPacket out_udp = new UdpPacket(in_udp.DestinationPort,
                                         in_udp.SourcePort, out_dns);
      return new IPPacket(IPPacket.Protocols.Udp, in_ip.DestinationIP,
                                       in_ip.SourceIP,
                                       out_udp.ICPacket);
    }
Beispiel #3
0
 /**
  * <summary>Given a DnsPacket, it will generate a failure message so that
  * the local resolver can move on to the next nameserver without timeouting
  * on the this one.</summary>
  * <param name="Packet">The base packet to translate into a failed response
  * </param>
  */
 public static MemBlock BuildFailedReplyPacket(DnsPacket Packet,
                                               bool refused_implemented)
 {
     byte[] res = new byte[Packet.Packet.Length];
     Packet.Packet.CopyTo(res, 0);
     if (refused_implemented)
     {
         res[3] |= 5;
     }
     else
     {
         res[3] |= 4;
     }
     res[2] |= 0x80;
     return(MemBlock.Reference(res));
 }
Beispiel #4
0
        public void TestHostname()
        {
            String   hostname  = "yo-in-f104.google.com";
            MemBlock hostnamem = MemBlock.Reference(new byte[] { 0x0a, 0x79, 0x6f,
                                                                 0x2d, 0x69, 0x6e, 0x2d, 0x66, 0x31, 0x30, 0x34, 0x06, 0x67, 0x6f, 0x6f,
                                                                 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00 });

            Assert.AreEqual(hostname, DnsPacket.HostnameMemBlockToString(hostnamem),
                            "HostnameMemBlockToString");
            Assert.AreEqual(hostnamem, DnsPacket.HostnameStringToMemBlock(hostname),
                            "HostnameStringToMemBlock");
            Assert.AreEqual(hostname, DnsPacket.HostnameMemBlockToString(
                                DnsPacket.HostnameStringToMemBlock(hostname)),
                            "Hostname String dual");
            Assert.AreEqual(hostnamem, DnsPacket.HostnameStringToMemBlock(
                                DnsPacket.HostnameMemBlockToString(hostnamem)),
                            "Hostname MemBlock dual");
        }
Beispiel #5
0
        public void TestMDns()
        {
            MemBlock mdnsm = MemBlock.Reference(new byte[] { 0x00, 0x00, 0x84, 0x00,
                                                             0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x12, 0x4c, 0x61, 0x70,
                                                             0x70, 0x79, 0x40, 0x64, 0x61, 0x76, 0x69, 0x64, 0x2d, 0x6c, 0x61, 0x70,
                                                             0x74, 0x6f, 0x70, 0x09, 0x5f, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63,
                                                             0x65, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c,
                                                             0x00, 0x00, 0x21, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x15, 0x00,
                                                             0x00, 0x00, 0x00, 0x14, 0xb2, 0x0c, 0x64, 0x61, 0x76, 0x69, 0x64, 0x2d,
                                                             0x6c, 0x61, 0x70, 0x74, 0x6f, 0x70, 0xc0, 0x2e, 0xc0, 0x0c, 0x00, 0x10,
                                                             0x80, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0x5c, 0x04, 0x76, 0x63, 0x3d,
                                                             0x21, 0x09, 0x76, 0x65, 0x72, 0x3d, 0x32, 0x2e, 0x33, 0x2e, 0x31, 0x0e,
                                                             0x6e, 0x6f, 0x64, 0x65, 0x3d, 0x6c, 0x69, 0x62, 0x70, 0x75, 0x72, 0x70,
                                                             0x6c, 0x65, 0x0c, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x3d, 0x61, 0x76,
                                                             0x61, 0x69, 0x6c, 0x0e, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x70, 0x32, 0x70,
                                                             0x6a, 0x3d, 0x35, 0x32, 0x39, 0x38, 0x0d, 0x6c, 0x61, 0x73, 0x74, 0x3d,
                                                             0x57, 0x6f, 0x6c, 0x69, 0x6e, 0x73, 0x6b, 0x79, 0x09, 0x31, 0x73, 0x74,
                                                             0x3d, 0x44, 0x61, 0x76, 0x69, 0x64, 0x09, 0x74, 0x78, 0x74, 0x76, 0x65,
                                                             0x72, 0x73, 0x3d, 0x31, 0x09, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
                                                             0x65, 0x73, 0x07, 0x5f, 0x64, 0x6e, 0x73, 0x2d, 0x73, 0x64, 0x04, 0x5f,
                                                             0x75, 0x64, 0x70, 0xc0, 0x2e, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x11,
                                                             0x94, 0x00, 0x02, 0xc0, 0x1f, 0xc0, 0x1f, 0x00, 0x0c, 0x00, 0x01, 0x00,
                                                             0x00, 0x11, 0x94, 0x00, 0x02, 0xc0, 0x0c, 0xc0, 0x45, 0x00, 0x01, 0x80,
                                                             0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x04, 0x0a, 0xe3, 0x38, 0x88 });

            DnsPacket mdns = new DnsPacket(mdnsm);

            Assert.AreEqual(mdns.Questions.Length, 0, "Questions");
            Assert.AreEqual(mdns.Answers.Length, 4, "Answers");
            Assert.AreEqual(mdns.Authority.Length, 0, "Authority");
            Assert.AreEqual(mdns.Additional.Length, 1, "Additional");
            DnsPacket dnsp = new DnsPacket(mdns.ID, mdns.Query, mdns.Opcode, mdns.AA,
                                           mdns.RD, mdns.RA, null, mdns.Answers,
                                           null, mdns.Additional);

            Assert.AreEqual(mdnsm, dnsp.Packet, "Packet");
            Assert.AreEqual(dnsp.Additional[0].Name, "david-laptop.local", "Name");
            Assert.AreEqual(dnsp.Additional[0].Type, DnsPacket.Types.A, "Type");
            Assert.AreEqual(dnsp.Additional[0].Class, DnsPacket.Classes.IN, "Class");
            Assert.AreEqual(dnsp.Additional[0].CacheFlush, true, "CacheFlush");
            Assert.AreEqual(dnsp.Additional[0].Ttl, 120, "Ttl");
            Assert.AreEqual(dnsp.Additional[0].RData, "10.227.56.136", "RData");
        }
Beispiel #6
0
        public void TestPtr()
        {
            String   ptr  = "64.233.169.104";
            MemBlock ptrm = MemBlock.Reference(new byte[] { 0x03, 0x31, 0x30, 0x34,
                                                            0x03, 0x31, 0x36, 0x39, 0x03, 0x32, 0x33, 0x33, 0x02, 0x36, 0x34, 0x07,
                                                            0x69, 0x6e, 0x2d, 0x61, 0x64, 0x64, 0x72, 0x04, 0x61, 0x72, 0x70, 0x61,
                                                            0x00 });

            Assert.AreEqual(ptr, DnsPacket.PtrMemBlockToString(ptrm),
                            "PtrMemBlockToString");
            Assert.AreEqual(ptrm, DnsPacket.PtrStringToMemBlock(ptr),
                            "PtrStringToMemBlock");
            Assert.AreEqual(ptr, DnsPacket.PtrMemBlockToString(
                                DnsPacket.PtrStringToMemBlock(ptr)),
                            "Ptr String dual");
            Assert.AreEqual(ptrm, DnsPacket.PtrStringToMemBlock(
                                DnsPacket.PtrMemBlockToString(ptrm)),
                            "Ptr MemBlock dual");
        }
Beispiel #7
0
        /**
         * <summary>Creates a response given the entire packet.</summary>
         * <remarks>The entire packet must be given, because some name servers take
         * advantage of pointers to reduce their size.</remarks>
         * <param name="Data">The entire Dns packet.</param>
         * <param name="Start">The starting position of the Response.</param>
         */
        public Response(MemBlock Data, int Start)
        {
            int idx = 0;

            NameBlob = DnsPacket.RetrieveBlob(Data, Start, out idx);

            int type = (Data[idx++] << 8) + Data[idx++];

            Type = (DnsPacket.Types)type;

            CacheFlush = ((Data[idx] & 0x80) == 0x80) ? true : false;
            int rclass = ((Data[idx++] << 8) & 0x7F) + Data[idx++];

            Class = (DnsPacket.Classes)rclass;

            Ttl  = (Data[idx++] << 24);
            Ttl |= (Data[idx++] << 16);
            Ttl |= (Data[idx++] << 8);
            Ttl |= (Data[idx++]);

            RdLength  = (short)((Data[idx++] << 8) + Data[idx++]);
            RDataBlob = Data.Slice(idx, RdLength);

            if (Type == DnsPacket.Types.Ptr)
            {
                try {
                    Name = DnsPacket.PtrMemBlockToString(NameBlob);
                }
                catch {
                    Name = DnsPacket.HostnameMemBlockToString(NameBlob);
                }
                int End = 0;
                RDataBlob = DnsPacket.RetrieveBlob(Data, idx, out End);
                RData     = DnsPacket.HostnameMemBlockToString(RDataBlob);
            }
            else if (Type == DnsPacket.Types.A)
            {
                Name  = DnsPacket.HostnameMemBlockToString(NameBlob);
                RData = DnsPacket.IPMemBlockToString(RDataBlob);
            }
            _icpacket = _packet = Data.Slice(Start, idx + RdLength - Start);
        }
Beispiel #8
0
        public void TestMDns0()
        {
            MemBlock mdnsm = MemBlock.Reference(new byte[] { 0x00, 0x00, 0x00, 0x00,
                                                             0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0E, 0x64, 0x61, 0x76,
                                                             0x69, 0x64, 0x69, 0x77, 0x2D, 0x6C, 0x61, 0x70, 0x74, 0x6F, 0x70, 0x05,
                                                             0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x00, 0x00, 0xFF, 0x00, 0x01, 0xC0, 0x0C,
                                                             0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x04, 0x0A, 0xFE,
                                                             0x00, 0x01 });
            DnsPacket mdns = new DnsPacket(mdnsm);

            Assert.AreEqual(mdns.Questions.Length, 1, "Questions");
            Assert.AreEqual(mdns.Answers.Length, 0, "Answers");
            Assert.AreEqual(mdns.Authority.Length, 1, "Authority");
            Assert.AreEqual(mdns.Additional.Length, 0, "Additional");
            DnsPacket dnsp = new DnsPacket(mdns.ID, mdns.Query, mdns.Opcode, mdns.AA,
                                           mdns.RD, mdns.RA, mdns.Questions, mdns.Answers,
                                           mdns.Authority, mdns.Additional);

            Assert.AreEqual(dnsp.Authority[0].Name, "davidiw-laptop.local", "Name");
            Assert.AreEqual(dnsp.Authority[0].Type, DnsPacket.Types.A, "Type");
            Assert.AreEqual(dnsp.Authority[0].Class, DnsPacket.Classes.IN, "Class");
            Assert.AreEqual(dnsp.Authority[0].CacheFlush, false, "CacheFlush");
            Assert.AreEqual(dnsp.Authority[0].Ttl, 120, "Ttl");
            Assert.AreEqual(dnsp.Authority[0].RData, "10.254.0.1", "RData");

            Response old = mdns.Authority[0];

            mdns.Authority[0] = new Response(old.Name, old.Type, old.Class,
                                             old.CacheFlush, old.Ttl, "10.254.111.252");

            dnsp = new DnsPacket(mdns.ID, mdns.Query, mdns.Opcode, mdns.AA,
                                 mdns.RD, mdns.RA, mdns.Questions, mdns.Answers,
                                 mdns.Authority, mdns.Additional);

            Assert.AreEqual(dnsp.Authority[0].Name, "davidiw-laptop.local", "Name");
            Assert.AreEqual(dnsp.Authority[0].Type, DnsPacket.Types.A, "Type");
            Assert.AreEqual(dnsp.Authority[0].Class, DnsPacket.Classes.IN, "Class");
            Assert.AreEqual(dnsp.Authority[0].CacheFlush, false, "CacheFlush");
            Assert.AreEqual(dnsp.Authority[0].Ttl, 120, "Ttl");
            Assert.AreEqual(dnsp.Authority[0].RData, "10.254.111.252", "RData");
        }
Beispiel #9
0
        public void TestIP()
        {
            String   ip  = "208.80.152.3";
            MemBlock ipm = MemBlock.Reference(new byte[] { 0xd0, 0x50, 0x98, 0x03 });

            Assert.AreEqual(ip, DnsPacket.IPMemBlockToString(ipm),
                            "IPMemBlockToString");
            Assert.AreEqual(ipm, DnsPacket.IPStringToMemBlock(ip),
                            "IPStringToMemBlock");
            Assert.AreEqual(ip, DnsPacket.IPMemBlockToString(
                                DnsPacket.IPStringToMemBlock(ip)),
                            "IP String dual");
            Assert.AreEqual(ipm, DnsPacket.IPStringToMemBlock(
                                DnsPacket.IPMemBlockToString(ipm)),
                            "IP MemBlock dual");

            String   bad_ip  = "Test.Test.Test.123";
            MemBlock bad_ipm = null;

            try {
                bad_ipm = DnsPacket.IPStringToMemBlock(bad_ip);
            } catch {}
            Assert.AreEqual(null, bad_ipm, "Bad IP");
        }
Beispiel #10
0
    /**
    <summary>Constructor when creating a Dns Query</summary>
    <param name="QName">the name of resource you are looking up, IP Address 
    when QType = Ptr otherwise hostname</param>
    <param name="QType"> the type of look up to perform</param>
    <param name="QClass">should always be IN</param>
    */
    public Question(String QName, DnsPacket.Types QType, DnsPacket.Classes QClass) {
      this.QName = QName;
      this.QType = QType;
      this.QClass = QClass;

      if(QType == DnsPacket.Types.A || QType == DnsPacket.Types.AAAA) {
        QNameBlob = DnsPacket.HostnameStringToMemBlock(QName);
      }
      else if(QType == DnsPacket.Types.Ptr) {
        QNameBlob = DnsPacket.PtrStringToMemBlock(QName);
      }
      else {
        throw new Exception("Invalid QType: " + QType + "!");
      }

        // 2 for QType + 2 for QClass
      byte[] data = new byte[4];
      int idx = 0;
      data[idx++] = (byte) ((((int) QType) >> 8) & 0xFF);
      data[idx++] = (byte) (((int) QType) & 0xFF);
      data[idx++] = (byte) ((((int) QClass) >> 8) & 0xFF);
      data[idx++] = (byte) (((int) QClass) & 0xFF);
      _icpacket = new CopyList(QNameBlob, MemBlock.Reference(data));
    }
Beispiel #11
0
        /**
         * <summary>Constructor when parsing a Dns Query</summary>
         * <param name="Data"> must pass in the entire packet from where the question
         * begins, after parsing, can check Data.Length to find where next
         * container begins.</param>
         */
        public Question(MemBlock Data, int Start)
        {
            int idx = 0;

            QNameBlob = DnsPacket.RetrieveBlob(Data, Start, out idx);
            int qtype = (Data[idx++] << 8) + Data[idx++];

            QType = (DnsPacket.Types)qtype;

            int qclass = (Data[idx++] << 8) + Data[idx];

            QClass = (DnsPacket.Classes)qclass;

            if (QType == DnsPacket.Types.A || QType == DnsPacket.Types.AAAA)
            {
                QName = DnsPacket.HostnameMemBlockToString(QNameBlob);
            }
            else if (QType == DnsPacket.Types.Ptr)
            {
                QName = DnsPacket.PtrMemBlockToString(QNameBlob);
            }

            _icpacket = _packet = Data.Slice(Start, idx + 1 - Start);
        }
Beispiel #12
0
    /**
    <summary>Creates a response from the parameter fields with RData being
    a memory chunk.  This is for MDns which supports caching</summary>
    <param name="Name">The name resolved.</param>
    <param name="Type">The query type.</param>
    <param name="Class">The network type.</param>
    <param name="CacheFlush">Flush the dns cache in the client.</param>
    <param name="Ttl">How long to hold the result in the local dns cache.</param>
    <param name="RData">RData in String format.</param>
    */
    public Response(string name, DnsPacket.Types type, DnsPacket.Classes class_type,
                    bool cache_flush, int ttl, String rdata) {
      Name = name;
      Class = class_type;
      Ttl = ttl;
      Type = type;
      CacheFlush = cache_flush;
      RData = rdata;

      if(Type == DnsPacket.Types.A) {
        NameBlob = DnsPacket.HostnameStringToMemBlock(Name);
        RDataBlob = DnsPacket.IPStringToMemBlock(RData);
      }
      else if(Type == DnsPacket.Types.Ptr) {
        if(DnsPacket.StringIsIP(Name)) {
          NameBlob = DnsPacket.PtrStringToMemBlock(Name);
        }
        else {
          NameBlob = DnsPacket.HostnameStringToMemBlock(Name);
        }
        RDataBlob = DnsPacket.HostnameStringToMemBlock(RData);
      }
      else {
        throw new Exception("Invalid Query Type: " + Type + "!");
      }

      RdLength = (short) RDataBlob.Length;
      // 2 for Type + 2 for Class + 4 for Ttl + 2 for RdLength
      byte[] data = new byte[10];
      int idx = 0;
      data[idx++] = (byte) ((((int) Type) >> 8) & 0xFF);
      data[idx++] = (byte) (((int) Type) & 0xFF);

      byte cf = 0x80;
      if(!CacheFlush) {
        cf = 0x00;
      }

      data[idx++] = (byte) (((((int) Class) >> 8) & 0x7F) | cf);
      data[idx++] = (byte) (((int) Class) & 0xFF);
      data[idx++] = (byte) ((Ttl >> 24) & 0xFF);
      data[idx++] = (byte) ((Ttl >> 16) & 0xFF);
      data[idx++] = (byte) ((Ttl >> 8) & 0xFF);
      data[idx++] = (byte) (Ttl & 0xFF);
      data[idx++] = (byte) ((RdLength >> 8) & 0xFF);
      data[idx] = (byte) (RdLength & 0xFF);

      _icpacket = new CopyList(NameBlob, MemBlock.Reference(data), RDataBlob);
    }
Beispiel #13
0
 /**
 <summary>Creates a response from the parameter fields with RData being
 a memory chunk.  This is for regular dns which has no notion of caching.
 </summary>
 <param name="Name">The name resolved.</param>
 <param name="Type">The query type.</param>
 <param name="Class">The network type.</param>
 <param name="CacheFlush">Flush the dns cache in the client.</param>
 <param name="Ttl">How long to hold the result in the local dns cache.</param>
 <param name="RData">RData in String format.</param>
 */
 public Response(String Name, DnsPacket.Types Type, DnsPacket.Classes Class,
   int Ttl, String RData): this(Name, Type, Class, false, Ttl, RData) {}
Beispiel #14
0
        public void TestPtrRPacketWithoutCompression()
        {
            int id = 55885;
              short ID = (short) id;
              bool Query = false;
              byte Opcode = 0;
              bool AA = false;

              String QName = "64.233.169.104";
              DnsPacket.Types QType = DnsPacket.Types.Ptr;
              DnsPacket.Classes QClass = DnsPacket.Classes.IN;
              Question qp = new Question(QName, QType, QClass);

              String Name = "64.233.169.104";
              DnsPacket.Types Type = DnsPacket.Types.Ptr;
              DnsPacket.Classes Class = DnsPacket.Classes.IN;
              int Ttl = 30;
              String RData = "yo-in-f104.google.com";
              Response rp = new Response(Name, Type, Class, Ttl, RData);

              DnsPacket dp = new DnsPacket(ID, Query, Opcode, AA, false, false,
                                   new Question[] {qp}, new Response[] {rp},
                                   null, null);

              MemBlock ptrm = MemBlock.Reference(new byte[] {0xda, 0x4d, 0x80, 0x00,
            0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x03, 0x31, 0x30, 0x34,
            0x03, 0x31, 0x36, 0x39, 0x03, 0x32, 0x33, 0x33, 0x02, 0x36, 0x34, 0x07,
            0x69, 0x6e, 0x2d, 0x61, 0x64, 0x64, 0x72, 0x04, 0x61, 0x72, 0x70, 0x61,
            0x00, 0x00, 0x0c, 0x00, 0x01, 0x03, 0x31, 0x30, 0x34, 0x03, 0x31, 0x36,
            0x39, 0x03, 0x32, 0x33, 0x33, 0x02, 0x36, 0x34, 0x07, 0x69, 0x6e, 0x2d,
            0x61, 0x64, 0x64, 0x72, 0x04, 0x61, 0x72, 0x70, 0x61, 0x00, 0x00, 0x0c,
            0x00, 0x01, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x17, 0x0a, 0x79, 0x6f, 0x2d,
            0x69, 0x6e, 0x2d, 0x66, 0x31, 0x30, 0x34, 0x06, 0x67, 0x6f, 0x6f, 0x67,
            0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00});

            DnsPacket dm = new DnsPacket(ptrm);
            Assert.AreEqual(dm.ID, ID, "ID");
            Assert.AreEqual(dm.Query, Query, "Query");
            Assert.AreEqual(dm.Opcode, Opcode, "Opcode");
            Assert.AreEqual(dm.AA, AA, "AA");
            Assert.AreEqual(dm.Questions.Length, 1, "Questions");
            Assert.AreEqual(dm.Answers.Length, 1, "Answers");
            Assert.AreEqual(dm.Packet, ptrm, "MemBlock");

            Response rm = dm.Answers[0];
            Assert.AreEqual(rm.Name, Name, "Name");
            Assert.AreEqual(rm.Type, Type, "Type");
            Assert.AreEqual(rm.Class, Class, "Class");
            Assert.AreEqual(rm.Ttl, Ttl, "Ttl");
            Assert.AreEqual(rm.RData, RData, "RData");

            Question qm = dm.Questions[0];
            Assert.AreEqual(qm.QName, Name, "QName");
            Assert.AreEqual(qm.QType, Type, "QType");
            Assert.AreEqual(qm.QClass, Class, "QClass");

            Assert.AreEqual(dp.Packet, ptrm, "Dns Packet");
        }
Beispiel #15
0
        public void TestMDns0()
        {
            MemBlock mdnsm = MemBlock.Reference(new byte[] {0x00, 0x00, 0x00, 0x00,
            0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0E, 0x64, 0x61, 0x76,
            0x69, 0x64, 0x69, 0x77, 0x2D, 0x6C, 0x61, 0x70, 0x74, 0x6F, 0x70, 0x05,
            0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x00, 0x00, 0xFF, 0x00, 0x01, 0xC0, 0x0C,
            0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x04, 0x0A, 0xFE,
            0x00, 0x01});
              DnsPacket mdns = new DnsPacket(mdnsm);

              Assert.AreEqual(mdns.Questions.Length, 1, "Questions");
              Assert.AreEqual(mdns.Answers.Length, 0, "Answers");
              Assert.AreEqual(mdns.Authority.Length, 1, "Authority");
              Assert.AreEqual(mdns.Additional.Length, 0, "Additional");
              DnsPacket dnsp = new DnsPacket(mdns.ID, mdns.Query, mdns.Opcode, mdns.AA,
                                     mdns.RD, mdns.RA, mdns.Questions, mdns.Answers,
                                     mdns.Authority, mdns.Additional);

              Assert.AreEqual(dnsp.Authority[0].Name, "davidiw-laptop.local", "Name");
              Assert.AreEqual(dnsp.Authority[0].Type, DnsPacket.Types.A, "Type");
              Assert.AreEqual(dnsp.Authority[0].Class, DnsPacket.Classes.IN, "Class");
              Assert.AreEqual(dnsp.Authority[0].CacheFlush, false, "CacheFlush");
              Assert.AreEqual(dnsp.Authority[0].Ttl, 120, "Ttl");
              Assert.AreEqual(dnsp.Authority[0].RData, "10.254.0.1", "RData");

              Response old = mdns.Authority[0];
              mdns.Authority[0] = new Response(old.Name, old.Type, old.Class,
                                         old.CacheFlush, old.Ttl, "10.254.111.252");

              dnsp = new DnsPacket(mdns.ID, mdns.Query, mdns.Opcode, mdns.AA,
                                     mdns.RD, mdns.RA, mdns.Questions, mdns.Answers,
                                     mdns.Authority, mdns.Additional);

              Assert.AreEqual(dnsp.Authority[0].Name, "davidiw-laptop.local", "Name");
              Assert.AreEqual(dnsp.Authority[0].Type, DnsPacket.Types.A, "Type");
              Assert.AreEqual(dnsp.Authority[0].Class, DnsPacket.Classes.IN, "Class");
              Assert.AreEqual(dnsp.Authority[0].CacheFlush, false, "CacheFlush");
              Assert.AreEqual(dnsp.Authority[0].Ttl, 120, "Ttl");
              Assert.AreEqual(dnsp.Authority[0].RData, "10.254.111.252", "RData");
        }
Beispiel #16
0
        public void TestMDns()
        {
            MemBlock mdnsm = MemBlock.Reference(new byte[] {0x00, 0x00, 0x84, 0x00,
            0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x12, 0x4c, 0x61, 0x70,
            0x70, 0x79, 0x40, 0x64, 0x61, 0x76, 0x69, 0x64, 0x2d, 0x6c, 0x61, 0x70,
            0x74, 0x6f, 0x70, 0x09, 0x5f, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x63,
            0x65, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c,
            0x00, 0x00, 0x21, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x15, 0x00,
            0x00, 0x00, 0x00, 0x14, 0xb2, 0x0c, 0x64, 0x61, 0x76, 0x69, 0x64, 0x2d,
            0x6c, 0x61, 0x70, 0x74, 0x6f, 0x70, 0xc0, 0x2e, 0xc0, 0x0c, 0x00, 0x10,
            0x80, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0x5c, 0x04, 0x76, 0x63, 0x3d,
            0x21, 0x09, 0x76, 0x65, 0x72, 0x3d, 0x32, 0x2e, 0x33, 0x2e, 0x31, 0x0e,
            0x6e, 0x6f, 0x64, 0x65, 0x3d, 0x6c, 0x69, 0x62, 0x70, 0x75, 0x72, 0x70,
            0x6c, 0x65, 0x0c, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x3d, 0x61, 0x76,
            0x61, 0x69, 0x6c, 0x0e, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x70, 0x32, 0x70,
            0x6a, 0x3d, 0x35, 0x32, 0x39, 0x38, 0x0d, 0x6c, 0x61, 0x73, 0x74, 0x3d,
            0x57, 0x6f, 0x6c, 0x69, 0x6e, 0x73, 0x6b, 0x79, 0x09, 0x31, 0x73, 0x74,
            0x3d, 0x44, 0x61, 0x76, 0x69, 0x64, 0x09, 0x74, 0x78, 0x74, 0x76, 0x65,
            0x72, 0x73, 0x3d, 0x31, 0x09, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
            0x65, 0x73, 0x07, 0x5f, 0x64, 0x6e, 0x73, 0x2d, 0x73, 0x64, 0x04, 0x5f,
            0x75, 0x64, 0x70, 0xc0, 0x2e, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x11,
            0x94, 0x00, 0x02, 0xc0, 0x1f, 0xc0, 0x1f, 0x00, 0x0c, 0x00, 0x01, 0x00,
            0x00, 0x11, 0x94, 0x00, 0x02, 0xc0, 0x0c, 0xc0, 0x45, 0x00, 0x01, 0x80,
            0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x04, 0x0a, 0xe3, 0x38, 0x88});

              DnsPacket mdns = new DnsPacket(mdnsm);

              Assert.AreEqual(mdns.Questions.Length, 0, "Questions");
              Assert.AreEqual(mdns.Answers.Length, 4, "Answers");
              Assert.AreEqual(mdns.Authority.Length, 0, "Authority");
              Assert.AreEqual(mdns.Additional.Length, 1, "Additional");
              DnsPacket dnsp = new DnsPacket(mdns.ID, mdns.Query, mdns.Opcode, mdns.AA,
                                     mdns.RD, mdns.RA, null, mdns.Answers,
                                     null, mdns.Additional);

              Assert.AreEqual(mdnsm, dnsp.Packet, "Packet");
              Assert.AreEqual(dnsp.Additional[0].Name, "david-laptop.local", "Name");
              Assert.AreEqual(dnsp.Additional[0].Type, DnsPacket.Types.A, "Type");
              Assert.AreEqual(dnsp.Additional[0].Class, DnsPacket.Classes.IN, "Class");
              Assert.AreEqual(dnsp.Additional[0].CacheFlush, true, "CacheFlush");
              Assert.AreEqual(dnsp.Additional[0].Ttl, 120, "Ttl");
              Assert.AreEqual(dnsp.Additional[0].RData, "10.227.56.136", "RData");
        }
Beispiel #17
0
        public void TestPtrRPacketWithoutCompression()
        {
            int   id     = 55885;
            short ID     = (short)id;
            bool  Query  = false;
            byte  Opcode = 0;
            bool  AA     = false;

            String QName = "64.233.169.104";

            DnsPacket.Types   QType  = DnsPacket.Types.Ptr;
            DnsPacket.Classes QClass = DnsPacket.Classes.IN;
            Question          qp     = new Question(QName, QType, QClass);

            String Name = "64.233.169.104";

            DnsPacket.Types   Type  = DnsPacket.Types.Ptr;
            DnsPacket.Classes Class = DnsPacket.Classes.IN;
            int      Ttl            = 30;
            String   RData          = "yo-in-f104.google.com";
            Response rp             = new Response(Name, Type, Class, Ttl, RData);

            DnsPacket dp = new DnsPacket(ID, Query, Opcode, AA, false, false,
                                         new Question[] { qp }, new Response[] { rp },
                                         null, null);

            MemBlock ptrm = MemBlock.Reference(new byte[] { 0xda, 0x4d, 0x80, 0x00,
                                                            0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x03, 0x31, 0x30, 0x34,
                                                            0x03, 0x31, 0x36, 0x39, 0x03, 0x32, 0x33, 0x33, 0x02, 0x36, 0x34, 0x07,
                                                            0x69, 0x6e, 0x2d, 0x61, 0x64, 0x64, 0x72, 0x04, 0x61, 0x72, 0x70, 0x61,
                                                            0x00, 0x00, 0x0c, 0x00, 0x01, 0x03, 0x31, 0x30, 0x34, 0x03, 0x31, 0x36,
                                                            0x39, 0x03, 0x32, 0x33, 0x33, 0x02, 0x36, 0x34, 0x07, 0x69, 0x6e, 0x2d,
                                                            0x61, 0x64, 0x64, 0x72, 0x04, 0x61, 0x72, 0x70, 0x61, 0x00, 0x00, 0x0c,
                                                            0x00, 0x01, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x17, 0x0a, 0x79, 0x6f, 0x2d,
                                                            0x69, 0x6e, 0x2d, 0x66, 0x31, 0x30, 0x34, 0x06, 0x67, 0x6f, 0x6f, 0x67,
                                                            0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00 });

            DnsPacket dm = new DnsPacket(ptrm);

            Assert.AreEqual(dm.ID, ID, "ID");
            Assert.AreEqual(dm.Query, Query, "Query");
            Assert.AreEqual(dm.Opcode, Opcode, "Opcode");
            Assert.AreEqual(dm.AA, AA, "AA");
            Assert.AreEqual(dm.Questions.Length, 1, "Questions");
            Assert.AreEqual(dm.Answers.Length, 1, "Answers");
            Assert.AreEqual(dm.Packet, ptrm, "MemBlock");

            Response rm = dm.Answers[0];

            Assert.AreEqual(rm.Name, Name, "Name");
            Assert.AreEqual(rm.Type, Type, "Type");
            Assert.AreEqual(rm.Class, Class, "Class");
            Assert.AreEqual(rm.Ttl, Ttl, "Ttl");
            Assert.AreEqual(rm.RData, RData, "RData");

            Question qm = dm.Questions[0];

            Assert.AreEqual(qm.QName, Name, "QName");
            Assert.AreEqual(qm.QType, Type, "QType");
            Assert.AreEqual(qm.QClass, Class, "QClass");

            Assert.AreEqual(dp.Packet, ptrm, "Dns Packet");
        }
Beispiel #18
0
 /**
 <summary>Given a DnsPacket, it will generate a failure message so that
 the local resolver can move on to the next nameserver without timeouting
 on the this one.</summary>
 <param name="Packet">The base packet to translate into a failed response
 </param>
 */
 public static MemBlock BuildFailedReplyPacket(DnsPacket Packet)
 {
     byte[] res = new byte[Packet.Packet.Length];
       Packet.Packet.CopyTo(res, 0);
       res[3] |= 5;
       res[2] |= 0x80;
       return MemBlock.Reference(res);
 }
Beispiel #19
0
 /**
 <summary>Given a DnsPacket, it will generate a failure message so that
 the local resolver can move on to the next nameserver without timeouting
 on the this one.</summary>
 <param name="Packet">The base packet to translate into a failed response
 </param>
 */
 public static MemBlock BuildFailedReplyPacket(DnsPacket Packet,
     bool refused_implemented)
 {
   byte[] res = new byte[Packet.Packet.Length];
   Packet.Packet.CopyTo(res, 0);
   if(refused_implemented) {
     res[3] |= 5;
   } else {
     res[3] |= 4;
   }
   res[2] |= 0x80;
   return MemBlock.Reference(res);
 }
Beispiel #20
0
        public void PtrNoIP()
        {
            MemBlock mdnsm = MemBlock.Reference(new byte[] { 0x00, 0x00, 0x84, 0x00,
                                                             0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x10, 0x50, 0x69, 0x65,
                                                             0x72, 0x72, 0x65, 0xe2, 0x80, 0x99, 0x73, 0x20, 0x4d, 0x75, 0x73, 0x69,
                                                             0x63, 0x05, 0x5f, 0x64, 0x61, 0x61, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70,
                                                             0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x21, 0x80, 0x01, 0x00,
                                                             0x00, 0x00, 0x78, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x69, 0x06,
                                                             0x70, 0x69, 0x65, 0x72, 0x72, 0x65, 0xc0, 0x28, 0xc0, 0x0c, 0x00, 0x10,
                                                             0x80, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0xb4, 0x09, 0x74, 0x78, 0x74,
                                                             0x76, 0x65, 0x72, 0x73, 0x3d, 0x31, 0x0c, 0x4f, 0x53, 0x73, 0x69, 0x3d,
                                                             0x30, 0x78, 0x32, 0x44, 0x46, 0x34, 0x35, 0x0e, 0x56, 0x65, 0x72, 0x73,
                                                             0x69, 0x6f, 0x6e, 0x3d, 0x31, 0x39, 0x36, 0x36, 0x31, 0x34, 0x1c, 0x44,
                                                             0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x20, 0x49, 0x44, 0x3d, 0x34,
                                                             0x44, 0x30, 0x43, 0x30, 0x42, 0x32, 0x30, 0x43, 0x39, 0x34, 0x46, 0x31,
                                                             0x42, 0x36, 0x31, 0x1d, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x20,
                                                             0x4e, 0x61, 0x6d, 0x65, 0x3d, 0x50, 0x69, 0x65, 0x72, 0x72, 0x65, 0xe2,
                                                             0x80, 0x99, 0x73, 0x20, 0x4d, 0x75, 0x73, 0x69, 0x63, 0x0e, 0x50, 0x61,
                                                             0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3d, 0x66, 0x61, 0x6c, 0x73, 0x65,
                                                             0x14, 0x4d, 0x65, 0x64, 0x69, 0x61, 0x20, 0x4b, 0x69, 0x6e, 0x64, 0x73,
                                                             0x20, 0x53, 0x68, 0x61, 0x72, 0x65, 0x64, 0x3d, 0x30, 0x16, 0x4d, 0x49,
                                                             0x44, 0x3d, 0x30, 0x78, 0x39, 0x30, 0x32, 0x43, 0x39, 0x44, 0x45, 0x34,
                                                             0x46, 0x35, 0x44, 0x46, 0x37, 0x45, 0x36, 0x46, 0x17, 0x4d, 0x61, 0x63,
                                                             0x68, 0x69, 0x6e, 0x65, 0x20, 0x49, 0x44, 0x3d, 0x32, 0x31, 0x42, 0x44,
                                                             0x36, 0x44, 0x37, 0x45, 0x31, 0x30, 0x36, 0x46, 0x09, 0x5f, 0x73, 0x65,
                                                             0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x07, 0x5f, 0x64, 0x6e, 0x73, 0x2d,
                                                             0x73, 0x64, 0x04, 0x5f, 0x75, 0x64, 0x70, 0xc0, 0x28, 0x00, 0x0c, 0x00,
                                                             0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0x02, 0xc0, 0x1d, 0xc0, 0x1d, 0x00,
                                                             0x0c, 0x00, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0x02, 0xc0, 0x0c, 0x1c,
                                                             0x69, 0x54, 0x75, 0x6e, 0x65, 0x73, 0x5f, 0x43, 0x74, 0x72, 0x6c, 0x5f,
                                                             0x34, 0x32, 0x36, 0x35, 0x37, 0x38, 0x32, 0x41, 0x43, 0x32, 0x46, 0x43,
                                                             0x46, 0x31, 0x41, 0x43, 0x05, 0x5f, 0x64, 0x61, 0x63, 0x70, 0xc0, 0x23,
                                                             0x00, 0x21, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x08, 0x00, 0x00,
                                                             0x00, 0x00, 0x0e, 0x69, 0xc0, 0x3f, 0xc1, 0x3b, 0x00, 0x10, 0x80, 0x01,
                                                             0x00, 0x00, 0x11, 0x94, 0x00, 0x37, 0x09, 0x74, 0x78, 0x74, 0x76, 0x65,
                                                             0x72, 0x73, 0x3d, 0x31, 0x09, 0x56, 0x65, 0x72, 0x3d, 0x36, 0x35, 0x35,
                                                             0x33, 0x37, 0x0c, 0x4f, 0x53, 0x73, 0x69, 0x3d, 0x30, 0x78, 0x32, 0x44,
                                                             0x46, 0x34, 0x35, 0x15, 0x44, 0x62, 0x49, 0x64, 0x3d, 0x34, 0x44, 0x30,
                                                             0x43, 0x30, 0x42, 0x32, 0x30, 0x43, 0x39, 0x34, 0x46, 0x31, 0x42, 0x36,
                                                             0x31, 0xc1, 0x08, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00,
                                                             0x02, 0xc1, 0x58, 0xc1, 0x58, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x11,
                                                             0x94, 0x00, 0x02, 0xc1, 0x3b, 0xc0, 0x3f, 0x00, 0x01, 0x80, 0x01, 0x00,
                                                             0x00, 0x00, 0x78, 0x00, 0x04, 0x0a, 0xfe, 0x00, 0x01, 0xc0, 0x3f, 0x00,
                                                             0x1c, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x10, 0xfe, 0x80, 0x00,
                                                             0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa9, 0xff, 0xfe, 0xe4, 0x23,
                                                             0x5f });
            DnsPacket mdns = new DnsPacket(mdnsm);

            Assert.AreEqual(mdns.Questions.Length, 0, "Questions");
            Assert.AreEqual(mdns.Answers.Length, 8, "Answers");
            Assert.AreEqual(mdns.Authority.Length, 0, "Authority");
            Assert.AreEqual(mdns.Additional.Length, 2, "Additional");
            MemBlock test = MemBlock.Reference(new byte[] { 0x1c, 0x69, 0x54, 0x75,
                                                            0x6e, 0x65, 0x73, 0x5f, 0x43, 0x74, 0x72, 0x6c, 0x5f, 0x34, 0x32, 0x36,
                                                            0x35, 0x37, 0x38, 0x32, 0x41, 0x43, 0x32, 0x46, 0x43, 0x46, 0x31, 0x41,
                                                            0x43, 0x05, 0x5f, 0x64, 0x61, 0x63, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70,
                                                            0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00 });

            Assert.AreEqual(mdns.Answers[5].NameBlob, test, "Answers[5].Name");
            Assert.AreEqual(mdns.Additional[0].Name, "pierre.local",
                            "Additional[0].Name");
            Assert.AreEqual(mdns.Additional[0].RData, "10.254.0.1",
                            "Additional[0].RData");
            Assert.AreEqual(mdns.Answers[2].Type, DnsPacket.Types.Ptr,
                            "Answers[2].Type");
            Response original = mdns.Answers[2];
            Response copy     = new Response(original.Name, original.Type,
                                             original.Class, original.CacheFlush,
                                             original.Ttl, original.RData);
            MemBlock original_expanded = MemBlock.Reference(new byte[] { 0x09, 0x5f,
                                                                         0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x07, 0x5f, 0x64, 0x6e,
                                                                         0x73, 0x2d, 0x73, 0x64, 0x04, 0x5f, 0x75, 0x64, 0x70, 0x05, 0x6c, 0x6f,
                                                                         0x63, 0x61, 0x6c, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x11, 0x94,
                                                                         0x00, 0x12, 0x05, 0x5f, 0x64, 0x61, 0x61, 0x70, 0x04, 0x5f, 0x74, 0x63,
                                                                         0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00 });

            Assert.AreEqual(original_expanded, copy.Packet, "original");
        }
Beispiel #21
0
        public void PtrNoIP()
        {
            MemBlock mdnsm = MemBlock.Reference(new byte[] {0x00, 0x00, 0x84, 0x00,
            0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x10, 0x50, 0x69, 0x65,
            0x72, 0x72, 0x65, 0xe2, 0x80, 0x99, 0x73, 0x20, 0x4d, 0x75, 0x73, 0x69,
            0x63, 0x05, 0x5f, 0x64, 0x61, 0x61, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70,
            0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x21, 0x80, 0x01, 0x00,
            0x00, 0x00, 0x78, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x69, 0x06,
            0x70, 0x69, 0x65, 0x72, 0x72, 0x65, 0xc0, 0x28, 0xc0, 0x0c, 0x00, 0x10,
            0x80, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0xb4, 0x09, 0x74, 0x78, 0x74,
            0x76, 0x65, 0x72, 0x73, 0x3d, 0x31, 0x0c, 0x4f, 0x53, 0x73, 0x69, 0x3d,
            0x30, 0x78, 0x32, 0x44, 0x46, 0x34, 0x35, 0x0e, 0x56, 0x65, 0x72, 0x73,
            0x69, 0x6f, 0x6e, 0x3d, 0x31, 0x39, 0x36, 0x36, 0x31, 0x34, 0x1c, 0x44,
            0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x20, 0x49, 0x44, 0x3d, 0x34,
            0x44, 0x30, 0x43, 0x30, 0x42, 0x32, 0x30, 0x43, 0x39, 0x34, 0x46, 0x31,
            0x42, 0x36, 0x31, 0x1d, 0x4d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x20,
            0x4e, 0x61, 0x6d, 0x65, 0x3d, 0x50, 0x69, 0x65, 0x72, 0x72, 0x65, 0xe2,
            0x80, 0x99, 0x73, 0x20, 0x4d, 0x75, 0x73, 0x69, 0x63, 0x0e, 0x50, 0x61,
            0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3d, 0x66, 0x61, 0x6c, 0x73, 0x65,
            0x14, 0x4d, 0x65, 0x64, 0x69, 0x61, 0x20, 0x4b, 0x69, 0x6e, 0x64, 0x73,
            0x20, 0x53, 0x68, 0x61, 0x72, 0x65, 0x64, 0x3d, 0x30, 0x16, 0x4d, 0x49,
            0x44, 0x3d, 0x30, 0x78, 0x39, 0x30, 0x32, 0x43, 0x39, 0x44, 0x45, 0x34,
            0x46, 0x35, 0x44, 0x46, 0x37, 0x45, 0x36, 0x46, 0x17, 0x4d, 0x61, 0x63,
            0x68, 0x69, 0x6e, 0x65, 0x20, 0x49, 0x44, 0x3d, 0x32, 0x31, 0x42, 0x44,
            0x36, 0x44, 0x37, 0x45, 0x31, 0x30, 0x36, 0x46, 0x09, 0x5f, 0x73, 0x65,
            0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x07, 0x5f, 0x64, 0x6e, 0x73, 0x2d,
            0x73, 0x64, 0x04, 0x5f, 0x75, 0x64, 0x70, 0xc0, 0x28, 0x00, 0x0c, 0x00,
            0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0x02, 0xc0, 0x1d, 0xc0, 0x1d, 0x00,
            0x0c, 0x00, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00, 0x02, 0xc0, 0x0c, 0x1c,
            0x69, 0x54, 0x75, 0x6e, 0x65, 0x73, 0x5f, 0x43, 0x74, 0x72, 0x6c, 0x5f,
            0x34, 0x32, 0x36, 0x35, 0x37, 0x38, 0x32, 0x41, 0x43, 0x32, 0x46, 0x43,
            0x46, 0x31, 0x41, 0x43, 0x05, 0x5f, 0x64, 0x61, 0x63, 0x70, 0xc0, 0x23,
            0x00, 0x21, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x08, 0x00, 0x00,
            0x00, 0x00, 0x0e, 0x69, 0xc0, 0x3f, 0xc1, 0x3b, 0x00, 0x10, 0x80, 0x01,
            0x00, 0x00, 0x11, 0x94, 0x00, 0x37, 0x09, 0x74, 0x78, 0x74, 0x76, 0x65,
            0x72, 0x73, 0x3d, 0x31, 0x09, 0x56, 0x65, 0x72, 0x3d, 0x36, 0x35, 0x35,
            0x33, 0x37, 0x0c, 0x4f, 0x53, 0x73, 0x69, 0x3d, 0x30, 0x78, 0x32, 0x44,
            0x46, 0x34, 0x35, 0x15, 0x44, 0x62, 0x49, 0x64, 0x3d, 0x34, 0x44, 0x30,
            0x43, 0x30, 0x42, 0x32, 0x30, 0x43, 0x39, 0x34, 0x46, 0x31, 0x42, 0x36,
            0x31, 0xc1, 0x08, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00,
            0x02, 0xc1, 0x58, 0xc1, 0x58, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x11,
            0x94, 0x00, 0x02, 0xc1, 0x3b, 0xc0, 0x3f, 0x00, 0x01, 0x80, 0x01, 0x00,
            0x00, 0x00, 0x78, 0x00, 0x04, 0x0a, 0xfe, 0x00, 0x01, 0xc0, 0x3f, 0x00,
            0x1c, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x10, 0xfe, 0x80, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa9, 0xff, 0xfe, 0xe4, 0x23,
            0x5f});
              DnsPacket mdns = new DnsPacket(mdnsm);

              Assert.AreEqual(mdns.Questions.Length, 0, "Questions");
              Assert.AreEqual(mdns.Answers.Length, 8, "Answers");
              Assert.AreEqual(mdns.Authority.Length, 0, "Authority");
              Assert.AreEqual(mdns.Additional.Length, 2, "Additional");
              MemBlock test = MemBlock.Reference(new byte[]{0x1c, 0x69, 0x54, 0x75,
            0x6e, 0x65, 0x73, 0x5f, 0x43, 0x74, 0x72, 0x6c, 0x5f, 0x34, 0x32, 0x36,
            0x35, 0x37, 0x38, 0x32, 0x41, 0x43, 0x32, 0x46, 0x43, 0x46, 0x31, 0x41,
            0x43, 0x05, 0x5f, 0x64, 0x61, 0x63, 0x70, 0x04, 0x5f, 0x74, 0x63, 0x70,
            0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00});
              Assert.AreEqual(mdns.Answers[5].NameBlob, test, "Answers[5].Name");
              Assert.AreEqual(mdns.Additional[0].Name, "pierre.local",
                      "Additional[0].Name");
              Assert.AreEqual(mdns.Additional[0].RData, "10.254.0.1",
                      "Additional[0].RData");
              Assert.AreEqual(mdns.Answers[2].Type, DnsPacket.Types.Ptr,
                      "Answers[2].Type");
              Response original = mdns.Answers[2];
              Response copy = new Response(original.Name, original.Type,
                                   original.Class, original.CacheFlush,
                                   original.Ttl, original.RData);
              MemBlock original_expanded = MemBlock.Reference(new byte[]{0x09, 0x5f,
            0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x07, 0x5f, 0x64, 0x6e,
            0x73, 0x2d, 0x73, 0x64, 0x04, 0x5f, 0x75, 0x64, 0x70, 0x05, 0x6c, 0x6f,
            0x63, 0x61, 0x6c, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x11, 0x94,
            0x00, 0x12, 0x05, 0x5f, 0x64, 0x61, 0x61, 0x70, 0x04, 0x5f, 0x74, 0x63,
            0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00});
              Assert.AreEqual(original_expanded, copy.Packet, "original");
        }
Beispiel #22
0
        public void Testdaap()
        {
            MemBlock mdnsm = MemBlock.Reference(new byte[] {0x00, 0x00, 0x00, 0x00,
            0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x50, 0x69, 0x65,
            0x72, 0x72, 0x65, 0x27, 0x73, 0x20, 0x4C, 0x69, 0x62, 0x72, 0x61, 0x72,
            0x79, 0x05, 0x5F, 0x64, 0x61, 0x61, 0x70, 0x04, 0x5F, 0x74, 0x63, 0x70,
            0x05, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x00, 0x00, 0xFF, 0x00, 0x01, 0xC0,
            0x0C, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x0D, 0x00,
            0x00, 0x00, 0x00, 0x0E, 0x69, 0x04, 0x50, 0x49, 0x42, 0x4D, 0xC0,
            0x2});
              DnsPacket mdns = new DnsPacket(mdnsm);
              Assert.AreEqual(mdns.Questions.Length, 1, "Questions");
              Assert.AreEqual(mdns.Answers.Length, 0, "Answers");
              Assert.AreEqual(mdns.Authority.Length, 1, "Authority");
              Assert.AreEqual(mdns.Additional.Length, 0, "Additional");

              Assert.AreEqual(mdns.Questions[0].QNameBlob,
            MemBlock.Reference(new byte[]{0x10, 0x50, 0x69, 0x65, 0x72, 0x72, 0x65,
            0x27, 0x73, 0x20, 0x4C, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x05, 0x5F,
            0x64, 0x61, 0x61, 0x70, 0x04, 0x5F, 0x74, 0x63, 0x70, 0x05, 0x6C, 0x6F,
            0x63, 0x61, 0x6C, 0x00}), "QName");
              Assert.AreEqual(mdns.Questions[0].QType, (DnsPacket.Types) 0xFF, "QType");
              Assert.AreEqual(mdns.Questions[0].QClass, DnsPacket.Classes.IN, "QClass");
        }