wireshark.cc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <dhcp4/tests/dhcp4_test_utils.h>
  16. #include <string>
  17. #include <asiolink/io_address.h>
  18. #include <util/encode/hex.h>
  19. /// @file wireshark.cc
  20. ///
  21. /// @brief contains packet captures imported from Wireshark
  22. ///
  23. /// These are actual packets captured over wire. They are used in various
  24. /// tests.
  25. ///
  26. /// The procedure to export Wireshark -> unit-tests is manual, but rather
  27. /// easy to follow:
  28. /// 1. Open a file in wireshark
  29. /// 2. Find the packet you want to export
  30. /// 3. There's a protocol stack (Frame, Ethernet, IPv6, UDP, DHCPv6, ...)
  31. /// 4. Right click on DHCPv6 -> Copy -> Bytes -> Hex Stream
  32. /// 5. Paste it as: string hex_string="[paste here]";
  33. /// 6. Coding guidelines line restrictions apply, so wrap your code as necessary
  34. /// 7. Make sure you decribe the capture appropriately
  35. /// 8. Follow whatever rest of the methods are doing (set ports, ifaces etc.)
  36. /// 9. To easily copy packet description, click File... -> Extract packet
  37. /// dissections -> as plain text file...
  38. /// (Make sure that the packet is expanded in the view. The text file will
  39. /// contain whatever expansion level you have in the graphical tree.)
  40. using namespace std;
  41. using namespace isc::asiolink;
  42. namespace isc {
  43. namespace dhcp {
  44. namespace test {
  45. Pkt4Ptr Dhcpv4SrvTest::packetFromCapture(const std::string& hex_string) {
  46. std::vector<uint8_t> bin;
  47. // Decode the hex string and store it in bin (which happens
  48. // to be OptionBuffer format)
  49. isc::util::encode::decodeHex(hex_string, bin);
  50. Pkt4Ptr pkt(new Pkt4(&bin[0], bin.size()));
  51. captureSetDefaultFields(pkt);
  52. return (pkt);
  53. }
  54. void Dhcpv4SrvTest::captureSetDefaultFields(const Pkt4Ptr& pkt) {
  55. pkt->setRemotePort(546);
  56. pkt->setRemoteAddr(IOAddress("fe80::1"));
  57. pkt->setLocalPort(0);
  58. pkt->setLocalAddr(IOAddress("ff02::1:2"));
  59. pkt->setIndex(2);
  60. pkt->setIface("eth0");
  61. }
  62. Pkt4Ptr Dhcpv4SrvTest::captureRelayedDiscover() {
  63. /* string exported from Wireshark:
  64. User Datagram Protocol, Src Port: bootps (67), Dst Port: bootps (67)
  65. Source port: bootps (67)
  66. Destination port: bootps (67)
  67. Length: 541
  68. Checksum: 0x2181 [validation disabled]
  69. Bootstrap Protocol
  70. Message type: Boot Request (1)
  71. Hardware type: Ethernet
  72. Hardware address length: 6
  73. Hops: 1
  74. Transaction ID: 0x5d05478d
  75. Seconds elapsed: 0
  76. Bootp flags: 0x0000 (Unicast)
  77. Client IP address: 0.0.0.0 (0.0.0.0)
  78. Your (client) IP address: 0.0.0.0 (0.0.0.0)
  79. Next server IP address: 0.0.0.0 (0.0.0.0)
  80. Relay agent IP address: 10.254.226.1 (10.254.226.1)
  81. Client MAC address: Netgear_b8:15:14 (20:e5:2a:b8:15:14)
  82. Client hardware address padding: 00000000000000000000
  83. Server host name not given
  84. Boot file name not given
  85. Magic cookie: DHCP
  86. Option: (53) DHCP Message Type
  87. Option: (55) Parameter Request List
  88. Option: (60) Vendor class identifier
  89. Option: (125) V-I Vendor-specific Information
  90. Option: (43) Vendor-Specific Information (CableLabs)
  91. Option: (61) Client identifier
  92. Option: (57) Maximum DHCP Message Size
  93. Option: (82) Agent Information Option
  94. Option: (255) End */
  95. string hex_string =
  96. "010106015d05478d000000000000000000000000000000000afee20120e52ab8151400"
  97. "0000000000000000000000000000000000000000000000000000000000000000000000"
  98. "0000000000000000000000000000000000000000000000000000000000000000000000"
  99. "0000000000000000000000000000000000000000000000000000000000000000000000"
  100. "0000000000000000000000000000000000000000000000000000000000000000000000"
  101. "0000000000000000000000000000000000000000000000000000000000000000000000"
  102. "0000000000000000000000000000000000000000000000000000638253633501013707"
  103. "0102030407067d3c0a646f63736973332e303a7d7f0000118b7a010102057501010102"
  104. "010303010104010105010106010107010f0801100901030a01010b01180c01010d0200"
  105. "400e0200100f010110040000000211010014010015013f160101170101180104190104"
  106. "1a01041b01201c01021d01081e01201f01102001102101022201012301002401002501"
  107. "01260200ff2701012b59020345434d030b45434d3a45524f55544552040d3242523232"
  108. "39553430303434430504312e3034060856312e33332e30330707322e332e3052320806"
  109. "30303039354209094347333030304443520a074e657467656172fe01083d0fff2ab815"
  110. "140003000120e52ab81514390205dc5219010420000002020620e52ab8151409090000"
  111. "118b0401020300ff";
  112. return (packetFromCapture(hex_string));
  113. }
  114. }; // end of isc::dhcp::test namespace
  115. }; // end of isc::dhcp namespace
  116. }; // end of isc namespace