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 Windows
14 func setDefaultSockopts(s syscall.Handle, f, t int) error {
16 case syscall.AF_INET6:
17 // Allow both IP versions even if the OS default is otherwise.
18 // Note that some operating systems never admit this option.
19 syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 0)
22 syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1)
26 func setDefaultListenerSockopts(s syscall.Handle) error {
27 // Windows will reuse recently-used addresses by default.
28 // SO_REUSEADDR should not be used here, as it allows
29 // a socket to forcibly bind to a port in use by another socket.
30 // This could lead to a non-deterministic behavior, where
31 // connection requests over the port cannot be guaranteed
32 // to be handled by the correct socket.
36 func setDefaultMulticastSockopts(s syscall.Handle) error {
37 // Allow multicast UDP and raw IP datagram sockets to listen
38 // concurrently across multiple listeners.
39 err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
41 return os.NewSyscallError("setsockopt", err)