2013-02-11 Sebastian Huber <sebastian.huber@embedded-brains.de>
[official-gcc.git] / libgo / go / net / sockoptip_bsd.go
blob263f8552176d6f895143ff6f9ab2070ddbb998bf
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.
5 // +build darwin freebsd netbsd openbsd
7 package net
9 import (
10 "os"
11 "syscall"
14 func setIPv4MulticastInterface(fd *netFD, ifi *Interface) error {
15 ip, err := interfaceToIPv4Addr(ifi)
16 if err != nil {
17 return os.NewSyscallError("setsockopt", err)
19 var a [4]byte
20 copy(a[:], ip.To4())
21 if err := fd.incref(false); err != nil {
22 return err
24 defer fd.decref()
25 err = syscall.SetsockoptInet4Addr(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_MULTICAST_IF, a)
26 if err != nil {
27 return os.NewSyscallError("setsockopt", err)
29 return nil
32 func setIPv4MulticastLoopback(fd *netFD, v bool) error {
33 if err := fd.incref(false); err != nil {
34 return err
36 defer fd.decref()
37 err := syscall.SetsockoptByte(fd.sysfd, syscall.IPPROTO_IP, syscall.IP_MULTICAST_LOOP, byte(boolint(v)))
38 if err != nil {
39 return os.NewSyscallError("setsockopt", err)
41 return nil