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); }
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); }
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(); }