Fix Linux's CMSG_NXTHDR and CMSG_SPACE definitions.
This is an error from PR #1098. The wrong definitions coincidentally work on Linux/glibc, but fail on Linux/musl.
This commit is contained in:
parent
73df81fcec
commit
4300666bf3
@ -1114,6 +1114,10 @@ pub const ARPHRD_IEEE802154: u16 = 804;
|
||||
pub const ARPHRD_VOID: u16 = 0xFFFF;
|
||||
pub const ARPHRD_NONE: u16 = 0xFFFE;
|
||||
|
||||
fn CMSG_ALIGN(len: usize) -> usize {
|
||||
len + mem::size_of::<usize>() - 1 & !(mem::size_of::<usize>() - 1)
|
||||
}
|
||||
|
||||
f! {
|
||||
pub fn CMSG_FIRSTHDR(mhdr: *const msghdr) -> *mut cmsghdr {
|
||||
if (*mhdr).msg_controllen as usize >= mem::size_of::<cmsghdr>() {
|
||||
@ -1125,17 +1129,19 @@ f! {
|
||||
|
||||
pub fn CMSG_NXTHDR(mhdr: *const msghdr,
|
||||
cmsg: *const cmsghdr) -> *mut cmsghdr {
|
||||
if cmsg.is_null() {
|
||||
return CMSG_FIRSTHDR(mhdr);
|
||||
if ((*cmsg).cmsg_len as usize) < mem::size_of::<cmsghdr>() {
|
||||
return 0 as *mut cmsghdr;
|
||||
};
|
||||
let pad = mem::align_of::<cmsghdr>() - 1;
|
||||
let next = cmsg as usize + (*cmsg).cmsg_len as usize + pad & !pad;
|
||||
let next = (cmsg as usize + CMSG_ALIGN((*cmsg).cmsg_len as usize))
|
||||
as *mut cmsghdr;
|
||||
let max = (*mhdr).msg_control as usize
|
||||
+ (*mhdr).msg_controllen as usize;
|
||||
if next < max {
|
||||
next as *mut cmsghdr
|
||||
} else {
|
||||
if (next.offset(1)) as usize > max
|
||||
|| next as usize + CMSG_ALIGN((*next).cmsg_len as usize) > max
|
||||
{
|
||||
0 as *mut cmsghdr
|
||||
} else {
|
||||
next as *mut cmsghdr
|
||||
}
|
||||
}
|
||||
|
||||
@ -1144,12 +1150,12 @@ f! {
|
||||
}
|
||||
|
||||
pub fn CMSG_SPACE(length: ::c_uint) -> ::c_uint {
|
||||
let pad = mem::align_of::<cmsghdr>() as ::c_uint - 1;
|
||||
mem::size_of::<cmsghdr>() as ::c_uint + ((length + pad) & !pad)
|
||||
(CMSG_ALIGN(length as usize) + CMSG_ALIGN(mem::size_of::<cmsghdr>()))
|
||||
as ::c_uint
|
||||
}
|
||||
|
||||
pub fn CMSG_LEN(length: ::c_uint) -> ::c_uint {
|
||||
mem::size_of::<cmsghdr>() as ::c_uint + length
|
||||
CMSG_ALIGN(mem::size_of::<cmsghdr>()) as ::c_uint + length
|
||||
}
|
||||
|
||||
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
|
||||
|
Loading…
Reference in New Issue
Block a user