summaryrefslogtreecommitdiffhomepage
path: root/server/sockopt_bsd.go
diff options
context:
space:
mode:
authorVincent Bernat <vincent@bernat.im>2016-09-08 07:57:31 +0200
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-09-12 23:48:02 -0700
commit8c11fdfd0ff67fcab0c60b4c1ba23280fa1589f2 (patch)
tree384e6364cf2522c8785c5778bc32ebeffbe0f190 /server/sockopt_bsd.go
parent83b6f07be76a5f5f8ae5b53b664bb8b902dcbf05 (diff)
server: portability fix for setsockopt() on Linux
On some architecture, setsockopt() is a multiplexed syscall and is not available directly (for example, on i386). Instead of invoking the syscall directly, use syscall.SetsockoptString() which is safe as strings are not null-terminated with Go. On BSD, use syscall.SetsockoptInt(), but I don't know if there are architectures with the same limitations as for Linux. Signed-off-by: Vincent Bernat <vincent@bernat.im>
Diffstat (limited to 'server/sockopt_bsd.go')
-rw-r--r--server/sockopt_bsd.go9
1 files changed, 3 insertions, 6 deletions
diff --git a/server/sockopt_bsd.go b/server/sockopt_bsd.go
index 6c86e068..8fac5165 100644
--- a/server/sockopt_bsd.go
+++ b/server/sockopt_bsd.go
@@ -43,12 +43,9 @@ func SetTcpMD5SigSockopts(l *net.TCPListener, address string, key string) error
// always enable and assumes that the configuration is done by
// setkey()
- t := int32(1)
- _, _, e := syscall.Syscall6(syscall.SYS_SETSOCKOPT, fi.Fd(),
- uintptr(syscall.IPPROTO_TCP), uintptr(TCP_MD5SIG),
- uintptr(unsafe.Pointer(&t)), unsafe.Sizeof(t), 0)
- if e > 0 {
- return e
+ if err := syscall.SetsockoptInt(int(fi.Fd()),
+ syscall.IPPROTO_TCP, TCP_MD5SIG, 1); err != nil {
+ return err
}
return nil
}