Source file
src/net/sockopt_bsd.go
1
2
3
4
5
6
7 package net
8
9 import (
10 "os"
11 "runtime"
12 "syscall"
13 )
14
15 func setDefaultSockopts(s, family, sotype int, ipv6only bool) error {
16 if runtime.GOOS == "dragonfly" && sotype != syscall.SOCK_RAW {
17
18
19
20
21 switch family {
22 case syscall.AF_INET:
23 syscall.SetsockoptInt(s, syscall.IPPROTO_IP, syscall.IP_PORTRANGE, syscall.IP_PORTRANGE_HIGH)
24 case syscall.AF_INET6:
25 syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_PORTRANGE, syscall.IPV6_PORTRANGE_HIGH)
26 }
27 }
28 if family == syscall.AF_INET6 && sotype != syscall.SOCK_RAW && supportsIPv4map() {
29
30
31
32 syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, boolint(ipv6only))
33 }
34 if (sotype == syscall.SOCK_DGRAM || sotype == syscall.SOCK_RAW) && family != syscall.AF_UNIX {
35
36 return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1))
37 }
38 return nil
39 }
40
41 func setDefaultListenerSockopts(s int) error {
42
43 return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1))
44 }
45
46 func setDefaultMulticastSockopts(s int) error {
47
48
49 if err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
50 return os.NewSyscallError("setsockopt", err)
51 }
52
53
54
55
56 return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1))
57 }
58
View as plain text