From 9b9dd4aeea858fb2249adc9421ab156a78e84b8b Mon Sep 17 00:00:00 2001 From: LinkTed Date: Tue, 24 Nov 2020 19:24:39 +0100 Subject: [PATCH] Bug fix for android platform, because of the wrong behavior of CMSG_NXTHDR --- library/std/src/sys/unix/ext/net/ancillary.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/library/std/src/sys/unix/ext/net/ancillary.rs b/library/std/src/sys/unix/ext/net/ancillary.rs index a68475ab985..a94456b4e7a 100644 --- a/library/std/src/sys/unix/ext/net/ancillary.rs +++ b/library/std/src/sys/unix/ext/net/ancillary.rs @@ -5,6 +5,8 @@ use crate::marker::PhantomData; use crate::mem::{size_of, zeroed}; use crate::os::unix::io::RawFd; use crate::path::Path; +#[cfg(target_os = "android")] +use crate::ptr::eq; use crate::ptr::read_unaligned; use crate::slice::from_raw_parts; use crate::sys::net::Socket; @@ -157,6 +159,13 @@ fn add_to_ancillary_data( while !cmsg.is_null() { previous_cmsg = 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() { @@ -420,6 +429,16 @@ impl<'a> Iterator for Messages<'a> { }; 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); let ancillary_result = AncillaryData::try_from_cmsghdr(cmsg); Some(ancillary_result)