syscall_linux_386.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // 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. // This code is a duplicate of syscall/syscall_linux_386.go with small
  5. // modifications.
  6. package ipv6
  7. import (
  8. "syscall"
  9. "unsafe"
  10. )
  11. // On x86 Linux, all the socket calls go through an extra indirection,
  12. // I think because the 5-register system call interface can't handle
  13. // the 6-argument calls like sendto and recvfrom. Instead the
  14. // arguments to the underlying system call are the number below and a
  15. // pointer to an array of uintptr. We hide the pointer in the
  16. // socketcall assembly to avoid allocation on every system call.
  17. const (
  18. // See /usr/include/linux/net.h.
  19. _SETSOCKOPT = 14
  20. _GETSOCKOPT = 15
  21. )
  22. var socketcall func(call int, a0, a1, a2, a3, a4, a5 uintptr) (int, syscall.Errno)
  23. func getsockopt(fd int, level int, name int, v uintptr, l *sysSockoptLen) error {
  24. if _, errno := socketcall(_GETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), uintptr(v), uintptr(unsafe.Pointer(l)), 0); errno != 0 {
  25. return error(errno)
  26. }
  27. return nil
  28. }
  29. func setsockopt(fd int, level int, name int, v uintptr, l uintptr) error {
  30. if _, errno := socketcall(_SETSOCKOPT, uintptr(fd), uintptr(level), uintptr(name), v, l, 0); errno != 0 {
  31. return error(errno)
  32. }
  33. return nil
  34. }