public DNSInputStream DNSInput(byte[] bytes) { var compress = new CompressionInputContext(bytes); var memory = new MemoryStream(bytes); return(new DNSInputStream(memory, compress)); }
public void TestUncompressionFirstUse() { var compress = new CompressionInputContext(new byte[] { 7, // Length of 'example' 101, 120, 97, 109, 112, 108, 101, 3, // Length of com 99, 111, 109, 0 // Length of root }); Tuple <Domain, int> domain_info = compress.ReadDomainAt(0); var expected_domain = new Domain("example.com"); var expected_offset = 13; Assert.That(domain_info.Item1, Is.EqualTo(expected_domain)); Assert.That(domain_info.Item2, Is.EqualTo(expected_offset)); }
public void TestUncompressionPointer() { var compress = new CompressionInputContext(new byte[] { 7, // Length of 'example' 101, 120, 97, 109, 112, 108, 101, 3, // Length of com 99, 111, 109, 0, // Length of root 3, // Length of dns 100, 110, 115, // Pointer to start of context 192, 0 }); Tuple <Domain, int> domain_info = compress.ReadDomainAt(13); var expected_domain = new Domain("dns.example.com"); var expected_offset = 19; Assert.That(domain_info.Item1, Is.EqualTo(expected_domain)); Assert.That(domain_info.Item2, Is.EqualTo(expected_offset)); }
/** * A convenience wrapper around Unserialize. */ public static DNSPacket FromBytes(byte[] bytes) { var buffer_stream = new MemoryStream(bytes); var compress = new CompressionInputContext(bytes); var dns_in = new DNSInputStream(buffer_stream, compress); return(Unserialize(dns_in)); }
public DNSInputStream(Stream stream, CompressionInputContext compress) { this.stream = stream; this.compress = compress; }