Skip to content

Commit 9b9dd4a

Browse files
committed
Bug fix for android platform, because of the wrong behavior of CMSG_NXTHDR
1 parent ead7185 commit 9b9dd4a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

library/std/src/sys/unix/ext/net/ancillary.rs

+19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use crate::marker::PhantomData;
55
use crate::mem::{size_of, zeroed};
66
use crate::os::unix::io::RawFd;
77
use crate::path::Path;
8+
#[cfg(target_os = "android")]
9+
use crate::ptr::eq;
810
use crate::ptr::read_unaligned;
911
use crate::slice::from_raw_parts;
1012
use crate::sys::net::Socket;
@@ -157,6 +159,13 @@ fn add_to_ancillary_data<T>(
157159
while !cmsg.is_null() {
158160
previous_cmsg = cmsg;
159161
cmsg = libc::CMSG_NXTHDR(&msg, cmsg);
162+
cfg_if::cfg_if! {
163+
if #[cfg(target_os = "android")] {
164+
if cmsg == previous_cmsg {
165+
break;
166+
}
167+
}
168+
}
160169
}
161170

162171
if previous_cmsg.is_null() {
@@ -420,6 +429,16 @@ impl<'a> Iterator for Messages<'a> {
420429
};
421430

422431
let cmsg = cmsg.as_ref()?;
432+
cfg_if::cfg_if! {
433+
if #[cfg(target_os = "android")] {
434+
if let Some(current) = self.current {
435+
if eq(current, cmsg) {
436+
return None;
437+
}
438+
}
439+
}
440+
}
441+
423442
self.current = Some(cmsg);
424443
let ancillary_result = AncillaryData::try_from_cmsghdr(cmsg);
425444
Some(ancillary_result)

0 commit comments

Comments
 (0)