[erlang-questions] Socket option FREEBIND
Michael L Martin
mmartin4242@REDACTED
Fri Oct 20 17:10:37 CEST 2017
Raw socket options looks like it should be the answer, but I'm not
getting good results:
iex(worker@REDACTED)28> {:ok, s} = :gen_tcp.connect('localhost', 80,
[{:raw, 6, 15, <<1>>}, {:ip, {10, 138, 69, 63}}])
{:ok, #Port<0.12110>}
iex(worker@REDACTED)29> :inet.getopts(s, [{:raw, 6, 15, 32}])
{:ok, []} <== option not set?
iex(worker@REDACTED)29> {:ok, s} = :gen_tcp.connect('localhost', 80,
[{:raw, 6, 15, <<1>>}, {:ip, {10, 138, 69, 64}}])
** (MatchError) no match of right hand side value: {:error, :eaddrnotavail}
It appears that the IP_FREEBIND option is simply not set. If I use
IP_TRANSPARENT instead:
iex(worker@REDACTED)35> {:ok, s} = :gen_tcp.connect('localhost', 80,
[{:raw, 6, 19, <<1>>}, {:ip, {10, 138, 69, 63}}])
{:ok, #Port<0.12113>}
iex(worker@REDACTED)34> :inet.getopts(s, [{:raw, 6, 19, 32}])
{:ok, [{:raw, 6, 19, <<0, 0, 0, 0>>}]}
In this case, the raw option 19 (IP_TRANSPARENT) is set, but to false
rather than true. I believe this is because the beam file needs root or
CAP_NET_ADMIN.
Any thoughts?
On 2017-10-16 01:18 PM, Guilherme Andrade wrote:
> I believe you can use raw socket options[1] for that, but it won't be
> portable.
>
> [1]: http://erlang.org/doc/man/inet.html#setopts-2 - {raw, Protocol,
> OptionNum, ValueBin}
>
> On 16 October 2017 at 15:09, Michael L Martin <mmartin4242@REDACTED
> <mailto:mmartin4242@REDACTED>> wrote:
>
> Hi all,
>
> Is there a way to specify the FREEBIND option when opening a
> socket? I don't see any reference to it in the documentation.
>
>
> Thanks,
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED <mailto:erlang-questions@REDACTED>
> http://erlang.org/mailman/listinfo/erlang-questions
> <http://erlang.org/mailman/listinfo/erlang-questions>
>
>
>
>
> --
> Guilherme
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171020/56bb980a/attachment.htm>
More information about the erlang-questions
mailing list