private static void AnnounceService(Socket sock, String service) { IPEndPoint remoteEp = new IPEndPoint(IPAddress.Parse(mdnsIP), mdnsPort); mDNSPacket dnsPkt = new mDNSPacket(); mDNSHeader mdnsHdr = new mDNSHeader(); mDNSAnswerRR mdnsAnRR = new mDNSAnswerRR(service, Type.AAAA, (Class.IN | Class.CF), 4500, 16); Byte[] rdata = new Byte[16]; mdnsAnRR.RDATA = rdata; mdnsHdr.AA = true; mdnsHdr.TC = false; mdnsHdr.RD = false; mdnsHdr.RA = false; mdnsHdr.RCODE = RespCode.NoError; mdnsHdr.OPCODE = OpCode.QUERY; mdnsHdr.QR = true; mdnsHdr.qdcount = 0; mdnsHdr.an_rrs = 1; mdnsHdr.ns_rrs = 0; mdnsHdr.ar_rrs = 0; dnsPkt.Header = mdnsHdr; dnsPkt.AnswerRR = mdnsAnRR; dnsPkt.print(); Console.WriteLine("Announcing Service: " + service); sock.SendTo(dnsPkt.data, remoteEp); }
private static void SendQuery(Socket sock, String service) { IPEndPoint remoteEp = new IPEndPoint(IPAddress.Parse(mdnsIP), mdnsPort); mDNSPacket dnsPkt = new mDNSPacket(); mDNSHeader mdnsHdr = new mDNSHeader(); mDNSQuestion mdnsQ = new mDNSQuestion(service, QType.ANY, QClass.IN); mdnsHdr.AA = false; mdnsHdr.TC = false; mdnsHdr.RD = false; mdnsHdr.RA = false; mdnsHdr.RCODE = RespCode.NoError; mdnsHdr.OPCODE = OpCode.QUERY; mdnsHdr.QR = false; mdnsHdr.qdcount = 1; mdnsHdr.an_rrs = 0; mdnsHdr.ns_rrs = 0; mdnsHdr.ar_rrs = 0; dnsPkt.Header = mdnsHdr; dnsPkt.Question = mdnsQ; dnsPkt.print(); Console.WriteLine("Sending Query: " + service); sock.SendTo(dnsPkt.data, remoteEp); }
static void PrintTestPacket() { mDNSPacket dnsPkt = new mDNSPacket(); mDNSHeader mdnsHdr = new mDNSHeader(); mDNSAnswerRR mdnsAnRR = new mDNSAnswerRR("_services._dns-sd._udp.local.", Type.TXT, Class.IN, 4500, 16); mDNSAdditionalRR mdnsArRR = new mDNSAdditionalRR("_services._dns-sd._udp.local.", Type.TXT, Class.IN, 4500, 16); Byte[] rdata = new Byte[16]; mdnsAnRR.RDATA = rdata; mdnsArRR.RDATA = rdata; mdnsHdr.AA = true; mdnsHdr.TC = false; mdnsHdr.RD = false; mdnsHdr.RA = false; mdnsHdr.RCODE = RespCode.NoError; mdnsHdr.QR = true; mdnsHdr.qdcount = 0; mdnsHdr.an_rrs = 3; mdnsHdr.ns_rrs = 0; mdnsHdr.ar_rrs = 4; dnsPkt.Header = mdnsHdr; dnsPkt.AnswerRR = mdnsAnRR; dnsPkt.AnswerRR = mdnsAnRR; dnsPkt.AnswerRR = mdnsAnRR; dnsPkt.AdditionalRR = mdnsArRR; dnsPkt.AdditionalRR = mdnsArRR; dnsPkt.AdditionalRR = mdnsArRR; dnsPkt.AdditionalRR = mdnsArRR; dnsPkt.print(); }
public mDNSPacket() { rawData = new Byte[1]; mdnsHdr = new mDNSHeader(); mdnsQs = new List <mDNSQuestion>(); mdnsAnRRs = new List <mDNSAnswerRR>(); mdnsNsRRs = new List <mDNSAuthorityRR>(); mdnsArRRs = new List <mDNSAdditionalRR>(); }
public mDNSPacket(Byte[] data) { int offset = mDNSHeader.ByteLen; int i; rawData = data; mdnsHdr = new mDNSHeader(data); mdnsQs = new List <mDNSQuestion>(); mdnsAnRRs = new List <mDNSAnswerRR>(); mdnsNsRRs = new List <mDNSAuthorityRR>(); mdnsArRRs = new List <mDNSAdditionalRR>(); Console.WriteLine("== Header =="); mdnsHdr.print(); Console.WriteLine("== Questions =="); for (i = 0; i < mdnsHdr.qdcount; i++) { mdnsQs.Add(new mDNSQuestion(data, offset)); offset += mdnsQs[i].ByteLen; mdnsQs[i].print(); } Console.WriteLine("== AnswerRRs =="); for (i = 0; i < mdnsHdr.an_rrs; i++) { mdnsAnRRs.Add(new mDNSAnswerRR(data, offset)); offset += mdnsAnRRs[i].ByteLen; mdnsAnRRs[i].print(); } Console.WriteLine("== AuthorityRRs =="); for (i = 0; i < mdnsHdr.ns_rrs; i++) { mdnsNsRRs.Add(new mDNSAuthorityRR(data, offset)); offset += mdnsNsRRs[i].ByteLen; mdnsNsRRs[i].print(); } Console.WriteLine("== AdditionalRRs =="); for (i = 0; i < mdnsHdr.ar_rrs; i++) { mdnsArRRs.Add(new mDNSAdditionalRR(data, offset)); offset += mdnsArRRs[i].ByteLen; mdnsArRRs[i].print(); } Console.WriteLine("===================\n"); }