phdr.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /** @file phdr.c
  2. * @brief Class represents a parameter header.
  3. */
  4. #include <stdlib.h>
  5. #include <stdint.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <assert.h>
  9. #include <unistd.h>
  10. #include <errno.h>
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include <arpa/inet.h>
  14. #include <faux/faux.h>
  15. #include <faux/str.h>
  16. #include <faux/list.h>
  17. #include <faux/msg.h>
  18. /** @brief Sets type to parameter header.
  19. *
  20. * @param [in] phdr Allocated faux_phdr_t object.
  21. * @param [in] param_type Type of parameter.
  22. */
  23. void faux_phdr_set_type(faux_phdr_t *phdr, uint16_t param_type)
  24. {
  25. assert(phdr);
  26. if (!phdr)
  27. return;
  28. phdr->param_type = htons(param_type);
  29. }
  30. /** @brief Gets type from parameter header.
  31. *
  32. * @param [in] phdr Allocated faux_phdr_t object.
  33. * @return Type of parameter or 0 on error.
  34. */
  35. uint16_t faux_phdr_get_type(const faux_phdr_t *phdr)
  36. {
  37. assert(phdr);
  38. if (!phdr)
  39. return 0;
  40. return ntohs(phdr->param_type);
  41. }
  42. /** @brief Sets length to parameter header.
  43. *
  44. * @param [in] phdr Allocated faux_phdr_t object.
  45. * @param [in] param_len Length of parameter.
  46. */
  47. void faux_phdr_set_len(faux_phdr_t *phdr, uint32_t param_len)
  48. {
  49. assert(phdr);
  50. if (!phdr)
  51. return;
  52. phdr->param_len = htonl(param_len);
  53. }
  54. /** @brief Gets length from parameter header.
  55. *
  56. * @param [in] phdr Allocated faux_phdr_t object.
  57. * @return Length of parameter or 0 on error.
  58. */
  59. uint32_t faux_phdr_get_len(const faux_phdr_t *phdr)
  60. {
  61. assert(phdr);
  62. if (!phdr)
  63. return 0;
  64. return ntohl(phdr->param_len);
  65. }