pim_igmp_join.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 "pim_igmp_join.h"
  23. #ifndef SOL_IP
  24. #define SOL_IP IPPROTO_IP
  25. #endif
  26. #ifndef MCAST_JOIN_SOURCE_GROUP
  27. #define MCAST_JOIN_SOURCE_GROUP 46
  28. struct group_source_req
  29. {
  30. uint32_t gsr_interface;
  31. struct sockaddr_storage gsr_group;
  32. struct sockaddr_storage gsr_source;
  33. };
  34. #endif
  35. int pim_igmp_join_source(int fd, int ifindex,
  36. struct in_addr group_addr,
  37. struct in_addr source_addr)
  38. {
  39. struct group_source_req req;
  40. struct sockaddr_in *group_sa = (struct sockaddr_in *) &req.gsr_group;
  41. struct sockaddr_in *source_sa = (struct sockaddr_in *) &req.gsr_source;
  42. memset(group_sa, 0, sizeof(*group_sa));
  43. group_sa->sin_family = AF_INET;
  44. group_sa->sin_addr = group_addr;
  45. group_sa->sin_port = htons(0);
  46. memset(source_sa, 0, sizeof(*source_sa));
  47. source_sa->sin_family = AF_INET;
  48. source_sa->sin_addr = source_addr;
  49. source_sa->sin_port = htons(0);
  50. req.gsr_interface = ifindex;
  51. return setsockopt(fd, SOL_IP, MCAST_JOIN_SOURCE_GROUP,
  52. &req, sizeof(req));
  53. return 0;
  54. }