github.com/slackhq/nebula@v1.9.0/udp/udp_linux_32.go (about)

     1  //go:build linux && (386 || amd64p32 || arm || mips || mipsle) && !android && !e2e_testing
     2  // +build linux
     3  // +build 386 amd64p32 arm mips mipsle
     4  // +build !android
     5  // +build !e2e_testing
     6  
     7  package udp
     8  
     9  import (
    10  	"golang.org/x/sys/unix"
    11  )
    12  
    13  type iovec struct {
    14  	Base *byte
    15  	Len  uint32
    16  }
    17  
    18  type msghdr struct {
    19  	Name       *byte
    20  	Namelen    uint32
    21  	Iov        *iovec
    22  	Iovlen     uint32
    23  	Control    *byte
    24  	Controllen uint32
    25  	Flags      int32
    26  }
    27  
    28  type rawMessage struct {
    29  	Hdr msghdr
    30  	Len uint32
    31  }
    32  
    33  func (u *StdConn) PrepareRawMessages(n int) ([]rawMessage, [][]byte, [][]byte) {
    34  	msgs := make([]rawMessage, n)
    35  	buffers := make([][]byte, n)
    36  	names := make([][]byte, n)
    37  
    38  	for i := range msgs {
    39  		buffers[i] = make([]byte, MTU)
    40  		names[i] = make([]byte, unix.SizeofSockaddrInet6)
    41  
    42  		//TODO: this is still silly, no need for an array
    43  		vs := []iovec{
    44  			{Base: &buffers[i][0], Len: uint32(len(buffers[i]))},
    45  		}
    46  
    47  		msgs[i].Hdr.Iov = &vs[0]
    48  		msgs[i].Hdr.Iovlen = uint32(len(vs))
    49  
    50  		msgs[i].Hdr.Name = &names[i][0]
    51  		msgs[i].Hdr.Namelen = uint32(len(names[i]))
    52  	}
    53  
    54  	return msgs, buffers, names
    55  }