1// Copyright 2020 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
5package socket
6
7import (
8	"syscall"
9	"unsafe"
10)
11
12func syscall_syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
13func syscall_syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
14
15func probeProtocolStack() int {
16	return 4 // sizeof(int) on GOOS=zos GOARCH=s390x
17}
18
19func getsockopt(s uintptr, level, name int, b []byte) (int, error) {
20	l := uint32(len(b))
21	_, _, errno := syscall_syscall6(syscall.SYS_GETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(unsafe.Pointer(&l)), 0)
22	return int(l), errnoErr(errno)
23}
24
25func setsockopt(s uintptr, level, name int, b []byte) error {
26	_, _, errno := syscall_syscall6(syscall.SYS_SETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), 0)
27	return errnoErr(errno)
28}
29
30func recvmsg(s uintptr, h *msghdr, flags int) (int, error) {
31	n, _, errno := syscall_syscall(syscall.SYS___RECVMSG_A, s, uintptr(unsafe.Pointer(h)), uintptr(flags))
32	return int(n), errnoErr(errno)
33}
34
35func sendmsg(s uintptr, h *msghdr, flags int) (int, error) {
36	n, _, errno := syscall_syscall(syscall.SYS___SENDMSG_A, s, uintptr(unsafe.Pointer(h)), uintptr(flags))
37	return int(n), errnoErr(errno)
38}
39