1
0
mirror of https://github.com/golang/go synced 2024-11-22 04:04:40 -07:00

net: Listen on specified multicast address

Fixes #34728
This commit is contained in:
Daniel Kucera 2021-08-18 07:56:39 +02:00 committed by GitHub
parent 946e2543f8
commit 0226690a9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -208,25 +208,10 @@ func (fd *netFD) listenStream(laddr sockaddr, backlog int, ctrlFn func(string, s
func (fd *netFD) listenDatagram(laddr sockaddr, ctrlFn func(string, string, syscall.RawConn) error) error {
switch addr := laddr.(type) {
case *UDPAddr:
// We provide a socket that listens to a wildcard
// address with reusable UDP port when the given laddr
// is an appropriate UDP multicast address prefix.
// This makes it possible for a single UDP listener to
// join multiple different group addresses, for
// multiple UDP listeners that listen on the same UDP
// port to join the same group address.
if addr.IP != nil && addr.IP.IsMulticast() {
if err := setDefaultMulticastSockopts(fd.pfd.Sysfd); err != nil {
return err
}
addr := *addr
switch fd.family {
case syscall.AF_INET:
addr.IP = IPv4zero
case syscall.AF_INET6:
addr.IP = IPv6unspecified
}
laddr = &addr
}
}
var err error