libgo: update to go1.9
[official-gcc.git] / libgo / go / net / sockoptip_posix.go
blob92af7646ef984811bba8e2b7fbbea2a249936e7b
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 aix darwin dragonfly freebsd linux netbsd openbsd windows
7 package net
9 import (
10 "runtime"
11 "syscall"
14 func joinIPv4Group(fd *netFD, ifi *Interface, ip IP) error {
15 mreq := &syscall.IPMreq{Multiaddr: [4]byte{ip[0], ip[1], ip[2], ip[3]}}
16 if err := setIPv4MreqToInterface(mreq, ifi); err != nil {
17 return err
19 err := fd.pfd.SetsockoptIPMreq(syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq)
20 runtime.KeepAlive(fd)
21 return wrapSyscallError("setsockopt", err)
24 func setIPv6MulticastInterface(fd *netFD, ifi *Interface) error {
25 var v int
26 if ifi != nil {
27 v = ifi.Index
29 err := fd.pfd.SetsockoptInt(syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_IF, v)
30 runtime.KeepAlive(fd)
31 return wrapSyscallError("setsockopt", err)
34 func setIPv6MulticastLoopback(fd *netFD, v bool) error {
35 err := fd.pfd.SetsockoptInt(syscall.IPPROTO_IPV6, syscall.IPV6_MULTICAST_LOOP, boolint(v))
36 runtime.KeepAlive(fd)
37 return wrapSyscallError("setsockopt", err)
40 func joinIPv6Group(fd *netFD, ifi *Interface, ip IP) error {
41 mreq := &syscall.IPv6Mreq{}
42 copy(mreq.Multiaddr[:], ip)
43 if ifi != nil {
44 mreq.Interface = uint32(ifi.Index)
46 err := fd.pfd.SetsockoptIPv6Mreq(syscall.IPPROTO_IPV6, syscall.IPV6_JOIN_GROUP, mreq)
47 runtime.KeepAlive(fd)
48 return wrapSyscallError("setsockopt", err)