target_ipv6_slash_descriptor.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * section and descriptor parser
  3. *
  4. * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
  5. * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
  6. * Copyright (C) 2006 Stephane Este-Gracias (sestegra@free.fr)
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  21. */
  22. #ifndef _UCSI_DVB_TARGET_IPV6_SLASH_DESCRIPTOR
  23. #define _UCSI_DVB_TARGET_IPV6_SLASH_DESCRIPTOR 1
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. #include <libucsi/descriptor.h>
  29. #include <libucsi/types.h>
  30. /**
  31. * dvb_target_ipv6_slash_descriptor structure.
  32. */
  33. struct dvb_target_ipv6_slash_descriptor {
  34. struct descriptor d;
  35. /* struct dvb_ipv6_slash ipv6_slash[] */
  36. } __ucsi_packed;
  37. /**
  38. * An entry in the ipv6_slash field of a dvb_target_ipv6_slash_descriptor.
  39. */
  40. struct dvb_ipv6_slash {
  41. uint8_t ipv6_addr[16];
  42. uint8_t ipv6_slash;
  43. } __ucsi_packed;
  44. /**
  45. * Process a dvb_target_ipv6_slash_descriptor.
  46. *
  47. * @param d Generic descriptor structure pointer.
  48. * @return dvb_target_ipv6_slash_descriptor pointer, or NULL on error.
  49. */
  50. static inline struct dvb_target_ipv6_slash_descriptor*
  51. dvb_target_ipv6_slash_descriptor_codec(struct descriptor* d)
  52. {
  53. uint32_t len = d->len;
  54. if (len % sizeof(struct dvb_ipv6_slash))
  55. return NULL;
  56. return (struct dvb_target_ipv6_slash_descriptor*) d;
  57. }
  58. /**
  59. * Iterator for entries in the ipv6_slash field of a dvb_target_ipv6_slash_descriptor.
  60. *
  61. * @param d dvb_target_ipv6_slash_descriptor pointer.
  62. * @param pos Variable containing a pointer to the current dvb_ipv6_slash.
  63. */
  64. #define dvb_target_ipv6_slash_descriptor_ipv6_slash_for_each(d, pos) \
  65. for ((pos) = dvb_target_ipv6_slash_descriptor_ipv6_slash_first(d); \
  66. (pos); \
  67. (pos) = dvb_target_ipv6_slash_descriptor_ipv6_slash_next(d, pos))
  68. /******************************** PRIVATE CODE ********************************/
  69. static inline struct dvb_ipv6_slash*
  70. dvb_target_ipv6_slash_descriptor_ipv6_slash_first(struct dvb_target_ipv6_slash_descriptor *d)
  71. {
  72. if (d->d.len == 0)
  73. return NULL;
  74. return (struct dvb_ipv6_slash *)
  75. ((uint8_t*) d + sizeof(struct dvb_target_ipv6_slash_descriptor));
  76. }
  77. static inline struct dvb_ipv6_slash*
  78. dvb_target_ipv6_slash_descriptor_ipv6_slash_next(struct dvb_target_ipv6_slash_descriptor *d,
  79. struct dvb_ipv6_slash *pos)
  80. {
  81. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  82. uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_ipv6_slash);
  83. if (next >= end)
  84. return NULL;
  85. return (struct dvb_ipv6_slash *) next;
  86. }
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. #endif