|
| 1 | +use byteorder::{BigEndian, ByteOrder}; |
| 2 | +use {Error, Name}; |
| 3 | + |
| 4 | +#[derive(Debug, Clone, Copy)] |
| 5 | +pub struct Record<'a> { |
| 6 | + pub target: Name<'a>, |
| 7 | +} |
| 8 | + |
| 9 | +impl<'a> super::Record<'a> for Record<'a> { |
| 10 | + const TYPE: isize = 65; |
| 11 | + |
| 12 | + fn parse(rdata: &'a [u8], original: &'a [u8]) -> super::RDataResult<'a> { |
| 13 | + if rdata.len() < 1 { |
| 14 | + return Err(Error::WrongRdataLength); |
| 15 | + } |
| 16 | + let record = Record { |
| 17 | + target: Name::scan(&rdata[0..], original)?, |
| 18 | + }; |
| 19 | + Ok(super::RData::HTTPS(record)) |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +#[cfg(test)] |
| 24 | +mod test { |
| 25 | + |
| 26 | + use Opcode::*; |
| 27 | + use QueryClass as QC; |
| 28 | + use QueryType as QT; |
| 29 | + use ResponseCode::NoError; |
| 30 | + use {Header, Packet}; |
| 31 | + |
| 32 | + #[test] |
| 33 | + fn parse_response() { |
| 34 | + // from wireshark |
| 35 | + let response: [u8; 215] = [ |
| 36 | + 0x21, 0x8b, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x06, 0x6d, |
| 37 | + 0x6f, 0x62, 0x69, 0x6c, 0x65, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x04, 0x64, |
| 38 | + 0x61, 0x74, 0x61, 0x09, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x03, |
| 39 | + 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x41, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x05, 0x00, 0x01, |
| 40 | + 0x00, 0x00, 0x00, 0x6d, 0x00, 0x27, 0x06, 0x6d, 0x6f, 0x62, 0x69, 0x6c, 0x65, 0x06, |
| 41 | + 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x04, 0x64, 0x61, 0x74, 0x61, 0x0e, 0x74, 0x72, |
| 42 | + 0x61, 0x66, 0x66, 0x69, 0x63, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x03, 0x6e, |
| 43 | + 0x65, 0x74, 0x00, 0xc0, 0x3e, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, |
| 44 | + 0x29, 0x10, 0x6f, 0x6e, 0x65, 0x64, 0x73, 0x63, 0x6f, 0x6c, 0x70, 0x72, 0x64, 0x65, |
| 45 | + 0x75, 0x73, 0x30, 0x37, 0x06, 0x65, 0x61, 0x73, 0x74, 0x75, 0x73, 0x08, 0x63, 0x6c, |
| 46 | + 0x6f, 0x75, 0x64, 0x61, 0x70, 0x70, 0x05, 0x61, 0x7a, 0x75, 0x72, 0x65, 0xc0, 0x29, |
| 47 | + 0xc0, 0x82, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x31, 0x07, 0x6e, |
| 48 | + 0x73, 0x31, 0x2d, 0x32, 0x30, 0x31, 0x09, 0x61, 0x7a, 0x75, 0x72, 0x65, 0x2d, 0x64, |
| 49 | + 0x6e, 0x73, 0xc0, 0x29, 0x06, 0x6d, 0x73, 0x6e, 0x68, 0x73, 0x74, 0xc0, 0x1f, 0x00, |
| 50 | + 0x00, 0x27, 0x11, 0x00, 0x00, 0x03, 0x84, 0x00, 0x00, 0x01, 0x2c, 0x00, 0x09, 0x3a, |
| 51 | + 0x80, 0x00, 0x00, 0x00, 0x3c, |
| 52 | + ]; |
| 53 | + |
| 54 | + let packet = Packet::parse(&response).unwrap(); |
| 55 | + assert_eq!( |
| 56 | + packet.header, |
| 57 | + Header { |
| 58 | + id: 0x218b, |
| 59 | + query: false, |
| 60 | + opcode: StandardQuery, |
| 61 | + authoritative: false, |
| 62 | + truncated: false, |
| 63 | + recursion_desired: true, |
| 64 | + recursion_available: true, |
| 65 | + authenticated_data: false, |
| 66 | + checking_disabled: false, |
| 67 | + response_code: NoError, |
| 68 | + questions: 1, |
| 69 | + answers: 2, |
| 70 | + nameservers: 1, |
| 71 | + additional: 0, |
| 72 | + } |
| 73 | + ); |
| 74 | + assert_eq!(packet.questions.len(), 1); |
| 75 | + assert_eq!(packet.questions[0].qtype, QT::HTTPS); |
| 76 | + assert_eq!(packet.questions[0].qclass, QC::IN); |
| 77 | + assert_eq!( |
| 78 | + &packet.questions[0].qname.to_string()[..], |
| 79 | + "mobile.events.data.microsoft.com" |
| 80 | + ); |
| 81 | + } |
| 82 | +} |
0 commit comments