[erlang-questions] gen_udp and Wake On Lan (wol)

Matthias Lang <>
Mon Jun 9 17:59:13 CEST 2008


Andrey Shnayder writes:

 > code below:
 > > {ok,S} = gen_udp:open(2025).
 > {ok,#Port<0.275>}
 > > gen_udp:send(S, Pack).
 > {error,einval}
 > > gen_udp:close(S).
 > 
 > Pack is the magic packet.
 > i.e. I have an error in gen_udp:send(S, Pack). Please, help me.

Why are you calling send with two arguments? The documented interface
has four:

  http://erlang.org/doc/man/gen_udp.html

1> {ok,S} = gen_udp:open(2025).
{ok,#Port<0.106>}
2> gen_udp:send(S, {172,16,2,1}, 1234, <<"not a magic wake on LAN packet">>).
ok

This at least sends a packet, but it still isn't what you want---you
almost certainly want to broadcast that packet, so maybe something
along the lines of

8> {ok,S} = gen_udp:open(0, [{broadcast, true}]).   
{ok,#Port<0.114>}
9>  gen_udp:send(S, {172,16,255,255}, 9, <<"not a magic wake on LAN packet">>).

would be more like it, though I don't know enough about wake-on-lan to
be sure that this fulfils all the requirements.

Matt



More information about the erlang-questions mailing list