Source file src/net/sockoptip4_linux.go

     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  package net
     6  
     7  import (
     8  	"runtime"
     9  	"syscall"
    10  )
    11  
    12  func joinIPv4Group(fd *netFD, ifi *Interface, ip IP) error {
    13  	mreq := &syscall.IPMreqn{Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]}}
    14  	if ifi != nil {
    15  		mreq.Ifindex = int32(ifi.Index)
    16  	}
    17  	err := fd.pfd.SetsockoptIPMreqn(syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq)
    18  	runtime.KeepAlive(fd)
    19  	return wrapSyscallError("setsockopt", err)
    20  }
    21  
    22  func setIPv4MulticastInterface(fd *netFD, ifi *Interface) error {
    23  	var v int32
    24  	if ifi != nil {
    25  		v = int32(ifi.Index)
    26  	}
    27  	mreq := &syscall.IPMreqn{Ifindex: v}
    28  	err := fd.pfd.SetsockoptIPMreqn(syscall.IPPROTO_IP, syscall.IP_MULTICAST_IF, mreq)
    29  	runtime.KeepAlive(fd)
    30  	return wrapSyscallError("setsockopt", err)
    31  }
    32  
    33  func setIPv4MulticastLoopback(fd *netFD, v bool) error {
    34  	err := fd.pfd.SetsockoptInt(syscall.IPPROTO_IP, syscall.IP_MULTICAST_LOOP, boolint(v))
    35  	runtime.KeepAlive(fd)
    36  	return wrapSyscallError("setsockopt", err)
    37  }
    38  

View as plain text