nebula/udp/udp_linux_32.go

56 lines
1.1 KiB
Go
Raw Normal View History

2021-10-21 15:24:11 -06:00
//go:build linux && (386 || amd64p32 || arm || mips || mipsle) && !android && !e2e_testing
// +build linux
// +build 386 amd64p32 arm mips mipsle
// +build !android
2021-03-26 08:46:30 -06:00
// +build !e2e_testing
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 uint32
}
type msghdr struct {
Name *byte
Namelen uint32
Iov *iovec
Iovlen uint32
Control *byte
Controllen uint32
Flags int32
}
type rawMessage struct {
Hdr msghdr
Len uint32
}
2023-06-14 09:48:52 -06:00
func (u *StdConn) 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 {
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: uint32(len(buffers[i]))},
2019-11-19 10:00:20 -07:00
}
msgs[i].Hdr.Iov = &vs[0]
msgs[i].Hdr.Iovlen = uint32(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
}