Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 127.255.255.255:54321 and clients listening to 0.0.0.0:54321.
  2. Server sending to 127.255.255.255:54321 and clients listening to 127.0.0.1:54321.
  3. server sending to 127.255.255.255:54321 and clients listening to 127.255.255.255:54321.

None of them worked! :(

OBS: I am using REUSE_ADDR and SO_BROADCAST options.

share|improve this question

2 Answers 2

First window:

socat -u udp-recv:12345,reuseaddr -

Second window:

socat -u udp-recv:12345,reuseaddr -

Third window

socat - tcp-sendto:127.255.255.255:12345,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.

socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) = 3
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("127.255.255.255")}, 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 127.0.0.0  proto kernel  src 127.0.0.1
broadcast 127.255.255.255  proto kernel  src 127.0.0.1

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

share|improve this answer
    
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 127.255.255.255 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.

share|improve this answer
    
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. –  John K 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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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