perf_pkt6.cc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. void
  56. PerfPkt6::writeAt(size_t dest_pos,
  57. std::vector<uint8_t>::iterator first,
  58. std::vector<uint8_t>::iterator last) {
  59. return (PktTransform::writeAt(data_, dest_pos, first, last));
  60. }
  61. } // namespace perfdhcp
  62. } // namespace isc