wire_building_tests.rs 1.1 KB

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