perf_pkt4.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (C) 2012 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 <dhcp/libdhcp++.h>
  15. #include <dhcp/dhcp4.h>
  16. #include "perf_pkt4.h"
  17. using namespace std;
  18. using namespace isc;
  19. using namespace dhcp;
  20. namespace isc {
  21. namespace perfdhcp {
  22. PerfPkt4::PerfPkt4(const uint8_t* buf,
  23. size_t len,
  24. size_t transid_offset,
  25. uint32_t transid) :
  26. Pkt4(buf, len),
  27. transid_offset_(transid_offset) {
  28. setTransid(transid);
  29. }
  30. bool
  31. PerfPkt4::rawPack() {
  32. return (PktTransform::pack(dhcp::Option::V4,
  33. data_,
  34. options_,
  35. getTransidOffset(),
  36. getTransid(),
  37. bufferOut_));
  38. }
  39. bool
  40. PerfPkt4::rawUnpack() {
  41. uint32_t transid = getTransid();
  42. bool res = PktTransform::unpack(dhcp::Option::V4,
  43. data_,
  44. options_,
  45. getTransidOffset(),
  46. transid);
  47. if (res) {
  48. setTransid(transid);
  49. }
  50. return (res);
  51. }
  52. void
  53. PerfPkt4::writeAt(size_t dest_pos,
  54. std::vector<uint8_t>::iterator first,
  55. std::vector<uint8_t>::iterator last) {
  56. return (PktTransform::writeAt(data_, dest_pos, first, last));
  57. }
  58. } // namespace perfdhcp
  59. } // namespace isc