github.com/tcnksm/go@v0.0.0-20141208075154-439b32936367/src/net/sockoptip_bsd.go (about)

     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  // +build darwin dragonfly freebsd netbsd openbsd
     6  
     7  package net
     8  
     9  import (
    10  	"os"
    11  	"syscall"
    12  )
    13  
    14  func setIPv4MulticastInterface(fd *netFD, ifi *Interface) error {
    15  	ip, err := interfaceToIPv4Addr(ifi)
    16  	if err != nil {
    17  		return os.NewSyscallError("setsockopt", err)
    18  	}
    19  	var a [4]byte
    20  	copy(a[:], ip.To4())
    21  	if err := fd.incref(); err != nil {
    22  		return err
    23  	}
    24  	defer fd.decref()
    25  	return os.NewSyscallError("setsockopt", syscall.SetsockoptInet4Addr(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_MULTICAST_IF, a))
    26  }
    27  
    28  func setIPv4MulticastLoopback(fd *netFD, v bool) error {
    29  	if err := fd.incref(); err != nil {
    30  		return err
    31  	}
    32  	defer fd.decref()
    33  	return os.NewSyscallError("setsockopt", syscall.SetsockoptByte(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_MULTICAST_LOOP, byte(boolint(v))))
    34  }