Re: problem with new socket module setopt()

Micael Karlberg <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <HE1PR0701MB23939201AB68212263EB93448EBA9@HE1PR0701MB2393.eurprd07.prod.outlook.com>
Before the call to the setopt, add a call to socket:setopt(Socket, otp, debug, true).

/BMK


________________________________
From: erlang-questions on behalf of Mark Geib
Sent: Thursday, January 28, 2021 6:24 PM
To: Erlang Questions
Subject: problem with new socket module setopt()

I am using the new socket module in order to join a source-specific multicast and receive datagrams. The following code fails with a “badarg” error on the socket:setopt() call. I have carefully checked the docs for R23, but can not find the problem.

    {ok, GroupAddr} = inet:getaddr(Group, inet),
    {ok, SourceAddr} = inet:getaddr(Source, inet),
    {ok, IfAddr} = inet:getaddr(Interface, inet),
    IpMreqSource = #{multiaddr => GroupAddr,
                     interface => IfAddr,
                     sourceaddr => SourceAddr},

    {ok, Socket} = socket:open(inet, dgram, udp),
    {ok, Port} = socket:bind(Socket, #{family => inet, port => Port, addr => GroupAddr}),
    ok = socket:setopt(Socket, ip, add_source_membership,  IpMreqSource),

I am using Erlang R23, latest release on debian-9 host.
Any suggestions would be appreciated greatly.

Mark.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.