From 2879e4d6f1ca3f02e0fde4de7d51b67f3b6c968c Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Mon, 9 Nov 2020 10:00:07 -0600 Subject: [PATCH] Avoid using libc::af_alg_iv to get rid of deprecation warnings --- src/sys/socket/mod.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 5e5fb8d370..1126bd798d 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -847,22 +847,22 @@ impl<'a> ControlMessage<'a> { } #[cfg(any(target_os = "android", target_os = "linux"))] ControlMessage::AlgSetIv(iv) => { - let af_alg_iv = libc::af_alg_iv { - ivlen: iv.len() as u32, - iv: [0u8; 0], - }; + // libc::af_alg_iv is deprecated: https://github.com/rust-lang/libc/issues/1501 + // struct af_alg_iv { ivlen: u32, iv: [c_uchar] } + // we just have to manually construct that in memory - let size = mem::size_of::(); + let ivlen = iv.len() as u32; + let lensize = mem::size_of::(); unsafe { ptr::copy_nonoverlapping( - &af_alg_iv as *const _ as *const u8, + &ivlen as *const _ as *const u8, cmsg_data, - size, + lensize, ); ptr::copy_nonoverlapping( iv.as_ptr(), - cmsg_data.add(size), + cmsg_data.add(lensize), iv.len() ); }; @@ -915,7 +915,7 @@ impl<'a> ControlMessage<'a> { } #[cfg(any(target_os = "android", target_os = "linux"))] ControlMessage::AlgSetIv(iv) => { - mem::size_of::() + iv.len() + mem::size_of::() + iv.len() }, #[cfg(any(target_os = "android", target_os = "linux"))] ControlMessage::AlgSetOp(op) => {