50 i += cmsgAlignOf(int(h.Len)) |
50 i += cmsgAlignOf(int(h.Len)) |
51 } |
51 } |
52 return msgs, nil |
52 return msgs, nil |
53 } |
53 } |
54 |
54 |
|
55 // ParseOneSocketControlMessage parses a single socket control message from b, returning the message header, |
|
56 // message data (a slice of b), and the remainder of b after that single message. |
|
57 // When there are no remaining messages, len(remainder) == 0. |
|
58 func ParseOneSocketControlMessage(b []byte) (hdr Cmsghdr, data []byte, remainder []byte, err error) { |
|
59 h, dbuf, err := socketControlMessageHeaderAndData(b) |
|
60 if err != nil { |
|
61 return Cmsghdr{}, nil, nil, err |
|
62 } |
|
63 if i := cmsgAlignOf(int(h.Len)); i < len(b) { |
|
64 remainder = b[i:] |
|
65 } |
|
66 return *h, dbuf, remainder, nil |
|
67 } |
|
68 |
55 func socketControlMessageHeaderAndData(b []byte) (*Cmsghdr, []byte, error) { |
69 func socketControlMessageHeaderAndData(b []byte) (*Cmsghdr, []byte, error) { |
56 h := (*Cmsghdr)(unsafe.Pointer(&b[0])) |
70 h := (*Cmsghdr)(unsafe.Pointer(&b[0])) |
57 if h.Len < SizeofCmsghdr || uint64(h.Len) > uint64(len(b)) { |
71 if h.Len < SizeofCmsghdr || uint64(h.Len) > uint64(len(b)) { |
58 return nil, nil, EINVAL |
72 return nil, nil, EINVAL |
59 } |
73 } |