OSDN Git Service

libgo: Update to weekly.2012-01-15.
[pf3gnuchains/gcc-fork.git] / libgo / go / net / sockopt_linux.go
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.
4
5 // Socket options for Linux
6
7 package net
8
9 import (
10         "syscall"
11 )
12
13 func setDefaultSockopts(s, f, p int) {
14         switch f {
15         case syscall.AF_INET6:
16                 // Allow both IP versions even if the OS default is otherwise.
17                 syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 0)
18         }
19
20         if f == syscall.AF_UNIX || p == syscall.IPPROTO_TCP {
21                 // Allow reuse of recently-used addresses.
22                 syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
23         }
24
25         // Allow broadcast.
26         syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1)
27
28 }
29
30 func setDefaultMulticastSockopts(fd *netFD) {
31         fd.incref()
32         defer fd.decref()
33         // Allow multicast UDP and raw IP datagram sockets to listen
34         // concurrently across multiple listeners.
35         syscall.SetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
36 }