protected DnsPacket (byte [] buffer, int length) { if (buffer == null) throw new ArgumentNullException("buffer"); if (length <= 0) throw new ArgumentOutOfRangeException("length", "Must be greater than zero."); packet = buffer; position = length; header = new DnsHeader(new ArraySegment<byte>(packet, 0, 12)); }
public DnsQuery (string name, DnsQType qtype, DnsQClass qclass) { if (String.IsNullOrEmpty (name)) throw new ArgumentNullException ("name"); int length = DnsUtil.GetEncodedLength (name); if (length == -1) throw new ArgumentException ("Invalid DNS name", "name"); length += 12 + 2 + 2; // Header + qtype + qclass packet = new byte [length]; header = new DnsHeader (packet, 0); position = 12; WriteDnsName (name); WriteUInt16 ((ushort) qtype); WriteUInt16 ((ushort) qclass); Header.QuestionCount = 1; Header.IsQuery = true; Header.RecursionDesired = true; }