Unable to bind_to_device

Hello,

Trying to set SO_BINDTODEVICE flag on a socket like:

iex(8)> :gen_tcp.connect({8, 8, 8, 8}, 53, [inet_backend: :socket, bind_to_device: 'ens3', active: false])
** (exit) :badarg
    (kernel 8.5.1) gen_tcp_socket.erl:137: :gen_tcp_socket.connect_lookup/4
    (kernel 8.5.1) gen_tcp_socket.erl:103: :gen_tcp_socket.connect/4

If I understand correctly this is not capabilities related issue, I’m just passing the arguments in a wrong way or so.

Can anyone help, please?

1 Like

Hi, as per the doc {bind_to_device, Ifname :: binary()} so Ifname should be a binary and you should be passing the arguments in tuples like this:

gen_tcp:connect({8, 8, 8, 8}, 53, [{inet_backend,socket}, {bind_to_device, <<"ens2">>}, {active,false}]).

I don’t know if this will work tho

1 Like