Skip to content

Commit

Permalink
Bug fix for android platform, because of the wrong behavior of CMSG_N…
Browse files Browse the repository at this point in the history
…XTHDR
  • Loading branch information
LinkTed committed Nov 24, 2020
1 parent ead7185 commit 9b9dd4a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions library/std/src/sys/unix/ext/net/ancillary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -157,6 +159,13 @@ fn add_to_ancillary_data<T>(
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() {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9b9dd4a

Please sign in to comment.