blob: 64a3c6653a3cbc04810e2c2d03b359a9c93ef09f [file] [log] [blame]
Mikio Harad3003be2013-11-05 10:09:42 +09001// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Mikio Harad3003be2013-11-05 10:09:42 +09005package ipv6
6
7import (
8 "syscall"
9 "unsafe"
10)
11
Mikio Harad3003be2013-11-05 10:09:42 +090012const (
Mikio Harafa893e02014-10-31 09:53:30 +090013 sysGETSOCKOPT = 0xf
14 sysSETSOCKOPT = 0xe
Mikio Harad3003be2013-11-05 10:09:42 +090015)
16
Mikio Harafa893e02014-10-31 09:53:30 +090017func socketcall(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno)
Mikio Harad3003be2013-11-05 10:09:42 +090018
Mikio Harac4bb2f72016-03-30 09:22:35 +090019func getsockopt(fd, level, name int, v unsafe.Pointer, l *uint32) error {
Mikio Harafa893e02014-10-31 09:53:30 +090020 if _, errno := socketcall(sysGETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
Mikio Harad3003be2013-11-05 10:09:42 +090021 return error(errno)
22 }
23 return nil
24}
25
Mikio Harac4bb2f72016-03-30 09:22:35 +090026func setsockopt(fd, level, name int, v unsafe.Pointer, l uint32) error {
Mikio Harafa893e02014-10-31 09:53:30 +090027 if _, errno := socketcall(sysSETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(l), 0); errno != 0 {
Mikio Harad3003be2013-11-05 10:09:42 +090028 return error(errno)
29 }
30 return nil
31}