public static void TestByteParsing() { int packetCount = rawPackets.Length / rawPackets.Rank; for (int i = 0; i < packetCount; i++) { Console.WriteLine("-- Packet {0} ---", i); Dump(rawPackets[i]); int offset = 0; Dns.Format format = Dns.Format.Parse(rawPackets[i], ref offset); Debug.Assert(offset == rawPackets[i].Length || format.GetRCode() != Dns.RCode.NoError); Debug.Assert(format == format); // format.Size may not equal offset here, because // packet may have RFC1035 compression enabled. // Debug.Assert(offset == format.Size) offset = 0; byte [] rendered = new byte [format.Size]; format.Write(rendered, ref offset); offset = 0; Dns.Format restored = Dns.Format.Parse(rendered, ref offset); Debug.Assert(format.GetHashCode() == restored.GetHashCode()); } }
private StatusCode Ask(IPv4 dnsServer, Dns.Query [] !queries, out Dns.Format answer) { answer = null; Dns.Format outFrame = new Dns.Format(); outFrame.SetFlags(flags); outFrame.Queries.AddRange(queries); byte[] outData = new byte [outFrame.Size]; if (outData.Length > Dns.Format.MaxUdpMessageLength) { return(StatusCode.OverSizeMessage); } int offset = 0; outFrame.Write(outData, ref offset); byte[] rcvData; StatusCode askResponse = AskDnsServer(dnsServer, outData, out rcvData); if (askResponse != StatusCode.Success) { return(askResponse); } assert rcvData != null; try { offset = 0; Dump(rcvData, offset); answer = Dns.Format.Parse(rcvData, ref offset); } catch (Exception e) { DebugPrint("Parser threw {0}", e); return(StatusCode.TransportError); } return(StatusCode.Success); }
public StatusCode Ask(IPv4 dnsServer, Dns.Query query, out Dns.Format answer) { return(Ask(dnsServer, new Dns.Query [] { query }, out answer)); }