package net
import (
"os"
"runtime"
"syscall"
)
func setDefaultSockopts (s , family , sotype int , ipv6only bool ) error {
if runtime .GOOS == "dragonfly" && sotype != syscall .SOCK_RAW {
switch family {
case syscall .AF_INET :
syscall .SetsockoptInt (s , syscall .IPPROTO_IP , syscall .IP_PORTRANGE , syscall .IP_PORTRANGE_HIGH )
case syscall .AF_INET6 :
syscall .SetsockoptInt (s , syscall .IPPROTO_IPV6 , syscall .IPV6_PORTRANGE , syscall .IPV6_PORTRANGE_HIGH )
}
}
if supportsIPv4map () && family == syscall .AF_INET6 && sotype != syscall .SOCK_RAW {
syscall .SetsockoptInt (s , syscall .IPPROTO_IPV6 , syscall .IPV6_V6ONLY , boolint (ipv6only ))
}
if (sotype == syscall .SOCK_DGRAM || sotype == syscall .SOCK_RAW ) && family != syscall .AF_UNIX {
return os .NewSyscallError ("setsockopt" , syscall .SetsockoptInt (s , syscall .SOL_SOCKET , syscall .SO_BROADCAST , 1 ))
}
return nil
}
func setDefaultListenerSockopts (s int ) error {
return os .NewSyscallError ("setsockopt" , syscall .SetsockoptInt (s , syscall .SOL_SOCKET , syscall .SO_REUSEADDR , 1 ))
}
func setDefaultMulticastSockopts (s int ) error {
if err := syscall .SetsockoptInt (s , syscall .SOL_SOCKET , syscall .SO_REUSEADDR , 1 ); err != nil {
return os .NewSyscallError ("setsockopt" , err )
}
return os .NewSyscallError ("setsockopt" , syscall .SetsockoptInt (s , syscall .SOL_SOCKET , syscall .SO_REUSEPORT , 1 ))
}
The pages are generated with Golds v0.3.6 . (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .