private void SendAddressResponse(Packet p, IPEndPoint ep) { var packet = new Packet(); packet.TransactionID = p.TransactionID; packet.Flags.IsResponse = true; packet.Flags.IsAuthoritative = true; var ip4Address = GetIP4Address(); var ip6Address = GetIP6Address(); var a = AAnswer.Build(fullName, ip4Address, (UInt16)120, true, 1); var aaaa = AAAAAnswer.Build(fullName, ip6Address, (UInt16)120, true, 1); if (a != null) { packet.Answers.Add(a); } if (aaaa != null) { packet.Answers.Add(aaaa); } if (ep != null) { _service.SendPacket(p, ep); } else { _service.SendPacket(packet); } }
Packet BuildAnswerPacket(string name, string ip4, string ip6 = null) { var resp = new Packet(); resp.Flags.IsResponse = true; resp.Flags.IsAuthoritative = true; if (!string.IsNullOrEmpty(ip4)) { var answer = new Answer(); answer.Record = new Record(); answer.Record.Name = name; answer.Record.RecordType = AAnswer.RecordType; var answerData = new AAnswer(); answerData.Address = IPAddress.Parse("10.99.99.99"); answer.Data = answerData; resp.Answers.Add(answer); } if (!string.IsNullOrEmpty(ip6)) { var answer = new Answer(); answer.Record = new Record(); answer.Record.Name = name; answer.Record.RecordType = AAAAAnswer.RecordType; var answerData = new AAAAAnswer(); answerData.Address = IPAddress.Parse(ip6); answer.Data = answerData; resp.Answers.Add(answer); } return(resp); }
private Packet BuildResponse(string name, UInt16 id, ServiceInfo info, IPAddress ip4Address, IPAddress ip6Address) { var ret = new Packet(); ret.TransactionID = id; ret.Flags.IsResponse = true; ret.Flags.IsAuthoritative = true; var dnsName = name; var domainName = string.Join(".", info.Name, dnsName); var machineName = fullName; var ptr = PTRAnswer.Build(dnsName, domainName, 4500, false, 1); var txt = TXTAnswer.Build(domainName, 4500, info.Flags, info.Data, true, 1); var srv = SRVAnswer.Build(domainName, 120, info.Priority, info.Weight, info.Port, machineName, true, 1); var a = AAnswer.Build(machineName, ip4Address, (UInt16)120, true, 1); var aaaa = AAAAAnswer.Build(machineName, ip6Address, (UInt16)120, true, 1); ret.Answers.Add(ptr); ret.Answers.Add(txt); ret.Answers.Add(srv); if (aaaa != null) { ret.Answers.Add(aaaa); } if (a != null) { ret.Answers.Add(a); } return(ret); }