AddrTools.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #ifndef AddrTools_H
  16. #define AddrTools_H
  17. #include "util/Linker.h"
  18. Linker_require("util/AddrTools.c")
  19. #include <stdint.h>
  20. /** Takes the path in host byte order. */
  21. void AddrTools_printPath(uint8_t out[20], uint64_t path);
  22. /**
  23. * Parse out a path.
  24. *
  25. * @param out a pointer to a number which will be set to the path in HOST BYTE ORDER.
  26. * @param netAddr a string representation of the path such as "0000.1111.2222.3333" in Big Endian.
  27. * @return 0 if successful, -1 if the netAddr is malformed.
  28. */
  29. int AddrTools_parsePath(uint64_t* out, const uint8_t netAddr[20]);
  30. void AddrTools_printIp(uint8_t output[40], const uint8_t binIp[16]);
  31. void AddrTools_printShortIp(uint8_t output[40], const uint8_t binIp[16]);
  32. /**
  33. * Parse out an address.
  34. *
  35. * @param out a pointer to a byte array which will be set to the bytes of the ipv6 address.
  36. * @param hexAddr a string representation of the ipv6 address such as:
  37. * "fc4f:630d:e499:8f5b:c49f:6e6b:01ae:3120".
  38. * @return 0 if successful, -1 if the hexAddr is malformed.
  39. */
  40. int AddrTools_parseIp(uint8_t out[16], const uint8_t* hexAddr);
  41. /**
  42. * Parse out an ethernet MAC address.
  43. *
  44. * @param out a pointer to a byte array which will be set to the bytes of the MAC address.
  45. * @param hexAddr a string representation of an ethernet MAC address such as:
  46. * "00:11:22:33:44:55"
  47. * @return 0 if successful, -1 if the hexAddr is malformed.
  48. */
  49. int AddrTools_parseMac(uint8_t out[6], const uint8_t hexAddr[17]);
  50. void AddrTools_printMac(uint8_t output[18], const uint8_t binMac[6]);
  51. #endif