1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2008 Everton da Silva Marques
7 #ifndef PIM_IGMP_JOIN_H
8 #define PIM_IGMP_JOIN_H
10 /* required headers #include'd by caller */
13 #define SOL_IP IPPROTO_IP
16 #ifndef MCAST_JOIN_GROUP
17 #define MCAST_JOIN_GROUP 42
20 #ifndef MCAST_JOIN_SOURCE_GROUP
21 #define MCAST_JOIN_SOURCE_GROUP 46
22 struct group_source_req
{
23 uint32_t gsr_interface
;
24 struct sockaddr_storage gsr_group
;
25 struct sockaddr_storage gsr_source
;
29 static inline int pim_igmp_join_source(int fd
, ifindex_t ifindex
,
30 struct in_addr group_addr
,
31 struct in_addr source_addr
)
33 struct group_source_req req
;
34 struct sockaddr_in group
;
35 struct sockaddr_in source
;
37 memset(&req
, 0, sizeof(req
));
38 memset(&group
, 0, sizeof(group
));
39 group
.sin_family
= AF_INET
;
40 group
.sin_addr
= group_addr
;
41 group
.sin_port
= htons(0);
42 memcpy(&req
.gsr_group
, &group
, sizeof(struct sockaddr_in
));
44 memset(&source
, 0, sizeof(source
));
45 source
.sin_family
= AF_INET
;
46 source
.sin_addr
= source_addr
;
47 source
.sin_port
= htons(0);
48 memcpy(&req
.gsr_source
, &source
, sizeof(struct sockaddr_in
));
50 req
.gsr_interface
= ifindex
;
52 if (source_addr
.s_addr
== INADDR_ANY
)
53 return setsockopt(fd
, SOL_IP
, MCAST_JOIN_GROUP
, &req
,
56 return setsockopt(fd
, SOL_IP
, MCAST_JOIN_SOURCE_GROUP
, &req
,
60 #endif /* PIM_IGMP_JOIN_H */