hwaddr.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #ifndef HWADDR_H
  15. #define HWADDR_H
  16. #include <vector>
  17. #include <stdint.h>
  18. #include <stddef.h>
  19. #include <dhcp/dhcp4.h>
  20. #include <boost/shared_ptr.hpp>
  21. namespace isc {
  22. namespace dhcp {
  23. /// @brief Hardware type that represents information from DHCPv4 packet
  24. struct HWAddr {
  25. public:
  26. /// @brief Size of an ethernet hardware address.
  27. static const size_t ETHERNET_HWADDR_LEN = 6;
  28. /// @brief Maximum size of a hardware address.
  29. static const size_t MAX_HWADDR_LEN = 20;
  30. /// @brief default constructor
  31. HWAddr();
  32. /// @brief constructor, based on C-style pointer and length
  33. /// @param hwaddr pointer to hardware address
  34. /// @param len length of the address pointed by hwaddr
  35. /// @param htype hardware type
  36. HWAddr(const uint8_t* hwaddr, size_t len, uint8_t htype);
  37. /// @brief constructor, based on C++ vector<uint8_t>
  38. /// @param hwaddr const reference to hardware address
  39. /// @param htype hardware type
  40. HWAddr(const std::vector<uint8_t>& hwaddr, uint8_t htype);
  41. // Vector that keeps the actual hardware address
  42. std::vector<uint8_t> hwaddr_;
  43. // Hardware type
  44. uint8_t htype_;
  45. /// @brief Returns textual representation of a client-id (e.g. 00:01:02:03)
  46. std::string toText() const;
  47. /// @brief Compares two hardware addresses for equality
  48. bool operator==(const HWAddr& other) const;
  49. /// @brief Compares two hardware addresses for inequality
  50. bool operator!=(const HWAddr& other) const;
  51. };
  52. /// @brief Shared pointer to a hardware address structure
  53. typedef boost::shared_ptr<HWAddr> HWAddrPtr;
  54. }; // end of isc::dhcp namespace
  55. }; // end of isc namespace
  56. #endif // HWADDR_H