2012-10-23 06:31:11 +02: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.
|
|
|
|
|
2013-11-06 20:49:01 +01:00
|
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd windows
|
2012-10-23 06:31:11 +02:00
|
|
|
|
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
func joinIPv4Group(fd *netFD, ifi *Interface, ip IP) error {
|
|
|
|
mreq := &syscall.IPMreq{Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]}}
|
|
|
|
if err := setIPv4MreqToInterface(mreq, ifi); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2013-11-06 20:49:01 +01:00
|
|
|
if err := fd.incref(); err != nil {
|
2012-10-23 06:31:11 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer fd.decref()
|
2013-11-06 20:49:01 +01:00
|
|
|
return os.NewSyscallError("setsockopt", syscall.SetsockoptIPMreq(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq))
|
2012-10-23 06:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func setIPv6MulticastInterface(fd *netFD, ifi *Interface) error {
|
|
|
|
var v int
|
|
|
|
if ifi != nil {
|
|
|
|
v = ifi.Index
|
|
|
|
}
|
2013-11-06 20:49:01 +01:00
|
|
|
if err := fd.incref(); err != nil {
|
2012-10-23 06:31:11 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer fd.decref()
|
2013-11-06 20:49:01 +01:00
|
|
|
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_IF, v))
|
2012-10-23 06:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func setIPv6MulticastLoopback(fd *netFD, v bool) error {
|
2013-11-06 20:49:01 +01:00
|
|
|
if err := fd.incref(); err != nil {
|
2012-10-23 06:31:11 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer fd.decref()
|
2013-11-06 20:49:01 +01:00
|
|
|
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_LOOP, boolint(v)))
|
2012-10-23 06:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func joinIPv6Group(fd *netFD, ifi *Interface, ip IP) error {
|
|
|
|
mreq := &syscall.IPv6Mreq{}
|
|
|
|
copy(mreq.Multiaddr[:], ip)
|
|
|
|
if ifi != nil {
|
|
|
|
mreq.Interface = uint32(ifi.Index)
|
|
|
|
}
|
2013-11-06 20:49:01 +01:00
|
|
|
if err := fd.incref(); err != nil {
|
2012-10-23 06:31:11 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer fd.decref()
|
2013-11-06 20:49:01 +01:00
|
|
|
return os.NewSyscallError("setsockopt", syscall.SetsockoptIPv6Mreq(fd.sysfd, syscall.IPPROTO_IPV6, syscall.IPV6_JOIN_GROUP, mreq))
|
2012-10-23 06:31:11 +02:00
|
|
|
}
|