protected override void ProcessRequest(byte[] data, UDPListener udpListener, IPEndPoint ipEndPoint, string replyIP, string replyIPv6) { string clientIP = ipEndPoint.Address.ToString(); MDNSPacket packet = new MDNSPacket(data); if (packet.Header.IsQuery()) { if (Check(packet.Question.Name, packet.Question.QuestionType, packet.Question.Type, clientIP, out string message)) { if (packet.Question.QuestionType.Equals("QM") && !this.UnicastOnly && string.Equals(ipEndPoint.Address.AddressFamily.ToString(), "InterNetwork")) { ipEndPoint.Address = IPAddress.Parse("224.0.0.251"); } else if (packet.Question.QuestionType.Equals("QM") && !this.UnicastOnly && string.Equals(ipEndPoint.Address.AddressFamily.ToString(), "InterNetworkV6")) { ipEndPoint.Address = IPAddress.Parse("ff02::fb"); } byte[] buffer = packet.GetBytes(this.TTL, replyIP, replyIPv6); SendTo(buffer, udpListener, ipEndPoint); } Output("mDNS", clientIP, packet.Question.Name, packet.Question.QuestionType, packet.Question.Type, message); } }
internal static void ProcessMDNSRequest(byte[] data, string clientIP, int clientPort, string sourceIP, int sourcePort) { MDNSPacket packet = new MDNSPacket(data); MDNSListener listener = new MDNSListener(); string destinationIP = clientIP; if (packet.Header.IsQuery()) { if (listener.Check(packet.Question.Name, packet.Question.QuestionType, packet.Question.Type, clientIP, out string message)) { if (packet.Question.QuestionType.Equals("QM") && !Program.enabledMDNSUnicast && string.Equals(IPAddress.Parse(clientIP).AddressFamily.ToString(), "InterNetwork")) { destinationIP = "224.0.0.251"; } else if (packet.Question.QuestionType.Equals("QM") && !Program.enabledMDNSUnicast && string.Equals(IPAddress.Parse(clientIP).AddressFamily.ToString(), "InterNetworkV6")) { destinationIP = "ff02::fb"; } byte[] buffer = packet.GetBytes(uint.Parse(Program.argMDNSTTL), Program.argSpooferIP, Program.argSpooferIPv6); if (!Utilities.ArrayIsNullOrEmpty(buffer)) { UDPSocket.SendTo(destinationIP, clientPort, sourceIP, sourcePort, buffer, false); } } string type = string.Concat(packet.Question.QuestionType, ")(", packet.Question.Type); Output.SpooferOutput("mDNS", type, packet.Question.Name, clientIP, message); } }