/// <summary> /// Take care of a packet of Multicast DNS stuff /// </summary> /// <param name="payload"></param> internal static void HandlePacket(byte[] payload) { ushort ipHeaderLength = (ushort)((payload[14] & 0x0f) * 4); var name = DNS.DecodeDnsName(payload, 34 + ipHeaderLength); // Name from first Query if (Adapter.VerboseDebugging) { Debug.WriteLine("Local Name Request (MDNS) for " + name); } bool isQuery = (payload[24 + ipHeaderLength] & (1 << 7)) == 0; // DNS Query ? if (!isQuery) { return; } // Validate that this is MDNS address 224.0.0.251 if (payload[10 + ipHeaderLength] != 0xe0 || payload[11 + ipHeaderLength] != 0x00 || payload[12 + ipHeaderLength] != 0x00 || payload[13 + ipHeaderLength] != 0xfb) { return; } if (name != Networking.Adapter.Name + ".local") { return; // if the name requested does not match ours, exit! } // Wow, if we made it past all that, we should send a reply... SendMDNSNameReply(); }
/// <summary> /// Take care of a packet of Linked-Local Multicast Name Resolution (LLMNR) stuff /// </summary> /// <param name="payload"></param> internal static void HandlePacket(byte[] payload) { ushort ipHeaderLength = (ushort)((payload[14] & 0x0f) * 4); var name = DNS.DecodeDnsName(payload, 34 + ipHeaderLength); // Name from first Query bool isQuery = (payload[24 + ipHeaderLength] & (1 << 7)) == 0; // DNS Query ? if (!isQuery) { return; } // This is not a good or valid way to detect the type because there could be multiple answers, but I have bigger fish to fry... bool isTypeA = payload[payload.Length - 3] == 0x01; if (!isTypeA) { return; } // Validate that this is an LLMNR address 224.0.0.252 if (payload[10 + ipHeaderLength] != 0xe0 || payload[11 + ipHeaderLength] != 0x00 || payload[12 + ipHeaderLength] != 0x00 || payload[13 + ipHeaderLength] != 0xfc) { return; } //Debug.WriteLine("Local Name Request (LLMNR, Type A) for " + name); if (name != Networking.Adapter.Name + ".local" && name != Networking.Adapter.Name) { return; // if the name requested does not match ours, exit! } if (Adapter.VerboseDebugging) { Debug.WriteLine("Local Name Request (LLMNR, Type A) for " + name); } SendLLMNRNameReply(name, Utility.ExtractRangeFromArray(payload, 42, 2), Utility.ExtractRangeFromArray(payload, 6, 6), Utility.ExtractRangeFromArray(payload, 26, 4), Utility.ExtractRangeFromArray(payload, 34, 2)); }