pim_igmp_join.c 1.9 KB

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