* gcc.dg/guality/guality.exp: Skip on AIX.
[official-gcc.git] / libgo / go / net / sockopt_bsd.go
blobaf88814b4b9ed918b66041f13e1aa2c5ace68864
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 // Socket options for BSD variants
9 package net
11 import (
12 "os"
13 "syscall"
16 func setDefaultSockopts(s, f, t int, ipv6only bool) error {
17 switch f {
18 case syscall.AF_INET6:
19 if ipv6only {
20 syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 1)
21 } else {
22 // Allow both IP versions even if the OS default
23 // is otherwise. Note that some operating systems
24 // never admit this option.
25 syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 0)
28 // Allow broadcast.
29 err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1)
30 if err != nil {
31 return os.NewSyscallError("setsockopt", err)
33 return nil
36 func setDefaultListenerSockopts(s int) error {
37 // Allow reuse of recently-used addresses.
38 err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
39 if err != nil {
40 return os.NewSyscallError("setsockopt", err)
42 return nil
45 func setDefaultMulticastSockopts(s int) error {
46 // Allow multicast UDP and raw IP datagram sockets to listen
47 // concurrently across multiple listeners.
48 err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
49 if err != nil {
50 return os.NewSyscallError("setsockopt", err)
52 // Allow reuse of recently-used ports.
53 // This option is supported only in descendants of 4.4BSD,
54 // to make an effective multicast application that requires
55 // quick draw possible.
56 if syscall.SO_REUSEPORT != 0 {
57 err = syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1)
58 if err != nil {
59 return os.NewSyscallError("setsockopt", err)
62 return nil