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