2017-10-07 00:16:47 +00:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
2012-03-27 23:13:14 +00:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2018-12-28 15:30:48 +00:00
|
|
|
"runtime"
|
2012-03-27 23:13:14 +00:00
|
|
|
"syscall"
|
2014-09-21 17:33:12 +00:00
|
|
|
"unsafe"
|
2012-03-27 23:13:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func setIPv4MulticastInterface(fd *netFD, ifi *Interface) error {
|
|
|
|
ip, err := interfaceToIPv4Addr(ifi)
|
|
|
|
if err != nil {
|
|
|
|
return os.NewSyscallError("setsockopt", err)
|
|
|
|
}
|
2014-09-21 17:33:12 +00:00
|
|
|
var a [4]byte
|
|
|
|
copy(a[:], ip.To4())
|
2018-12-28 15:30:48 +00:00
|
|
|
err = fd.pfd.Setsockopt(syscall.IPPROTO_IP, syscall.IP_MULTICAST_IF, (*byte)(unsafe.Pointer(&a[0])), 4)
|
|
|
|
runtime.KeepAlive(fd)
|
|
|
|
return wrapSyscallError("setsockopt", err)
|
2012-03-27 23:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func setIPv4MulticastLoopback(fd *netFD, v bool) error {
|
2018-12-28 15:30:48 +00:00
|
|
|
err := fd.pfd.SetsockoptInt(syscall.IPPROTO_IP, syscall.IP_MULTICAST_LOOP, boolint(v))
|
|
|
|
runtime.KeepAlive(fd)
|
|
|
|
return wrapSyscallError("setsockopt", err)
|
2012-03-27 23:13:14 +00:00
|
|
|
}
|