2012-01-25 21:56:26 +01:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
2012-02-09 09:19:58 +01:00
|
|
|
"os"
|
2012-01-25 21:56:26 +01:00
|
|
|
"syscall"
|
2012-10-23 06:31:11 +02:00
|
|
|
"unsafe"
|
2012-01-25 21:56:26 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func setIPv4MulticastInterface(fd *netFD, ifi *Interface) error {
|
2012-02-09 09:19:58 +01:00
|
|
|
ip, err := interfaceToIPv4Addr(ifi)
|
|
|
|
if err != nil {
|
|
|
|
return os.NewSyscallError("setsockopt", err)
|
|
|
|
}
|
2012-10-23 06:31:11 +02:00
|
|
|
var a [4]byte
|
|
|
|
copy(a[:], ip.To4())
|
2013-11-06 20:49:01 +01:00
|
|
|
if err := fd.incref(); err != nil {
|
2012-03-02 17:38:43 +01:00
|
|
|
return err
|
|
|
|
}
|
2012-02-09 09:19:58 +01:00
|
|
|
defer fd.decref()
|
2013-11-06 20:49:01 +01:00
|
|
|
return os.NewSyscallError("setsockopt", syscall.Setsockopt(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_MULTICAST_IF, (*byte)(unsafe.Pointer(&a[0])), 4))
|
2012-01-25 21:56:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func setIPv4MulticastLoopback(fd *netFD, v bool) error {
|
2013-11-06 20:49:01 +01:00
|
|
|
if err := fd.incref(); err != nil {
|
2012-03-02 17:38:43 +01:00
|
|
|
return err
|
|
|
|
}
|
2012-02-09 09:19:58 +01:00
|
|
|
defer fd.decref()
|
2013-11-06 20:49:01 +01:00
|
|
|
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_MULTICAST_LOOP, boolint(v)))
|
2012-01-25 21:56:26 +01:00
|
|
|
}
|