...

Source file src/net/sockoptip_posix.go

Documentation: net

		 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 aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || windows
		 6  // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows
		 7  
		 8  package net
		 9  
		10  import (
		11  	"runtime"
		12  	"syscall"
		13  )
		14  
		15  func joinIPv4Group(fd *netFD, ifi *Interface, ip IP) error {
		16  	mreq := &syscall.IPMreq{Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]}}
		17  	if err := setIPv4MreqToInterface(mreq, ifi); err != nil {
		18  		return err
		19  	}
		20  	err := fd.pfd.SetsockoptIPMreq(syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq)
		21  	runtime.KeepAlive(fd)
		22  	return wrapSyscallError("setsockopt", err)
		23  }
		24  
		25  func setIPv6MulticastInterface(fd *netFD, ifi *Interface) error {
		26  	var v int
		27  	if ifi != nil {
		28  		v = ifi.Index
		29  	}
		30  	err := fd.pfd.SetsockoptInt(syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_IF, v)
		31  	runtime.KeepAlive(fd)
		32  	return wrapSyscallError("setsockopt", err)
		33  }
		34  
		35  func setIPv6MulticastLoopback(fd *netFD, v bool) error {
		36  	err := fd.pfd.SetsockoptInt(syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_LOOP, boolint(v))
		37  	runtime.KeepAlive(fd)
		38  	return wrapSyscallError("setsockopt", err)
		39  }
		40  
		41  func joinIPv6Group(fd *netFD, ifi *Interface, ip IP) error {
		42  	mreq := &syscall.IPv6Mreq{}
		43  	copy(mreq.Multiaddr[:], ip)
		44  	if ifi != nil {
		45  		mreq.Interface = uint32(ifi.Index)
		46  	}
		47  	err := fd.pfd.SetsockoptIPv6Mreq(syscall.IPPROTO_IPV6, syscall.IPV6_JOIN_GROUP, mreq)
		48  	runtime.KeepAlive(fd)
		49  	return wrapSyscallError("setsockopt", err)
		50  }
		51  

View as plain text