Skip to content

Commit 5974926

Browse files
committed
Add CMSG_* "macro" support to Fuchsia
This change defines and implements functions for the Fuchsia platform corresponding to the C library CMSG_* macros, used for processing socket control messages sent or received using the recv_msg(2)/send_msg(2) syscalls.
1 parent b2e250e commit 5974926

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/fuchsia/mod.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,6 +3250,60 @@ f! {
32503250
dev |= (minor & 0xffffff00) << 12;
32513251
dev
32523252
}
3253+
3254+
pub fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
3255+
cmsg.offset(1) as *mut c_uchar
3256+
}
3257+
3258+
pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) ->
3259+
*mut cmsghdr {
3260+
if ((*cmsg).cmsg_len as ::size_t) < ::mem::size_of::<cmsghdr>() {
3261+
core::ptr::null_mut()
3262+
} else if __CMSG_NEXT(cmsg).add(::mem::size_of::<cmsghdr>())
3263+
>= __MHDR_END(mhdr) {
3264+
core::ptr::null_mut()
3265+
} else {
3266+
__CMSG_NEXT(cmsg).cast()
3267+
}
3268+
}
3269+
3270+
pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr {
3271+
if (*mhdr).msg_controllen as ::size_t >= ::mem::size_of::<cmsghdr>() {
3272+
(*mhdr).msg_control.cast()
3273+
} else {
3274+
core::ptr::null_mut()
3275+
}
3276+
}
3277+
3278+
pub fn CMSG_ALIGN(len: ::size_t) -> ::size_t {
3279+
(len + ::mem::size_of::<::size_t>() - 1)
3280+
& !(::mem::size_of::<::size_t>() - 1)
3281+
}
3282+
3283+
pub fn CMSG_SPACE(len: ::c_uint) -> ::c_uint {
3284+
(CMSG_ALIGN(len as ::size_t) + CMSG_ALIGN(::mem::size_of::<cmsghdr>()))
3285+
as ::c_uint
3286+
}
3287+
3288+
pub fn CMSG_LEN(len: ::c_uint) -> ::c_uint {
3289+
(CMSG_ALIGN(::mem::size_of::<cmsghdr>()) + len as ::size_t) as ::c_uint
3290+
}
3291+
}
3292+
3293+
fn __CMSG_LEN(cmsg: *const cmsghdr) -> ::ssize_t {
3294+
((unsafe { (*cmsg).cmsg_len as ::size_t } + ::mem::size_of::<::c_long>()
3295+
- 1)
3296+
& !(::mem::size_of::<::c_long>() - 1)) as ::ssize_t
3297+
}
3298+
3299+
fn __CMSG_NEXT(cmsg: *const cmsghdr) -> *mut c_uchar {
3300+
(unsafe { cmsg.offset(__CMSG_LEN(cmsg)) }) as *mut c_uchar
3301+
}
3302+
3303+
fn __MHDR_END(mhdr: *const msghdr) -> *mut c_uchar {
3304+
unsafe {
3305+
(*mhdr).msg_control.offset((*mhdr).msg_controllen as isize)
3306+
}.cast()
32533307
}
32543308

32553309
// EXTERN_FN

0 commit comments

Comments
 (0)