pim_int.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. PIM for Quagga
  3. Copyright (C) 2008 Everton da Silva Marques
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING; if not, write to the
  14. Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  15. MA 02110-1301 USA
  16. $QuaggaId: $Format:%an, %ai, %h$ $
  17. */
  18. #include <zebra.h>
  19. #include <string.h>
  20. #include <netinet/in.h>
  21. #include <arpa/inet.h>
  22. #include "pim_int.h"
  23. uint32_t pim_read_uint32_host(const uint8_t *buf)
  24. {
  25. uint32_t val;
  26. memcpy(&val, buf, sizeof(val));
  27. /* val is in netorder */
  28. val = ntohl(val);
  29. /* val is in hostorder */
  30. return val;
  31. }
  32. void pim_write_uint32(uint8_t *buf, uint32_t val_host)
  33. {
  34. /* val_host is in host order */
  35. val_host = htonl(val_host);
  36. /* val_host is in netorder */
  37. memcpy(buf, &val_host, sizeof(val_host));
  38. }