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
16 func setDefaultSockopts(s
, f
, t
int, ipv6only
bool) error
{
18 case syscall
.AF_INET6
:
20 syscall
.SetsockoptInt(s
, syscall
.IPPROTO_IPV6
, syscall
.IPV6_V6ONLY
, 1)
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)
29 err
:= syscall
.SetsockoptInt(s
, syscall
.SOL_SOCKET
, syscall
.SO_BROADCAST
, 1)
31 return os
.NewSyscallError("setsockopt", err
)
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)
40 return os
.NewSyscallError("setsockopt", err
)
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)
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)
59 return os
.NewSyscallError("setsockopt", err
)