I want to have a server sending broadcast UDP packets and two other clients, in the same machine, receiving them. Can I do that somehow? What IP address would I use?

@gravyface gave me hope but I tried:

  1. Server sending to and clients listening to
  2. Server sending to and clients listening to
  3. server sending to and clients listening to

None of them worked! :(

OBS: I am using REUSE_ADDR and SO_BROADCAST options.


First window:

socat -u udp-recv:12345,reuseaddr -

Second window:

socat -u udp-recv:12345,reuseaddr -

Third window

socat - udp-sendto:,broadcast

Then enter a few lines of text in the 3rd window and see if you're getting anything in the two other ones.

Replace "socat" with "strace -fe network socat" to see what system calls are actually being made (assuming you're on Linux, other unices have equivalents sometimes called tusc, struss or dtruss). socat is opensource and binary packages are available for most operating systems.

setsockopt(3, SOL_SOCKET, SO_BROADCAST, [1], 4) = 0
sendto(3, "qwe\n", 4, 0, {sa_family=AF_INET, sin_port=htons(12345), sin_addr=inet_addr("")}, 16) = 4

Above, the receiving "clients" bind to the INADDR_ANY address. What I found and am not sure why, is that if you bind to an address on the loopback subnet, you're not seeing the packets coming in.

See also:

$ ip route show table local dev lo scope link
broadcast  proto kernel  src
broadcast  proto kernel  src

If the clients bind to or and the server sends to that same address (with SO_BROADCAST), then it works as well.

  • Hey sch, thanks for the info, but my problem is that my loopback does NOT have the broadcast flag turned on (lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384_. Is there a way to fix that? – chrisapotek Aug 26 '12 at 17:24
  • Neither does mine, but I'm still able to have one process talk to many. See also my recent edit. – sch Aug 26 '12 at 17:37
  • I don't see those addresses when I run the ip command. :( I need to set them up somehow. Not sure how => serverfault.com/questions/421389/… – chrisapotek Aug 26 '12 at 17:47

Sending broadcast traffic to should work, but obviously test it out (and Wireshark/tcpdump is your friend here).

Obviously your clients need to be listening on the loopback device too.

  • It did NOT work. :( :( :( See my edit in the question. – chrisapotek Aug 26 '12 at 16:55
  • 1
    What OS are you running? You might confirm that you have a broadcast address for the loop back set, there are cases when lo is brought up with no broadcast set. – Univ426 Aug 26 '12 at 17:12
  • You are very right. I am using OS/X and lo0 has no broadcast flag => lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384. Is there a fix for that? – chrisapotek Aug 26 '12 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.