MCPcopy Create free account
hub / github.com/Starry-OS/StarryOS / parse

Method parse

api/src/syscall/net/cmsg.rs:15–43  ·  view source on GitHub ↗
(hdr: &cmsghdr)

Source from the content-addressed store, hash-verified

13}
14impl CMsg {
15 pub fn parse(hdr: &cmsghdr) -> AxResult<Self> {
16 if hdr.cmsg_len < size_of::<cmsghdr>() {
17 return Err(AxError::InvalidInput);
18 }
19
20 let data =
21 UserConstPtr::<u8>::from((hdr as *const cmsghdr as usize) + size_of::<cmsghdr>())
22 .get_as_slice(hdr.cmsg_len - size_of::<cmsghdr>())?;
23 Ok(match (hdr.cmsg_level as u32, hdr.cmsg_type as u32) {
24 (SOL_SOCKET, SCM_RIGHTS) => {
25 if data.len() % size_of::<i32>() != 0 {
26 return Err(AxError::InvalidInput);
27 }
28 let mut fds = Vec::new();
29 for fd in data.chunks_exact(size_of::<i32>()) {
30 let fd = i32::from_ne_bytes(fd.try_into().unwrap());
31 if fd < 0 {
32 return Err(AxError::BadFileDescriptor);
33 }
34 let f = get_file_like(fd)?;
35 fds.push(f);
36 }
37 Self::Rights { fds }
38 }
39 _ => {
40 return Err(AxError::InvalidInput);
41 }
42 })
43 }
44}
45
46pub struct CMsgBuilder<'a> {

Callers

nothing calls this directly

Calls 4

get_file_likeFunction · 0.85
get_as_sliceMethod · 0.80
pushMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected