/** <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) { QNAME_BLOB = DNSPacket.HostnameStringToMemBlock(QNAME); } else if(QTYPE == DNSPacket.TYPES.PTR) { QNAME_BLOB = 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(QNAME_BLOB, MemBlock.Reference(data)); }
/// <summary>Look up a hostname given a DNS request in the form of IPPacket /// </summary> /// <param name="req_ipp">An IPPacket containing the DNS request</param> /// <returns>An IPPacket containing the results</returns> public virtual IPPacket LookUp(IPPacket req_ipp) { UDPPacket req_udpp = new UDPPacket(req_ipp.Payload); DNSPacket dnspacket = new DNSPacket(req_udpp.Payload); ICopyable rdnspacket = null; try { string qname_response = String.Empty; string qname = dnspacket.Questions[0].QNAME; if(dnspacket.Questions[0].QTYPE == DNSPacket.TYPES.A) { qname_response = AddressLookUp(qname); } else if(dnspacket.Questions[0].QTYPE == DNSPacket.TYPES.PTR) { if(!InRange(qname)) { throw new Exception("Address out of range."); } qname_response = NameLookUp(qname); } if(qname_response == null) { throw new Exception("Unable to resolve name: " + qname); } Response response = new Response(qname, dnspacket.Questions[0].QTYPE, dnspacket.Questions[0].QCLASS, 1800, qname_response); // For some reason, if RD is set and we don't have RA it Linux `host` // doesn't work! DNSPacket res_packet = new DNSPacket(dnspacket.ID, false, dnspacket.OPCODE, true, dnspacket.RD, dnspacket.RD, dnspacket.Questions, new Response[] {response}, null, null); rdnspacket = res_packet.ICPacket; } catch(Exception e) { ProtocolLog.WriteIf(IpopLog.DNS, e.Message); rdnspacket = DNSPacket.BuildFailedReplyPacket(dnspacket); } UDPPacket res_udpp = new UDPPacket(req_udpp.DestinationPort, req_udpp.SourcePort, rdnspacket); IPPacket res_ipp = new IPPacket(IPPacket.Protocols.UDP, req_ipp.DestinationIP, req_ipp.SourceIP, res_udpp.ICPacket); return res_ipp; }
/** <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="CACHE_FLUSH">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) { }
/** <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="CACHE_FLUSH">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, bool CACHE_FLUSH, int TTL, String RDATA) { this.NAME = NAME; this.CLASS = CLASS; this.TTL = TTL; this.TYPE = TYPE; this.CLASS = CLASS; this.CACHE_FLUSH = CACHE_FLUSH; this.RDATA = RDATA; if(TYPE == DNSPacket.TYPES.A) { NAME_BLOB = DNSPacket.HostnameStringToMemBlock(NAME); RDATA_BLOB = DNSPacket.IPStringToMemBlock(RDATA); } else if(TYPE == DNSPacket.TYPES.PTR) { if(DNSPacket.StringIsIP(NAME)) { NAME_BLOB = DNSPacket.PtrStringToMemBlock(NAME); } else { NAME_BLOB = DNSPacket.HostnameStringToMemBlock(NAME); } RDATA_BLOB = DNSPacket.HostnameStringToMemBlock(RDATA); } else { throw new Exception("Invalid Query TYPE: " + TYPE + "!"); } RDLENGTH = (short) RDATA_BLOB.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 cache_flush = 0x80; if(!CACHE_FLUSH) { cache_flush = 0x00; } data[idx++] = (byte) (((((int) CLASS) >> 8) & 0x7F) | cache_flush); 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(NAME_BLOB, MemBlock.Reference(data), RDATA_BLOB); }
public void Test() { 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); String ss_ip = "10.254.112.232"; bool change = ManagedAddressResolverAndDNS.mDnsTranslate(mdns.Answers, ss_ip); change |= ManagedAddressResolverAndDNS.mDnsTranslate(mdns.Authority, ss_ip); change |= ManagedAddressResolverAndDNS.mDnsTranslate(mdns.Additional, ss_ip); // If we make a change let's make a new packet! if(change) { mdns = new DNSPacket(mdns.ID, mdns.QUERY, mdns.OPCODE, mdns.AA, mdns.RA, mdns.RD, mdns.Questions, mdns.Answers, mdns.Authority, mdns.Additional); } Assert.AreEqual(mdns.Authority[0].NAME, "davidiw-laptop.local", "NAME"); Assert.AreEqual(mdns.Authority[0].TYPE, DNSPacket.TYPES.A, "TYPE"); Assert.AreEqual(mdns.Authority[0].CLASS, DNSPacket.CLASSES.IN, "CLASS"); Assert.AreEqual(mdns.Authority[0].CACHE_FLUSH, false, "CACHE_FLUSH"); Assert.AreEqual(mdns.Authority[0].TTL, 120, "TTL"); Assert.AreEqual(mdns.Authority[0].RDATA, "10.254.112.232", "RDATA"); }
/** <summary>Implements the ITranslator portion for ManagedAddress..., takes an IP Packet, based upon who the originating Brunet Sender was, changes who the packet was sent from and then switches the destination address to the local nodes address</summary> <param name="packet">The IP Packet to translate.</param> <param name="from">The Brunet address the packet was sent from.</param> <returns>The translated IP Packet.</returns> */ public MemBlock Translate(MemBlock packet, Address from) { MemBlock source_ip = (MemBlock) _addr_ip[from]; if(source_ip == null) { throw new Exception("Invalid mapping " + from + "."); } // Attempt to translate a MDNS packet IPPacket ipp = new IPPacket(packet); MemBlock hdr = packet.Slice(0,12); bool fragment = ((packet[6] & 0x1F) | packet[7]) != 0; if(ipp.Protocol == IPPacket.Protocols.UDP && !fragment) { UDPPacket udpp = new UDPPacket(ipp.Payload); // MDNS runs on 5353 if(udpp.DestinationPort == 5353) { DNSPacket dnsp = new DNSPacket(udpp.Payload); String ss_ip = DNSPacket.IPMemBlockToString(source_ip); bool change = mDnsTranslate(dnsp.Answers, ss_ip); change |= mDnsTranslate(dnsp.Authority, ss_ip); change |= mDnsTranslate(dnsp.Additional, ss_ip); // If we make a change let's make a new packet! if(change) { dnsp = new DNSPacket(dnsp.ID, dnsp.QUERY, dnsp.OPCODE, dnsp.AA, dnsp.RA, dnsp.RD, dnsp.Questions, dnsp.Answers, dnsp.Authority, dnsp.Additional); udpp = new UDPPacket(udpp.SourcePort, udpp.DestinationPort, dnsp.ICPacket); ipp = new IPPacket(ipp.Protocol, source_ip, ipp.DestinationIP, hdr, udpp.ICPacket); return ipp.Packet; } } else if(udpp.DestinationPort >= 5060 && udpp.DestinationPort < 5100) { udpp = SIPTranslate(udpp, source_ip, ipp.SSourceIP, ipp.SDestinationIP); ipp = new IPPacket(ipp.Protocol, source_ip, _local_ip, hdr, udpp.ICPacket); return ipp.Packet; } } return IPPacket.Translate(packet, source_ip, _local_ip); }
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"); }
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].CACHE_FLUSH, false, "CACHE_FLUSH"); 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.CACHE_FLUSH, 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].CACHE_FLUSH, false, "CACHE_FLUSH"); Assert.AreEqual(dnsp.Authority[0].TTL, 120, "TTL"); Assert.AreEqual(dnsp.Authority[0].RDATA, "10.254.111.252", "RDATA"); }
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].CACHE_FLUSH, true, "CACHE_FLUSH"); Assert.AreEqual(dnsp.Additional[0].TTL, 120, "TTL"); Assert.AreEqual(dnsp.Additional[0].RDATA, "10.227.56.136", "RDATA"); }
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].QNAME_BLOB, 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"); }
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].NAME_BLOB, 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.CACHE_FLUSH, 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"); }
/** <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); }