github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/proto_vendor/golang.org/x/net/internal/socket/mmsghdr_unix.go (about) 1 // Copyright 2017 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 5 // +build aix linux netbsd 6 7 package socket 8 9 import "net" 10 11 type mmsghdrs []mmsghdr 12 13 func (hs mmsghdrs) pack(ms []Message, parseFn func([]byte, string) (net.Addr, error), marshalFn func(net.Addr) []byte) error { 14 for i := range hs { 15 vs := make([]iovec, len(ms[i].Buffers)) 16 var sa []byte 17 if parseFn != nil { 18 sa = make([]byte, sizeofSockaddrInet6) 19 } 20 if marshalFn != nil { 21 sa = marshalFn(ms[i].Addr) 22 } 23 hs[i].Hdr.pack(vs, ms[i].Buffers, ms[i].OOB, sa) 24 } 25 return nil 26 } 27 28 func (hs mmsghdrs) unpack(ms []Message, parseFn func([]byte, string) (net.Addr, error), hint string) error { 29 for i := range hs { 30 ms[i].N = int(hs[i].Len) 31 ms[i].NN = hs[i].Hdr.controllen() 32 ms[i].Flags = hs[i].Hdr.flags() 33 if parseFn != nil { 34 var err error 35 ms[i].Addr, err = parseFn(hs[i].Hdr.name(), hint) 36 if err != nil { 37 return err 38 } 39 } 40 } 41 return nil 42 }