Problems with gen_udp on multi-homed hosts

Gregory Haskins <>
Tue Nov 16 16:31:47 CET 2010


Hi All,

I am trying to develop a custom DHCP server against 14B on that is
sitting on a multi-homed linux host.  I only want the server to
listen/respond on one of these interfaces, but I am having trouble
getting gen_udp to behave in a way I would expect.

My system has the following interfaces:

3> inet:getiflist().
{ok,["lo","br0","virbr0"]}
4> inet:ifget("virbr0", [addr]).
{ok,[{addr,{192,168,122,1}}]}
5> inet:ifget("br0", [addr]).
{ok,[{addr,{151,155,230,24}}]}

and I am interested in packets only on 192.168.122.1/virbr0.

So if I gen_udp:open() _without_ {ip, ?ADDR} set, I can see the
broadcasts coming from 192.168.122.0/24 (as well as from the other
interfaces) as I would expect.  However, the {udp, Socket, ..} message I
get has a inet:sockname() of {0.0.0.0}, and if I try to reply with a
broadcast of {255.255.255.255} to the same socket, it goes out on the
"br0" interface.

So the obvious solution to me after googling was to use the {ip,
{192.168.122.1}} option on the open.  The open() call succeeds with this
option set, but I never see any packets (even though I have sniffed the
line and they are indeed being sent.  As a sanity check, I also set a
bogus IP in the open(), and it does indeed exception out, so it seems
like it is taking the option I set.

I am running out of ideas outside of abandoning gen_udp() in favor of a
ports driver, and/or not writing the DHCP portion of my code in Erlang.
 Neither is particularly attractive, especially given that this seems
like a fairly straight forward sockets app and I would think it could be
made to work.

Thoughts?

-Greg

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 267 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20101116/0b502a9f/attachment.bin>


More information about the erlang-questions mailing list