Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: ListenMulticastUDP doesn't set {IP,IPV6}_MULTICAST_LOOP #10742

Closed
rosscanning opened this issue May 7, 2015 · 2 comments
Closed

net: ListenMulticastUDP doesn't set {IP,IPV6}_MULTICAST_LOOP #10742

rosscanning opened this issue May 7, 2015 · 2 comments

Comments

@rosscanning
Copy link

The following program creates a unicast UDP4 socket for sending, a multicast UDP4 socket for receiving, and sends one packet of data from the former to the latter. It should succeed (and does on Linux), but on Windows (Windows 7, 64-bit, go v1.4.2), it hangs on the ReadFrom() call.

Note: If you go to udpsock_posix.go in the std library, and in listenIPv4MulticastUDP(), change:
if err := setIPv4MulticastLoopback(c.fd, false); ...
to:
if err := setIPv4MulticastLoopback(c.fd, true); ...
the program works as expected, so it seems like the loopback flag should be set on Windows (maybe in setDefaultMulticastSockopts), or at least the loopback flag should be exposed through the API.

package main
import "net"
func main() {
    src, err := net.Dial("udp4", "238.98.76.54:4378")
    if err != nil {
        panic("test failed")
    }
    defer src.Close()
    addr := net.ParseIP("238.98.76.54")
    dest, err := net.ListenMulticastUDP("udp4", nil, &net.UDPAddr{IP: addr, Port: 4378})
    if err != nil {
        panic("test failed")
    }
    defer dest.Close()
    if _, err := src.Write(make([]byte, 100)); err != nil {
        panic("test failed")
    }
    b := make([]byte, 1024)
    n, _, err := dest.ReadFrom(b)
    if err != nil || n != 100 {
        panic("test failed")
    }
}
@mikioh mikioh changed the title Loopback flag not set on IP4 multicast socket on Windows net: ListenMulticastUDP does't set {IP,IPV6}_MULTICAST_LOOP May 7, 2015
@mikioh
Copy link
Contributor

mikioh commented May 7, 2015

Because ListenMulticastUDP is just for convenience of simple small applications. There are a few packages for general purpose uses, golang.org/x/net/ipv4 and golang.org/x/net/ipv6.

@mikioh mikioh closed this as completed May 7, 2015
@mikioh mikioh changed the title net: ListenMulticastUDP does't set {IP,IPV6}_MULTICAST_LOOP net: ListenMulticastUDP doesn't set {IP,IPV6}_MULTICAST_LOOP May 7, 2015
@rosscanning
Copy link
Author

Thanks Mikio. "net/ipv4" works correctly.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants