pim_int.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 <string.h>
  19. #include <netinet/in.h>
  20. #include <arpa/inet.h>
  21. #include "pim_int.h"
  22. uint32_t pim_read_uint32_host(const uint8_t *buf)
  23. {
  24. uint32_t val;
  25. memcpy(&val, buf, sizeof(val));
  26. /* val is in netorder */
  27. val = ntohl(val);
  28. /* val is in hostorder */
  29. return val;
  30. }
  31. void pim_write_uint32(uint8_t *buf, uint32_t val_host)
  32. {
  33. /* val_host is in host order */
  34. val_host = htonl(val_host);
  35. /* val_host is in netorder */
  36. memcpy(buf, &val_host, sizeof(val_host));
  37. }