sys_linux_s390x.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2017 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. package socket
  5. import (
  6. "syscall"
  7. "unsafe"
  8. )
  9. func probeProtocolStack() int { return 8 }
  10. const (
  11. sysSETSOCKOPT = 0xe
  12. sysGETSOCKOPT = 0xf
  13. sysSENDMSG = 0x10
  14. sysRECVMSG = 0x11
  15. sysRECVMMSG = 0x13
  16. sysSENDMMSG = 0x14
  17. )
  18. func socketcall(call, a0, a1, a2, a3, a4, a5 uintptr) (uintptr, syscall.Errno)
  19. func rawsocketcall(call, a0, a1, a2, a3, a4, a5 uintptr) (uintptr, syscall.Errno)
  20. func getsockopt(s uintptr, level, name int, b []byte) (int, error) {
  21. l := uint32(len(b))
  22. _, errno := socketcall(sysGETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(unsafe.Pointer(&l)), 0)
  23. return int(l), errnoErr(errno)
  24. }
  25. func setsockopt(s uintptr, level, name int, b []byte) error {
  26. _, errno := socketcall(sysSETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), 0)
  27. return errnoErr(errno)
  28. }
  29. func recvmsg(s uintptr, h *msghdr, flags int) (int, error) {
  30. n, errno := socketcall(sysRECVMSG, s, uintptr(unsafe.Pointer(h)), uintptr(flags), 0, 0, 0)
  31. return int(n), errnoErr(errno)
  32. }
  33. func sendmsg(s uintptr, h *msghdr, flags int) (int, error) {
  34. n, errno := socketcall(sysSENDMSG, s, uintptr(unsafe.Pointer(h)), uintptr(flags), 0, 0, 0)
  35. return int(n), errnoErr(errno)
  36. }
  37. func recvmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
  38. n, errno := socketcall(sysRECVMMSG, s, uintptr(unsafe.Pointer(&hs[0])), uintptr(len(hs)), uintptr(flags), 0, 0)
  39. return int(n), errnoErr(errno)
  40. }
  41. func sendmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
  42. n, errno := socketcall(sysSENDMMSG, s, uintptr(unsafe.Pointer(&hs[0])), uintptr(len(hs)), uintptr(flags), 0, 0)
  43. return int(n), errnoErr(errno)
  44. }