I am working on an app which must join multiple source-specific multicasts, SSM, and all the multicasts use the same group address and port. Only the source address changes. I have tested and this works fine if the group and port are different for each multicast. I have a function:
open_ssm_mc(Group, Port, Source, Interface) ->
% add_source_membership
LocalIp = ip_to_binary(Interface),
GroupIp = ip_to_binary(Group),
SourceIp = ip_to_binary(Source),
Bin = << GroupIp/binary, LocalIp/binary, SourceIp/binary >>,
{ok, Fd} = procket:open(Port, [{protocol, udp}, {type, dgram}, {family, inet}]),
ok = procket:setsockopt(Fd, 'SOL_SOCKET', 'SO_REUSEADDR', <<1:32>>),
ok = procket:setsockopt(Fd, 'SOL_SOCKET', 'SO_REUSEPORT', <<1:32>>),
ok = procket:setsockopt(Fd, 0, 39, Bin),
% ok = procket:bind(Fd, GroupIp),
{ok, Fd, Port}.
Where the returned FD is then used in a gen_udp:open() like:
{ok, Fd, Port} = cse_socket:open_ssm_mc(Addr, Port, Source, LAddr),
{ok, Socket} = gen_udp:open(0, [{fd, Fd}, binary, {active, true}, {recbuf, RecBuf}, {buffer, Buffer}, {read_packets, ReadPackets}]),
?LOGIT_INFO("SSM socket open and active", [{fd, Fd}, {socket, Socket}, {port, Port}, {group, Addr}, {source, Source}, {interface, LAddr}])
As I said, only the "Source" changes for each instance, and the second instance fails with {error,eaddrinuse} on the procket:open(Port...) call. I am missing some other option that needs set on the FD, or Socket.??
Thanks,
Mark.
I am working on an app which must join multiple source-specific multicasts, SSM, and all the multicasts use the same group address and port. Only the source address changes. I have tested and this works fine if the group and port are different for each multicast. I have a function:
Where the returned FD is then used in a gen_udp:open() like:
{ok, Fd, Port} = cse_socket:open_ssm_mc(Addr, Port, Source, LAddr), {ok, Socket} = gen_udp:open(0, [{fd, Fd}, binary, {active, true}, {recbuf, RecBuf}, {buffer, Buffer}, {read_packets, ReadPackets}]), ?LOGIT_INFO("SSM socket open and active", [{fd, Fd}, {socket, Socket}, {port, Port}, {group, Addr}, {source, Source}, {interface, LAddr}])As I said, only the "Source" changes for each instance, and the second instance fails with {error,eaddrinuse} on the procket:open(Port...) call. I am missing some other option that needs set on the FD, or Socket.??
Thanks,
Mark.