Skip to content

Commit

Permalink
multicast: add multicast_iface for IPv6 multicast (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianfridrich committed Jul 2, 2024
1 parent 243e870 commit 5ff0759
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/examples/config
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
# multicast receivers (in priority order)- port number must be even
#multicast_call_prio 0
#multicast_ttl 1
#multicast_iface eth0 # needed for IPv6 multicast
#multicast_jbuf_type fixed # off, fixed, adaptive
#multicast_jbuf_delay 5-10 # frames
#multicast_fade_time 125 # fade in/out time in [ms]
#multicast_listener 224.0.2.21:50000
#multicast_listener 224.0.2.21:50002
#multicast_listener [FF2E::42]:50004
27 changes: 27 additions & 0 deletions modules/multicast/multicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* Copyright (C) 2021 Commend.com - c.huber@commend.com
*/

#include <net/if.h>
#undef LIST_INIT
#undef LIST_FOREACH

#include <re.h>
#include <baresip.h>

Expand All @@ -20,12 +24,14 @@ struct mccfg {
uint32_t callprio;
uint32_t ttl;
uint32_t tfade;
char iface[128];
};

static struct mccfg mccfg = {
0,
1,
125,
""
};


Expand Down Expand Up @@ -309,6 +315,24 @@ static int cmd_mcreg(struct re_printf *pf, void *arg)
goto out;
}

#ifdef HAVE_GETIFADDRS
if (str_isset(mccfg.iface)) {
unsigned int if_index;
if_index = if_nametoindex(mccfg.iface);
if (!if_index) {
warning("multicast: could not find interface %s\n",
&mccfg.iface);
if (sa_af(&addr) == AF_INET6) {
err = EINVAL;
goto out;
}
}
else {
sa_set_scopeid(&addr, if_index);
}
}
#endif

err = mcreceiver_alloc(&addr, prio);

out:
Expand Down Expand Up @@ -645,6 +669,9 @@ static int module_read_config(void)
if (mccfg.tfade > 2000)
mccfg.tfade = 2000;

(void)conf_get_str(conf_cur(), "multicast_iface", mccfg.iface,
sizeof(mccfg.iface));

sa_init(&laddr, AF_INET);
err = conf_apply(conf_cur(), "multicast_listener",
module_read_config_handler, &prio);
Expand Down

0 comments on commit 5ff0759

Please sign in to comment.