OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [net/] [sockopt_bsd.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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
// +build darwin freebsd netbsd openbsd
6
 
7
// Socket options for BSD variants
8
 
9
package net
10
 
11
import (
12
        "os"
13
        "syscall"
14
)
15
 
16
func setDefaultSockopts(s, f, t int) error {
17
        switch f {
18
        case syscall.AF_INET6:
19
                // Allow both IP versions even if the OS default is otherwise.
20
                // Note that some operating systems never admit this option.
21
                syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 0)
22
        }
23
 
24
        if f == syscall.AF_UNIX ||
25
                (f == syscall.AF_INET || f == syscall.AF_INET6) && t == syscall.SOCK_STREAM {
26
                // Allow reuse of recently-used addresses.
27
                err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
28
                if err != nil {
29
                        return os.NewSyscallError("setsockopt", err)
30
                }
31
 
32
                // Allow reuse of recently-used ports.
33
                // This option is supported only in descendants of 4.4BSD,
34
                // to make an effective multicast application and an application
35
                // that requires quick draw possible.
36
                err = syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1)
37
                if err != nil {
38
                        return os.NewSyscallError("setsockopt", err)
39
                }
40
        }
41
 
42
        // Allow broadcast.
43
        err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1)
44
        if err != nil {
45
                return os.NewSyscallError("setsockopt", err)
46
        }
47
 
48
        return nil
49
}
50
 
51
func setDefaultMulticastSockopts(s int) error {
52
        // Allow multicast UDP and raw IP datagram sockets to listen
53
        // concurrently across multiple listeners.
54
        err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
55
        if err != nil {
56
                return os.NewSyscallError("setsockopt", err)
57
        }
58
        err = syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1)
59
        if err != nil {
60
                return os.NewSyscallError("setsockopt", err)
61
        }
62
        return nil
63
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.