net: fix broken setDefaultSockopts

R=rsc, bradfitz
CC=golang-dev
https://golang.org/cl/5536068
This commit is contained in:
Mikio Hara 2012-01-20 07:31:13 +09:00
parent 8d66a416cb
commit 743c2d0f48
8 changed files with 44 additions and 35 deletions

View file

@ -10,14 +10,15 @@ import (
"syscall"
)
func setDefaultSockopts(s, f, p int) {
func setDefaultSockopts(s, f, t int) {
switch f {
case syscall.AF_INET6:
// Allow both IP versions even if the OS default is otherwise.
syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 0)
}
if f == syscall.AF_UNIX || p == syscall.IPPROTO_TCP {
if f == syscall.AF_UNIX ||
(f == syscall.AF_INET || f == syscall.AF_INET6) && t == syscall.SOCK_STREAM {
// Allow reuse of recently-used addresses.
syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
}