[erlang-questions] Broadcast UDP message

Richard Andrews bflatmaj7th@REDACTED
Thu Jun 11 00:47:28 CEST 2009


On Thu, Jun 11, 2009 at 12:53 AM, Lucas
Robsahm<lucas.robsahm@REDACTED> wrote:
> Hi!
>
> I'm trying to send a broadcast message to 255.255.255.255 but I can't
> get it to work.
> My IP-Address is 192.168.1.1 and it's ok to send UDP message to
> 192.168.1.255 but I need to send it to 255.255.255.255.
>
> {ok, Socket} = gen_udp:open(0, [binary, {broadcast, true}]),
> ok = gen_udp:send(Socket, {255, 255, 255, 255}, 68, Message).
>
> The result of this is badmatch, {error, enetunreach}.
>
> What's wrong?
> How can i broadcast UDP messages?

Works for me.

$ erl
Erlang (BEAM) emulator version 5.6.4 [source] [smp:2]
[async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.6.4  (abort with ^G)
1> {ok, S} = gen_udp:open( 0, [binary, {broadcast, true}]).
{ok,#Port<0.94>}
2> gen_udp:send( S, {255,255,255,255}, 9998, <<"UDP broadcast test
message.">> ).
ok

08:36:30.626792 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto
UDP (17), length 55) 192.168.0.126.58794 > 255.255.255.255.9998: [bad
udp cksum bd48!] UDP, length 27


Running on Ubuntu 8.04 x86_32.

Can you do the same test in C? Netcat can also test it:

$ echo "UDP bcast test2 from nc" | nc -u -b 255.255.255.255 9998

08:43:08.971801 IP (tos 0x0, ttl 64, id 56364, offset 0, flags [DF],
proto UDP (17), length 52) 192.168.0.126.33921 > 255.255.255.255.9998:
[bad udp cksum f280!] UDP, length 24

The enetunreach error is likely returned from the kernel. strace will
show if that is the case.You may be missing some permissions. Try
running the same simple test as superuser.

--
  Rich


More information about the erlang-questions mailing list