perf_pkt6.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2011 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 <iostream>
  15. #include <exceptions/exceptions.h>
  16. #include <dhcp/libdhcp++.h>
  17. #include <dhcp/dhcp6.h>
  18. #include "perf_pkt6.h"
  19. #include "pkt_transform.h"
  20. using namespace std;
  21. using namespace isc;
  22. using namespace dhcp;
  23. namespace isc {
  24. namespace perfdhcp {
  25. PerfPkt6::PerfPkt6(const uint8_t* buf,
  26. size_t len,
  27. size_t transid_offset,
  28. uint32_t transid) :
  29. Pkt6(buf, len, Pkt6::UDP),
  30. transid_offset_(transid_offset) {
  31. setTransid(transid);
  32. }
  33. bool
  34. PerfPkt6::rawPack() {
  35. return (PktTransform::pack(dhcp::Option::V6,
  36. data_,
  37. options_,
  38. getTransidOffset(),
  39. getTransid(),
  40. bufferOut_));
  41. }
  42. bool
  43. PerfPkt6::rawUnpack() {
  44. uint32_t transid = getTransid();
  45. bool res = PktTransform::unpack(dhcp::Option::V6,
  46. data_,
  47. options_,
  48. getTransidOffset(),
  49. transid);
  50. if (res) {
  51. setTransid(transid);
  52. }
  53. return (res);
  54. }
  55. } // namespace perfdhcp
  56. } // namespace isc