addr_utilities.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #ifndef ADDR_UTILITIES_H
  15. #define ADDR_UTILITIES_H
  16. #include <asiolink/io_address.h>
  17. namespace isc {
  18. namespace dhcp {
  19. /// This code is based on similar code from the Dibbler project. I, Tomasz Mrugalski,
  20. /// as a sole creator of that code hereby release it under BSD license for the benefit
  21. /// of the BIND10 project.
  22. /// @brief returns a first address in a given prefix
  23. ///
  24. /// Example: For 2001:db8:1\::deaf:beef and length /120 the function will return
  25. /// 2001:db8:1\::dead:be00. See also @ref lastAddrInPrefix.
  26. ///
  27. /// @todo It currently works for v6 only and will throw if v4 address is passed.
  28. ///
  29. /// @param prefix and address that belongs to a prefix
  30. /// @param len prefix length
  31. ///
  32. /// @return first address from a prefix
  33. isc::asiolink::IOAddress firstAddrInPrefix(const isc::asiolink::IOAddress& prefix,
  34. uint8_t len);
  35. /// @brief returns a last address in a given prefix
  36. ///
  37. /// Example: For 2001:db8:1\::deaf:beef and length /112 the function will return
  38. /// 2001:db8:1\::dead:ffff. See also @ref firstAddrInPrefix.
  39. ///
  40. /// @todo It currently works for v6 only and will throw if v4 address is passed.
  41. ///
  42. /// @param prefix and address that belongs to a prefix
  43. /// @param len prefix length
  44. ///
  45. /// @return first address from a prefix
  46. isc::asiolink::IOAddress lastAddrInPrefix(const isc::asiolink::IOAddress& prefix,
  47. uint8_t len);
  48. /// @brief generates an IPv4 netmask of specified length
  49. /// @throw BadValue if len is greater than 32
  50. /// @return netmask
  51. isc::asiolink::IOAddress getNetmask4(uint8_t len);
  52. };
  53. };
  54. #endif // ADDR_UTILITIES_H