ListenMulticastUDP doesn't work with 255.255.255.255

Trying to write some code that listens for UDP broadcasts sent to 255.255.255.255.

I can get equivalent code to work in C, but it fails in Go.

lAddr, err := net.ResolveUDPAddr("udp", "255.255.255.255:48899")
if err != nil {
    log.Fatal(err)
}

_, err = net.ListenMulticastUDP("udp", nil, lAddr)
if err != nil {
    log.Fatal(err)
}

Fails with:
2018/11/14 11:53:28 listen udp 255.255.255.255:48899: bind: cannot assign requested address

Because it seems as if 255.255.255.255 is not a multicast address for go: https://play.golang.org/p/l0I-Gbd_edx

Also Wikipedia does not list it as multicast: https://en.wikipedia.org/wiki/Multicast_address

Perhaps try to simply listen on that IP in the zero-network?

1 Like

Yep, this is user error.

255.255.255.255 is a broadcast address and not a multi-cast address. Broadcast != multicast :blush:

Appears as if broadcast packets are delivered to any socket that is bound to that port.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.