msghdr.SetControllen(int(unsafe.Sizeof(cmsg)))
- // sendmsg(sock, &msghdr, 0)
-
- _, _, errno := unix.Syscall(
- unix.SYS_SENDMSG,
- uintptr(sock),
- uintptr(unsafe.Pointer(&msghdr)),
- 0,
- )
+ _, _, errno := sendmsg(sock, &msghdr, 0)
if errno == 0 {
return nil
if errno == unix.EINVAL {
end.ClearSrc()
cmsg.pktinfo = unix.Inet6Pktinfo{}
- _, _, errno = unix.Syscall(
- unix.SYS_SENDMSG,
- uintptr(sock),
- uintptr(unsafe.Pointer(&msghdr)),
- 0,
- )
+ _, _, errno = sendmsg(sock, &msghdr, 0)
}
return errno
}
msghdr.SetControllen(int(unsafe.Sizeof(cmsg)))
- // sendmsg(sock, &msghdr, 0)
-
- _, _, errno := unix.Syscall(
- unix.SYS_SENDMSG,
- uintptr(sock),
- uintptr(unsafe.Pointer(&msghdr)),
- 0,
- )
+ _, _, errno := sendmsg(sock, &msghdr, 0)
// clear source and try again
if errno == unix.EINVAL {
end.ClearSrc()
cmsg.pktinfo = unix.Inet4Pktinfo{}
- _, _, errno = unix.Syscall(
- unix.SYS_SENDMSG,
- uintptr(sock),
- uintptr(unsafe.Pointer(&msghdr)),
- 0,
- )
+ _, _, errno = sendmsg(sock, &msghdr, 0)
}
// errno = 0 is still an error instance
msghdr.Control = (*byte)(unsafe.Pointer(&cmsg))
msghdr.SetControllen(int(unsafe.Sizeof(cmsg)))
- // recvmsg(sock, &mskhdr, 0)
-
- size, _, errno := unix.Syscall(
- unix.SYS_RECVMSG,
- uintptr(sock),
- uintptr(unsafe.Pointer(&msghdr)),
- 0,
- )
+ size, _, errno := recvmsg(sock, &msghdr, 0)
if errno != 0 {
return 0, errno
msg.Control = (*byte)(unsafe.Pointer(&cmsg))
msg.SetControllen(int(unsafe.Sizeof(cmsg)))
- // recvmsg(sock, &mskhdr, 0)
-
- size, _, errno := unix.Syscall(
- unix.SYS_RECVMSG,
- uintptr(sock),
- uintptr(unsafe.Pointer(&msg)),
- 0,
- )
+ size, _, errno := recvmsg(sock, &msg, 0)
if errno != 0 {
return 0, errno
--- /dev/null
+// +build linux,!386
+
+/* Copyright 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
+ */
+
+package main
+
+import (
+ "golang.org/x/sys/unix"
+ "syscall"
+ "unsafe"
+)
+
+func sendmsg(fd int, msghdr *unix.Msghdr, flags int) (uintptr, uintptr, syscall.Errno) {
+ return unix.Syscall(
+ unix.SYS_SENDMSG,
+ uintptr(fd),
+ uintptr(unsafe.Pointer(msghdr)),
+ uintptr(flags),
+ )
+}
+
+func recvmsg(fd int, msghdr *unix.Msghdr, flags int) (uintptr, uintptr, syscall.Errno) {
+ return unix.Syscall(
+ unix.SYS_RECVMSG,
+ uintptr(fd),
+ uintptr(unsafe.Pointer(msghdr)),
+ uintptr(flags),
+ )
+}
--- /dev/null
+// +build linux,386
+
+/* Copyright 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
+ */
+
+package main
+
+import (
+ "golang.org/x/sys/unix"
+ "syscall"
+ "unsafe"
+)
+
+const (
+ _SENDMSG = 16
+ _RECVMSG = 17
+)
+
+func sendmsg(fd int, msghdr *unix.Msghdr, flags int) (uintptr, uintptr, syscall.Errno) {
+ args := struct {
+ fd uintptr
+ msghdr uintptr
+ flags uintptr
+ }{
+ uintptr(fd),
+ uintptr(unsafe.Pointer(msghdr)),
+ uintptr(flags),
+ }
+ return unix.Syscall(
+ unix.SYS_SOCKETCALL,
+ _SENDMSG,
+ uintptr(unsafe.Pointer(&args)),
+ 0,
+ )
+}
+
+func recvmsg(fd int, msghdr *unix.Msghdr, flags int) (uintptr, uintptr, syscall.Errno) {
+ args := struct {
+ fd uintptr
+ msghdr uintptr
+ flags uintptr
+ }{
+ uintptr(fd),
+ uintptr(unsafe.Pointer(msghdr)),
+ uintptr(flags),
+ }
+ return unix.Syscall(
+ unix.SYS_SOCKETCALL,
+ _RECVMSG,
+ uintptr(unsafe.Pointer(&args)),
+ 0,
+ )
+}