2021-10-21 15:24:11 -06:00
|
|
|
//go:build linux && (amd64 || arm64 || ppc64 || ppc64le || mips64 || mips64le || s390x || riscv64) && !android && !e2e_testing
|
2019-12-11 11:38:45 -07:00
|
|
|
// +build linux
|
2021-10-13 08:55:32 -06:00
|
|
|
// +build amd64 arm64 ppc64 ppc64le mips64 mips64le s390x riscv64
|
2020-06-30 12:48:58 -06:00
|
|
|
// +build !android
|
2021-03-26 08:46:30 -06:00
|
|
|
// +build !e2e_testing
|
2019-12-11 11:38:45 -07:00
|
|
|
|
2021-11-03 19:54:04 -06:00
|
|
|
package udp
|
2019-11-19 10:00:20 -07:00
|
|
|
|
2021-03-18 19:37:24 -06:00
|
|
|
import (
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
2019-11-19 10:00:20 -07:00
|
|
|
|
|
|
|
type iovec struct {
|
|
|
|
Base *byte
|
|
|
|
Len uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
type msghdr struct {
|
|
|
|
Name *byte
|
|
|
|
Namelen uint32
|
|
|
|
Pad0 [4]byte
|
|
|
|
Iov *iovec
|
|
|
|
Iovlen uint64
|
|
|
|
Control *byte
|
|
|
|
Controllen uint64
|
|
|
|
Flags int32
|
|
|
|
Pad1 [4]byte
|
|
|
|
}
|
|
|
|
|
|
|
|
type rawMessage struct {
|
|
|
|
Hdr msghdr
|
|
|
|
Len uint32
|
|
|
|
Pad0 [4]byte
|
|
|
|
}
|
|
|
|
|
2021-11-03 19:54:04 -06:00
|
|
|
func (u *Conn) PrepareRawMessages(n int) ([]rawMessage, [][]byte, [][]byte) {
|
2019-11-19 10:00:20 -07:00
|
|
|
msgs := make([]rawMessage, n)
|
|
|
|
buffers := make([][]byte, n)
|
|
|
|
names := make([][]byte, n)
|
|
|
|
|
|
|
|
for i := range msgs {
|
2021-11-03 19:54:04 -06:00
|
|
|
buffers[i] = make([]byte, MTU)
|
2021-03-18 19:37:24 -06:00
|
|
|
names[i] = make([]byte, unix.SizeofSockaddrInet6)
|
2019-11-19 10:00:20 -07:00
|
|
|
|
|
|
|
//TODO: this is still silly, no need for an array
|
|
|
|
vs := []iovec{
|
2021-03-18 19:37:24 -06:00
|
|
|
{Base: &buffers[i][0], Len: uint64(len(buffers[i]))},
|
2019-11-19 10:00:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
msgs[i].Hdr.Iov = &vs[0]
|
|
|
|
msgs[i].Hdr.Iovlen = uint64(len(vs))
|
|
|
|
|
2021-03-18 19:37:24 -06:00
|
|
|
msgs[i].Hdr.Name = &names[i][0]
|
2019-11-19 10:00:20 -07:00
|
|
|
msgs[i].Hdr.Namelen = uint32(len(names[i]))
|
|
|
|
}
|
|
|
|
|
|
|
|
return msgs, buffers, names
|
|
|
|
}
|