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 // Socket options for Linux
14 func setDefaultSockopts(s
, f
, t
int, ipv6only
bool) error
{
16 case syscall
.AF_INET6
:
18 syscall
.SetsockoptInt(s
, syscall
.IPPROTO_IPV6
, syscall
.IPV6_V6ONLY
, 1)
20 // Allow both IP versions even if the OS default
21 // is otherwise. Note that some operating systems
22 // never admit this option.
23 syscall
.SetsockoptInt(s
, syscall
.IPPROTO_IPV6
, syscall
.IPV6_V6ONLY
, 0)
27 err
:= syscall
.SetsockoptInt(s
, syscall
.SOL_SOCKET
, syscall
.SO_BROADCAST
, 1)
29 return os
.NewSyscallError("setsockopt", err
)
34 func setDefaultListenerSockopts(s
int) error
{
35 // Allow reuse of recently-used addresses.
36 err
:= syscall
.SetsockoptInt(s
, syscall
.SOL_SOCKET
, syscall
.SO_REUSEADDR
, 1)
38 return os
.NewSyscallError("setsockopt", err
)
43 func setDefaultMulticastSockopts(s
int) error
{
44 // Allow multicast UDP and raw IP datagram sockets to listen
45 // concurrently across multiple listeners.
46 err
:= syscall
.SetsockoptInt(s
, syscall
.SOL_SOCKET
, syscall
.SO_REUSEADDR
, 1)
48 return os
.NewSyscallError("setsockopt", err
)