(qname: &str, qtype: QueryType, qclass: QueryClass)
| 68 | } |
| 69 | |
| 70 | fn query(qname: &str, qtype: QueryType, qclass: QueryClass) -> Self { |
| 71 | let mut datagram = Vec::new(); |
| 72 | |
| 73 | let id = crate::ephemeral_port_number(); // A random semi-unique number |
| 74 | for b in id.to_be_bytes().iter() { |
| 75 | datagram.push(*b); // Transaction ID |
| 76 | } |
| 77 | for b in FLAG_RD.to_be_bytes().iter() { |
| 78 | datagram.push(*b); // Flags |
| 79 | } |
| 80 | for b in (1 as u16).to_be_bytes().iter() { |
| 81 | datagram.push(*b); // Questions |
| 82 | } |
| 83 | for _ in 0..6 { |
| 84 | datagram.push(0); // Answer + Authority + Additional |
| 85 | } |
| 86 | for label in qname.split('.') { |
| 87 | datagram.push(label.len() as u8); // QNAME label length |
| 88 | for b in label.bytes() { |
| 89 | datagram.push(b); // QNAME label bytes |
| 90 | } |
| 91 | } |
| 92 | datagram.push(0); // Root null label |
| 93 | for b in (qtype as u16).to_be_bytes().iter() { |
| 94 | datagram.push(*b); // QTYPE |
| 95 | } |
| 96 | for b in (qclass as u16).to_be_bytes().iter() { |
| 97 | datagram.push(*b); // QCLASS |
| 98 | } |
| 99 | |
| 100 | Self { datagram } |
| 101 | } |
| 102 | |
| 103 | fn id(&self) -> u16 { |
| 104 | u16::from_be_bytes(self.datagram[0..2].try_into().unwrap()) |
nothing calls this directly
no test coverage detected