MCPcopy Create free account
hub / github.com/DNSCrypt/encrypted-dns-server / set_ttl

Function set_ttl

src/dns.rs:385–405  ·  view source on GitHub ↗
(packet: &mut [u8], ttl: u32)

Source from the content-addressed store, hash-verified

383}
384
385pub fn set_ttl(packet: &mut [u8], ttl: u32) -> Result<(), Error> {
386 let packet_len = packet.len();
387 ensure!(packet_len > DNS_OFFSET_QUESTION, "Short packet");
388 ensure!(packet_len <= DNS_MAX_PACKET_SIZE, "Large packet");
389 ensure!(qdcount(packet) == 1, "No question");
390 let mut offset = skip_name(packet, DNS_OFFSET_QUESTION)?;
391 assert!(offset > DNS_OFFSET_QUESTION);
392 ensure!(packet_len - offset > 4, "Short packet");
393 offset += 4;
394 let (ancount, nscount, arcount) = (ancount(packet), nscount(packet), arcount(packet));
395 let rrcount = ancount as usize + nscount as usize + arcount as usize;
396 offset = traverse_rrs_mut(packet, offset, rrcount, |packet, offset| {
397 let qtype = BigEndian::read_u16(&packet[offset..]);
398 if qtype != DNS_TYPE_OPT {
399 BigEndian::write_u32(&mut packet[offset + 4..], ttl)
400 }
401 Ok(())
402 })?;
403 ensure!(packet_len == offset, "Garbage after packet");
404 Ok(())
405}
406
407fn add_edns_section(packet: &mut Vec<u8>, max_payload_size: u16) -> Result<(), Error> {
408 let opt_rr: [u8; 11] = [

Callers 1

Calls 5

skip_nameFunction · 0.85
ancountFunction · 0.85
nscountFunction · 0.85
arcountFunction · 0.85
traverse_rrs_mutFunction · 0.85

Tested by

no test coverage detected