sockoptip6_posix.mx raw

   1  // Copyright 2011 The Go Authors. All rights reserved.
   2  // Use of this source code is governed by a BSD-style
   3  // license that can be found in the LICENSE file.
   4  
   5  //go:build unix || windows
   6  
   7  package net
   8  
   9  import (
  10  	"runtime"
  11  	"syscall"
  12  )
  13  
  14  func setIPv6MulticastInterface(fd *netFD, ifi *Interface) error {
  15  	var v int
  16  	if ifi != nil {
  17  		v = ifi.Index
  18  	}
  19  	err := fd.pfd.SetsockoptInt(syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_IF, v)
  20  	runtime.KeepAlive(fd)
  21  	return wrapSyscallError("setsockopt", err)
  22  }
  23  
  24  func setIPv6MulticastLoopback(fd *netFD, v bool) error {
  25  	err := fd.pfd.SetsockoptInt(syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_LOOP, boolint(v))
  26  	runtime.KeepAlive(fd)
  27  	return wrapSyscallError("setsockopt", err)
  28  }
  29  
  30  func joinIPv6Group(fd *netFD, ifi *Interface, ip IP) error {
  31  	mreq := &syscall.IPv6Mreq{}
  32  	copy(mreq.Multiaddr[:], ip)
  33  	if ifi != nil {
  34  		mreq.Interface = uint32(ifi.Index)
  35  	}
  36  	err := fd.pfd.SetsockoptIPv6Mreq(syscall.IPPROTO_IPV6, syscall.IPV6_JOIN_GROUP, mreq)
  37  	runtime.KeepAlive(fd)
  38  	return wrapSyscallError("setsockopt", err)
  39  }
  40