]> Cypherpunks repositories - gostls13.git/commit
net: add IPv4 multicast to UDPConn
authorDave Cheney <dave@cheney.net>
Wed, 16 Feb 2011 20:07:13 +0000 (15:07 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 16 Feb 2011 20:07:13 +0000 (15:07 -0500)
commit0856731daad6026fed5118d15efc86daba65782c
tree8f2947688fa6ac5b121a17a2eeacbd801348fae8
parent9b66129fe38e467c5c25eed4ab271ca88c3f8840
net: add IPv4 multicast to UDPConn

notes:
Darwin is very particular about joining a multicast group if the
listneing socket is not created in "udp4" mode, the other supported
OS's are more flexible.

A simple example sets up a socket to listen on the mdns/bonjour
group 224.0.0.251:5353

// ensure the sock is udp4, and the IP is a 4 byte IPv4
socket, err := net.ListenUDP("udp4", &net.UDPAddr {
        IP: net.IPv4zero,
        // currently darwin will not allow you to bind to
        // a port if it is already bound to another process
        Port: 5353,
})
if err != nil {
        log.Exitf("listen %s", err)
}
defer socket.Close()
err = socket.JoinGroup(net.IPv4(224, 0, 0, 251))
if err != nil {
        log.Exitf("join group %s", err)
}

R=adg, rsc
CC=golang-dev
https://golang.org/cl/4066044
src/pkg/net/multicast_test.go [new file with mode: 0644]
src/pkg/net/udpsock.go