+
+#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
+/// An IPv4 Address resource record
+pub struct A {
+ /// The name this record is at.
+ pub name: Name,
+ /// The bytes of the IPv4 address.
+ pub address: [u8; 4],
+}
+/// The wire type for A records
+pub const A_TYPE: u16 = 1;
+impl StaticRecord for A {
+ const TYPE: u16 = A_TYPE;
+ fn name(&self) -> &Name { &self.name }
+ fn json(&self) -> String {
+ format!("{{\"type\":\"a\",\"name\":\"{}\",\"address\":{:?}}}", self.name.0, self.address)
+ }
+ fn read_from_data(name: Name, data: &[u8], _wire_packet: &[u8]) -> Result<Self, ()> {
+ if data.len() != 4 { return Err(()); }
+ let mut address = [0; 4];
+ address.copy_from_slice(&data);
+ Ok(A { name, address })
+ }
+ fn write_u16_len_prefixed_data(&self, out: &mut Vec<u8>) {
+ out.extend_from_slice(&4u16.to_be_bytes());
+ out.extend_from_slice(&self.address);
+ }
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
+/// An IPv6 Address resource record
+pub struct AAAA {
+ /// The name this record is at.
+ pub name: Name,
+ /// The bytes of the IPv6 address.
+ pub address: [u8; 16],
+}
+/// The wire type for AAAA records
+pub const AAAA_TYPE: u16 = 28;
+impl StaticRecord for AAAA {
+ const TYPE: u16 = AAAA_TYPE;
+ fn name(&self) -> &Name { &self.name }
+ fn json(&self) -> String {
+ format!("{{\"type\":\"aaaa\",\"name\":\"{}\",\"address\":{:?}}}", self.name.0, self.address)
+ }
+ fn read_from_data(name: Name, data: &[u8], _wire_packet: &[u8]) -> Result<Self, ()> {
+ if data.len() != 16 { return Err(()); }
+ let mut address = [0; 16];
+ address.copy_from_slice(&data);
+ Ok(AAAA { name, address })
+ }
+ fn write_u16_len_prefixed_data(&self, out: &mut Vec<u8>) {
+ out.extend_from_slice(&16u16.to_be_bytes());
+ out.extend_from_slice(&self.address);
+ }
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
+/// A Name Server resource record, which indicates the server responsible for handling queries for
+/// a zone.
+pub struct NS {
+ /// The name this record is at.
+ ///
+ /// This is also the zone which the server at [`Self::name_server`] is responsible for handling
+ /// queries for.
+ pub name: Name,
+ /// The name of the server which is responsible for handling queries for the [`self.name`]
+ /// zone.
+ pub name_server: Name,
+}
+impl StaticRecord for NS {
+ const TYPE: u16 = 2;
+ fn name(&self) -> &Name { &self.name }
+ fn json(&self) -> String {
+ format!("{{\"type\":\"ns\",\"name\":\"{}\",\"ns\":\"{}\"}}", self.name.0, self.name_server.0)
+ }
+ fn read_from_data(name: Name, mut data: &[u8], wire_packet: &[u8]) -> Result<Self, ()> {
+ Ok(NS { name, name_server: read_wire_packet_name(&mut data, wire_packet)? })
+ }
+ fn write_u16_len_prefixed_data(&self, out: &mut Vec<u8>) {
+ out.extend_from_slice(&name_len(&self.name_server).to_be_bytes());
+ write_name(out, &self.name_server);
+ }
+}