wire_building_tests.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. use dns::{Request, Flags, Query, Labels, QClass};
  2. use dns::record::RecordType;
  3. use pretty_assertions::assert_eq;
  4. #[test]
  5. fn build_request() {
  6. let request = Request {
  7. transaction_id: 0xceac,
  8. flags: Flags::query(),
  9. query: Query {
  10. qname: Labels::encode("rfcs.io").unwrap(),
  11. qclass: QClass::Other(0x42),
  12. qtype: RecordType::from(0x1234),
  13. },
  14. additional: Some(Request::additional_record()),
  15. };
  16. let result = vec![
  17. 0xce, 0xac, // transaction ID
  18. 0x01, 0x00, // flags (standard query)
  19. 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // counts (1, 0, 0, 1)
  20. // query:
  21. 0x04, 0x72, 0x66, 0x63, 0x73, 0x02, 0x69, 0x6f, 0x00, // qname
  22. 0x12, 0x34, // type
  23. 0x00, 0x42, // class
  24. // OPT record:
  25. 0x00, // name
  26. 0x00, 0x29, // type OPT
  27. 0x02, 0x00, // UDP payload size
  28. 0x00, // higher bits
  29. 0x00, // EDNS(0) version
  30. 0x00, 0x00, // more flags
  31. 0x00, 0x00, // no data
  32. ];
  33. assert_eq!(request.to_bytes().unwrap(), result);
  34. }