Bug fix for android platform, because of the wrong behavior of CMSG_NXTHDR

This commit is contained in:
LinkTed 2020-11-24 19:24:39 +01:00
parent ead7185db6
commit 9b9dd4aeea

View File

@ -5,6 +5,8 @@ use crate::marker::PhantomData;
use crate::mem::{size_of, zeroed}; use crate::mem::{size_of, zeroed};
use crate::os::unix::io::RawFd; use crate::os::unix::io::RawFd;
use crate::path::Path; use crate::path::Path;
#[cfg(target_os = "android")]
use crate::ptr::eq;
use crate::ptr::read_unaligned; use crate::ptr::read_unaligned;
use crate::slice::from_raw_parts; use crate::slice::from_raw_parts;
use crate::sys::net::Socket; use crate::sys::net::Socket;
@ -157,6 +159,13 @@ fn add_to_ancillary_data<T>(
while !cmsg.is_null() { while !cmsg.is_null() {
previous_cmsg = cmsg; previous_cmsg = cmsg;
cmsg = libc::CMSG_NXTHDR(&msg, cmsg); cmsg = libc::CMSG_NXTHDR(&msg, cmsg);
cfg_if::cfg_if! {
if #[cfg(target_os = "android")] {
if cmsg == previous_cmsg {
break;
}
}
}
} }
if previous_cmsg.is_null() { if previous_cmsg.is_null() {
@ -420,6 +429,16 @@ impl<'a> Iterator for Messages<'a> {
}; };
let cmsg = cmsg.as_ref()?; let cmsg = cmsg.as_ref()?;
cfg_if::cfg_if! {
if #[cfg(target_os = "android")] {
if let Some(current) = self.current {
if eq(current, cmsg) {
return None;
}
}
}
}
self.current = Some(cmsg); self.current = Some(cmsg);
let ancillary_result = AncillaryData::try_from_cmsghdr(cmsg); let ancillary_result = AncillaryData::try_from_cmsghdr(cmsg);
Some(ancillary_result) Some(ancillary_result)