pim_igmp_join.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 <sys/types.h>
  20. #include <sys/socket.h>
  21. #include <string.h>
  22. #include "zebra.h"
  23. #include "pim_igmp_join.h"
  24. #ifndef SOL_IP
  25. #define SOL_IP IPPROTO_IP
  26. #endif
  27. #ifndef MCAST_JOIN_SOURCE_GROUP
  28. #define MCAST_JOIN_SOURCE_GROUP 46
  29. struct group_source_req
  30. {
  31. uint32_t gsr_interface;
  32. struct sockaddr_storage gsr_group;
  33. struct sockaddr_storage gsr_source;
  34. };
  35. #endif
  36. int pim_igmp_join_source(int fd, ifindex_t ifindex,
  37. struct in_addr group_addr,
  38. struct in_addr source_addr)
  39. {
  40. struct group_source_req req;
  41. struct sockaddr_in group;
  42. struct sockaddr_in source;
  43. memset(&group, 0, sizeof(group));
  44. group.sin_family = AF_INET;
  45. group.sin_addr = group_addr;
  46. group.sin_port = htons(0);
  47. memcpy(&req.gsr_group, &group, sizeof(struct sockaddr_in));
  48. memset(&source, 0, sizeof(source));
  49. source.sin_family = AF_INET;
  50. source.sin_addr = source_addr;
  51. source.sin_port = htons(0);
  52. memcpy(&req.gsr_source, &source, sizeof(struct sockaddr_in));
  53. req.gsr_interface = ifindex;
  54. return setsockopt(fd, SOL_IP, MCAST_JOIN_SOURCE_GROUP,
  55. &req, sizeof(req));
  56. return 0;
  57. }