[erlang-questions] Problems with gen_udp on multi-homed hosts

Raimo Niskanen <>
Wed Nov 17 11:17:59 CET 2010


This seems to be a known property of the Linux TCP/IP stack, and I have
checked FreeBSD 7.3 seems to behave the same meaning all BSDs probably do.
Windows don't by the way, there you apparently get the broadcasts...

http://www.developerweb.net/forum/showthread.php?t=5722

How network specific broadcasts work I have just tested briefly
on Linux, and it seems not to make any difference.


On Tue, Nov 16, 2010 at 11:48:21AM -0500, Michael Santos wrote:
> On Tue, Nov 16, 2010 at 10:31:47AM -0500, Gregory Haskins wrote:
> > 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.
> 
> Does it work if you send the packet out using a more specific broadcast
> address? e.g., 192.168.122.255
> 
> > 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.
> 
> Not sure why this isn't working, maybe the packet is still going out
> your default interface.
> 
> > 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.
> 
> On Linux, you can try binding the socket to an interface [1]. klaar added
> support to do this for his quite interesting dhcp server, edhcpd [2].
> 
> [1] https://github.com/msantos/procket
> [2] https://github.com/klaar/edhcpd
> 
> 
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list