target_ip_source_slash_descriptor.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_IP_SOURCE_SLASH_DESCRIPTOR
  23. #define _UCSI_DVB_TARGET_IP_SOURCE_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_ip_source_slash_descriptor structure.
  32. */
  33. struct dvb_target_ip_source_slash_descriptor {
  34. struct descriptor d;
  35. /* struct dvb_ipv4_source_slash ipv4_source_slash[] */
  36. } __ucsi_packed;
  37. /**
  38. * An entry in the ipv4_source_slash field of a dvb_target_ip_source_slash_descriptor.
  39. */
  40. struct dvb_ipv4_source_slash {
  41. uint8_t ipv4_source_addr[4];
  42. uint8_t ipv4_source_slash;
  43. uint8_t ipv4_dest_addr[4];
  44. uint8_t ipv4_dest_slash;
  45. } __ucsi_packed;
  46. /**
  47. * Process a dvb_target_ip_source_slash_descriptor.
  48. *
  49. * @param d Generic descriptor structure pointer.
  50. * @return dvb_target_ip_source_slash_descriptor pointer, or NULL on error.
  51. */
  52. static inline struct dvb_target_ip_source_slash_descriptor*
  53. dvb_target_ip_source_slash_descriptor_codec(struct descriptor* d)
  54. {
  55. uint32_t len = d->len;
  56. if (len % sizeof(struct dvb_ipv4_source_slash))
  57. return NULL;
  58. return (struct dvb_target_ip_source_slash_descriptor*) d;
  59. }
  60. /**
  61. * Iterator for entries in the ipv4_source_slash field of a dvb_target_ip_source_slash_descriptor.
  62. *
  63. * @param d dvb_target_ip_source_slash_descriptor pointer.
  64. * @param pos Variable containing a pointer to the current dvb_ipv4_source_slash.
  65. */
  66. #define dvb_target_ip_source_slash_descriptor_ipv4_source_slash_for_each(d, pos) \
  67. for ((pos) = dvb_target_ip_source_slash_descriptor_ipv4_source_slash_first(d); \
  68. (pos); \
  69. (pos) = dvb_target_ip_source_slash_descriptor_ipv4_source_slash_next(d, pos))
  70. /******************************** PRIVATE CODE ********************************/
  71. static inline struct dvb_ipv4_source_slash*
  72. dvb_target_ip_source_slash_descriptor_ipv4_source_slash_first(struct dvb_target_ip_source_slash_descriptor *d)
  73. {
  74. if (d->d.len == 0)
  75. return NULL;
  76. return (struct dvb_ipv4_source_slash *)
  77. ((uint8_t*) d + sizeof(struct dvb_target_ip_source_slash_descriptor));
  78. }
  79. static inline struct dvb_ipv4_source_slash*
  80. dvb_target_ip_source_slash_descriptor_ipv4_source_slash_next(struct dvb_target_ip_source_slash_descriptor *d,
  81. struct dvb_ipv4_source_slash *pos)
  82. {
  83. uint8_t *end = (uint8_t*) d + 2 + d->d.len;
  84. uint8_t *next = (uint8_t *) pos + sizeof(struct dvb_ipv4_source_slash);
  85. if (next >= end)
  86. return NULL;
  87. return (struct dvb_ipv4_source_slash *) next;
  88. }
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif