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())
|
2012-03-02 17:38:43 +01:00
|
|
|
if err := fd.incref(false); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2012-02-09 09:19:58 +01:00
|
|
|
defer fd.decref()
|
2012-10-23 06:31:11 +02:00
|
|
|
err = syscall.Setsockopt(fd.sysfd, int32(syscall.IPPROTO_IP), int32(syscall.IP_MULTICAST_IF), (*byte)(unsafe.Pointer(&a[0])), 4)
|
2012-02-09 09:19:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return os.NewSyscallError("setsockopt", err)
|
|
|
|
}
|
|
|
|
return nil
|
2012-01-25 21:56:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func setIPv4MulticastLoopback(fd *netFD, v bool) error {
|
2012-03-02 17:38:43 +01:00
|
|
|
if err := fd.incref(false); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2012-02-09 09:19:58 +01:00
|
|
|
defer fd.decref()
|
2012-10-23 06:31:11 +02:00
|
|
|
vv := int32(boolint(v))
|
|
|
|
err := syscall.Setsockopt(fd.sysfd, int32(syscall.IPPROTO_IP), int32(syscall.IP_MULTICAST_LOOP), (*byte)(unsafe.Pointer(&vv)), 4)
|
2012-02-09 09:19:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return os.NewSyscallError("setsockopt", err)
|
|
|
|
}
|
|
|
|
return nil
|
2012-01-25 21:56:26 +01:00
|
|
|
}
|