From 04b99c50b82ff72728fdcd82f29546de1ab95ea5 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Sun, 25 Jan 2026 21:45:36 +0000 Subject: [PATCH] Accept AsFd in ioctl macros --- changelog/2727.changed.md | 1 + src/sys/ioctl/mod.rs | 73 +++++++++++++++++++++++---------------- src/sys/socket/addr.rs | 4 +-- test/sys/test_ioctl.rs | 28 +++++++-------- test/sys/test_socket.rs | 4 +-- test/sys/test_sockopt.rs | 9 ++--- 6 files changed, 64 insertions(+), 55 deletions(-) create mode 100644 changelog/2727.changed.md diff --git a/changelog/2727.changed.md b/changelog/2727.changed.md new file mode 100644 index 0000000000..d67c15c894 --- /dev/null +++ b/changelog/2727.changed.md @@ -0,0 +1 @@ +Accept `AsFd` in `ioctl` macros diff --git a/src/sys/ioctl/mod.rs b/src/sys/ioctl/mod.rs index aab48192f5..783b346aeb 100644 --- a/src/sys/ioctl/mod.rs +++ b/src/sys/ioctl/mod.rs @@ -261,7 +261,7 @@ macro_rules! convert_ioctl_res { /// The generated function has the following signature: /// /// ```rust,ignore -/// pub unsafe fn FUNCTION_NAME(fd: libc::c_int) -> Result +/// pub unsafe fn FUNCTION_NAME(fd: Fd) -> Result /// ``` /// /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html). @@ -285,8 +285,9 @@ macro_rules! convert_ioctl_res { macro_rules! ioctl_none { ($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int) + pub unsafe fn $name(fd: Fd) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); unsafe { convert_ioctl_res!($crate::libc::ioctl(fd, request_code_none!($ioty, $nr) as $crate::sys::ioctl::ioctl_num_type)) } @@ -304,7 +305,7 @@ macro_rules! ioctl_none { /// The generated function has the following signature: /// /// ```rust,ignore -/// pub unsafe fn FUNCTION_NAME(fd: libc::c_int) -> Result +/// pub unsafe fn FUNCTION_NAME(fd: Fd) -> Result /// ``` /// /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html). @@ -315,11 +316,10 @@ macro_rules! ioctl_none { /// # #[macro_use] extern crate nix; /// # use libc::TIOCNXCL; /// # use std::fs::File; -/// # use std::os::unix::io::AsRawFd; /// ioctl_none_bad!(tiocnxcl, TIOCNXCL); /// fn main() { /// let file = File::open("/dev/ttyUSB0").unwrap(); -/// unsafe { tiocnxcl(file.as_raw_fd()) }.unwrap(); +/// unsafe { tiocnxcl(&file) }.unwrap(); /// } /// ``` // TODO: add an example using request_code_*!() @@ -327,8 +327,9 @@ macro_rules! ioctl_none { macro_rules! ioctl_none_bad { ($(#[$attr:meta])* $name:ident, $nr:expr) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int) + pub unsafe fn $name(fd: Fd) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); unsafe { convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type)) } @@ -348,7 +349,7 @@ macro_rules! ioctl_none_bad { /// The generated function has the following signature: /// /// ```rust,ignore -/// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: *mut DATA_TYPE) -> Result +/// pub unsafe fn FUNCTION_NAME(fd: Fd, data: *mut DATA_TYPE) -> Result /// ``` /// /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html). @@ -366,9 +367,10 @@ macro_rules! ioctl_none_bad { macro_rules! ioctl_read { ($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr, $ty:ty) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int, + pub unsafe fn $name(fd: Fd, data: *mut $ty) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); unsafe { convert_ioctl_res!($crate::libc::ioctl(fd, request_code_read!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data)) } @@ -387,7 +389,7 @@ macro_rules! ioctl_read { /// The generated function has the following signature: /// /// ```rust,ignore -/// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: *mut DATA_TYPE) -> Result +/// pub unsafe fn FUNCTION_NAME(fd: Fd, data: *mut DATA_TYPE) -> Result /// ``` /// /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html). @@ -404,9 +406,10 @@ macro_rules! ioctl_read { macro_rules! ioctl_read_bad { ($(#[$attr:meta])* $name:ident, $nr:expr, $ty:ty) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int, + pub unsafe fn $name(fd: Fd, data: *mut $ty) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); unsafe { convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type, data)) } @@ -426,7 +429,7 @@ macro_rules! ioctl_read_bad { /// The generated function has the following signature: /// /// ```rust,ignore -/// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: *const DATA_TYPE) -> Result +/// pub unsafe fn FUNCTION_NAME(fd: Fd, data: *const DATA_TYPE) -> Result /// ``` /// /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html). @@ -443,9 +446,10 @@ macro_rules! ioctl_read_bad { macro_rules! ioctl_write_ptr { ($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr, $ty:ty) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int, + pub unsafe fn $name(fd: Fd, data: *const $ty) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); unsafe { convert_ioctl_res!($crate::libc::ioctl(fd, request_code_write!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, data)) } @@ -464,7 +468,7 @@ macro_rules! ioctl_write_ptr { /// The generated function has the following signature: /// /// ```rust,ignore -/// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: *const DATA_TYPE) -> Result +/// pub unsafe fn FUNCTION_NAME(fd: Fd, data: *const DATA_TYPE) -> Result /// ``` /// /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html). @@ -481,9 +485,10 @@ macro_rules! ioctl_write_ptr { macro_rules! ioctl_write_ptr_bad { ($(#[$attr:meta])* $name:ident, $nr:expr, $ty:ty) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int, + pub unsafe fn $name(fd: Fd, data: *const $ty) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); unsafe { convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type, data)) } @@ -504,7 +509,7 @@ cfg_if! { /// The generated function has the following signature: /// /// ```rust,ignore - /// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: nix::sys::ioctl::ioctl_param_type) -> Result + /// pub unsafe fn FUNCTION_NAME(fd: Fd, data: nix::sys::ioctl::ioctl_param_type) -> Result /// ``` /// /// `nix::sys::ioctl::ioctl_param_type` depends on the OS: @@ -524,9 +529,10 @@ cfg_if! { macro_rules! ioctl_write_int { ($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int, + pub unsafe fn $name(fd: Fd, data: $crate::sys::ioctl::ioctl_param_type) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); unsafe { convert_ioctl_res!($crate::libc::ioctl(fd, request_code_write_int!($ioty, $nr) as $crate::sys::ioctl::ioctl_num_type, data)) } @@ -545,7 +551,7 @@ cfg_if! { /// The generated function has the following signature: /// /// ```rust,ignore - /// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: nix::sys::ioctl::ioctl_param_type) -> Result + /// pub unsafe fn FUNCTION_NAME(fd: Fd, data: nix::sys::ioctl::ioctl_param_type) -> Result /// ``` /// /// `nix::sys::ioctl::ioctl_param_type` depends on the OS: @@ -567,9 +573,10 @@ cfg_if! { macro_rules! ioctl_write_int { ($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int, + pub unsafe fn $name(fd: Fd, data: $crate::sys::ioctl::ioctl_param_type) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); unsafe { convert_ioctl_res!($crate::libc::ioctl(fd, request_code_write!($ioty, $nr, ::std::mem::size_of::<$crate::libc::c_int>()) as $crate::sys::ioctl::ioctl_num_type, data)) } @@ -589,7 +596,7 @@ cfg_if! { /// The generated function has the following signature: /// /// ```rust,ignore -/// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: libc::c_int) -> Result +/// pub unsafe fn FUNCTION_NAME(fd: Fd, data: libc::c_int) -> Result /// ``` /// /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html). @@ -613,9 +620,10 @@ cfg_if! { macro_rules! ioctl_write_int_bad { ($(#[$attr:meta])* $name:ident, $nr:expr) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int, + pub unsafe fn $name(fd: Fd, data: $crate::libc::c_int) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); unsafe { convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type, data)) } @@ -635,7 +643,7 @@ macro_rules! ioctl_write_int_bad { /// The generated function has the following signature: /// /// ```rust,ignore -/// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: *mut DATA_TYPE) -> Result +/// pub unsafe fn FUNCTION_NAME(fd: Fd, data: *mut DATA_TYPE) -> Result /// ``` /// /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html). @@ -652,9 +660,10 @@ macro_rules! ioctl_write_int_bad { macro_rules! ioctl_readwrite { ($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr, $ty:ty) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int, + pub unsafe fn $name(fd: Fd, data: *mut $ty) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); let ioty = $ioty; let nr = $nr; unsafe { @@ -675,7 +684,7 @@ macro_rules! ioctl_readwrite { /// The generated function has the following signature: /// /// ```rust,ignore -/// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: *mut DATA_TYPE) -> Result +/// pub unsafe fn FUNCTION_NAME(fd: Fd, data: *mut DATA_TYPE) -> Result /// ``` /// /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html). @@ -684,9 +693,10 @@ macro_rules! ioctl_readwrite { macro_rules! ioctl_readwrite_bad { ($(#[$attr:meta])* $name:ident, $nr:expr, $ty:ty) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int, + pub unsafe fn $name(fd: Fd, data: *mut $ty) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); unsafe { convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type, data)) } @@ -706,7 +716,7 @@ macro_rules! ioctl_readwrite_bad { /// The generated function has the following signature: /// /// ```rust,ignore -/// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: &mut [DATA_TYPE]) -> Result +/// pub unsafe fn FUNCTION_NAME(fd: Fd, data: &mut [DATA_TYPE]) -> Result /// ``` /// /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html). @@ -715,9 +725,10 @@ macro_rules! ioctl_readwrite_bad { macro_rules! ioctl_read_buf { ($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr, $ty:ty) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int, + pub unsafe fn $name(fd: Fd, data: &mut [$ty]) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); unsafe { convert_ioctl_res!($crate::libc::ioctl(fd, request_code_read!($ioty, $nr, ::std::mem::size_of_val(data)) as $crate::sys::ioctl::ioctl_num_type, data.as_mut_ptr())) } @@ -737,7 +748,7 @@ macro_rules! ioctl_read_buf { /// The generated function has the following signature: /// /// ```rust,ignore -/// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: &[DATA_TYPE]) -> Result +/// pub unsafe fn FUNCTION_NAME(fd: Fd, data: &[DATA_TYPE]) -> Result /// ``` /// /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html). @@ -756,9 +767,10 @@ macro_rules! ioctl_read_buf { macro_rules! ioctl_write_buf { ($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr, $ty:ty) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int, + pub unsafe fn $name(fd: Fd, data: &[$ty]) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); unsafe { convert_ioctl_res!($crate::libc::ioctl(fd, request_code_write!($ioty, $nr, ::std::mem::size_of_val(data)) as $crate::sys::ioctl::ioctl_num_type, data.as_ptr())) } @@ -778,7 +790,7 @@ macro_rules! ioctl_write_buf { /// The generated function has the following signature: /// /// ```rust,ignore -/// pub unsafe fn FUNCTION_NAME(fd: libc::c_int, data: &mut [DATA_TYPE]) -> Result +/// pub unsafe fn FUNCTION_NAME(fd: Fd, data: &mut [DATA_TYPE]) -> Result /// ``` /// /// For a more in-depth explanation of ioctls, see [`::sys::ioctl`](sys/ioctl/index.html). @@ -787,9 +799,10 @@ macro_rules! ioctl_write_buf { macro_rules! ioctl_readwrite_buf { ($(#[$attr:meta])* $name:ident, $ioty:expr, $nr:expr, $ty:ty) => ( $(#[$attr])* - pub unsafe fn $name(fd: $crate::libc::c_int, + pub unsafe fn $name(fd: Fd, data: &mut [$ty]) -> $crate::Result<$crate::libc::c_int> { + let fd = ::std::os::fd::AsRawFd::as_raw_fd(&fd.as_fd()); unsafe { convert_ioctl_res!($crate::libc::ioctl(fd, request_code_readwrite!($ioty, $nr, ::std::mem::size_of_val(data)) as $crate::sys::ioctl::ioctl_num_type, data.as_mut_ptr())) } diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 09be1d68b5..b5e6badfbb 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -1732,7 +1732,7 @@ pub mod sys_control { use crate::sys::socket::addr::AddressFamily; use libc::{self, c_uchar}; use std::{fmt, mem, ptr}; - use std::os::unix::io::RawFd; + use crate::{Errno, Result}; use super::{private, SockaddrLike}; @@ -1801,7 +1801,7 @@ pub mod sys_control { /// Construct a new `SysControlAddr` from its human readable name and /// unit number. - pub fn from_name(sockfd: RawFd, name: &str, unit: u32) -> Result { + pub fn from_name(sockfd: Fd, name: &str, unit: u32) -> Result { if name.len() > MAX_KCTL_NAME { return Err(Errno::ENAMETOOLONG); } diff --git a/test/sys/test_ioctl.rs b/test/sys/test_ioctl.rs index 08843bf61c..df922341f0 100644 --- a/test/sys/test_ioctl.rs +++ b/test/sys/test_ioctl.rs @@ -203,7 +203,6 @@ mod bsd { #[cfg(linux_android)] mod linux_ioctls { use std::mem; - use std::os::unix::io::AsRawFd; use libc::{termios, TCGETS, TCSBRK, TCSETS, TIOCNXCL}; use tempfile::tempfile; @@ -214,7 +213,7 @@ mod linux_ioctls { #[test] fn test_ioctl_none_bad() { let file = tempfile().unwrap(); - let res = unsafe { tiocnxcl(file.as_raw_fd()) }; + let res = unsafe { tiocnxcl(&file) }; assert_eq!(res, Err(Errno::ENOTTY)); } @@ -223,7 +222,7 @@ mod linux_ioctls { fn test_ioctl_read_bad() { let file = tempfile().unwrap(); let mut termios = unsafe { mem::zeroed() }; - let res = unsafe { tcgets(file.as_raw_fd(), &mut termios) }; + let res = unsafe { tcgets(&file, &mut termios) }; assert_eq!(res, Err(Errno::ENOTTY)); } @@ -231,7 +230,7 @@ mod linux_ioctls { #[test] fn test_ioctl_write_int_bad() { let file = tempfile().unwrap(); - let res = unsafe { tcsbrk(file.as_raw_fd(), 0) }; + let res = unsafe { tcsbrk(&file, 0) }; assert_eq!(res, Err(Errno::ENOTTY)); } @@ -240,7 +239,7 @@ mod linux_ioctls { fn test_ioctl_write_ptr_bad() { let file = tempfile().unwrap(); let termios: termios = unsafe { mem::zeroed() }; - let res = unsafe { tcsets(file.as_raw_fd(), &termios) }; + let res = unsafe { tcsets(&file, &termios) }; assert_eq!(res, Err(Errno::ENOTTY)); } @@ -251,7 +250,7 @@ mod linux_ioctls { #[test] fn test_ioctl_none() { let file = tempfile().unwrap(); - let res = unsafe { log_status(file.as_raw_fd()) }; + let res = unsafe { log_status(&file) }; assert!(res == Err(Errno::ENOTTY) || res == Err(Errno::ENOSYS)); } @@ -270,7 +269,7 @@ mod linux_ioctls { fn test_ioctl_write_ptr() { let file = tempfile().unwrap(); let data: v4l2_audio = unsafe { mem::zeroed() }; - let res = unsafe { s_audio(file.as_raw_fd(), &data) }; + let res = unsafe { s_audio(&file, &data) }; assert!(res == Err(Errno::ENOTTY) || res == Err(Errno::ENOSYS)); } @@ -281,7 +280,7 @@ mod linux_ioctls { #[test] fn test_ioctl_write_int() { let file = tempfile().unwrap(); - let res = unsafe { hcidevup(file.as_raw_fd(), 0) }; + let res = unsafe { hcidevup(&file, 0) }; assert!(res == Err(Errno::ENOTTY) || res == Err(Errno::ENOSYS)); } @@ -291,7 +290,7 @@ mod linux_ioctls { fn test_ioctl_read() { let file = tempfile().unwrap(); let mut data: v4l2_audio = unsafe { mem::zeroed() }; - let res = unsafe { g_audio(file.as_raw_fd(), &mut data) }; + let res = unsafe { g_audio(&file, &mut data) }; assert!(res == Err(Errno::ENOTTY) || res == Err(Errno::ENOSYS)); } @@ -301,7 +300,7 @@ mod linux_ioctls { fn test_ioctl_readwrite() { let file = tempfile().unwrap(); let mut data: v4l2_audio = unsafe { mem::zeroed() }; - let res = unsafe { enum_audio(file.as_raw_fd(), &mut data) }; + let res = unsafe { enum_audio(&file, &mut data) }; assert!(res == Err(Errno::ENOTTY) || res == Err(Errno::ENOSYS)); } @@ -332,7 +331,7 @@ mod linux_ioctls { fn test_ioctl_write_buf() { let file = tempfile().unwrap(); let data: [spi_ioc_transfer; 4] = unsafe { mem::zeroed() }; - let res = unsafe { spi_ioc_message(file.as_raw_fd(), &data[..]) }; + let res = unsafe { spi_ioc_message(&file, &data[..]) }; assert!(res == Err(Errno::ENOTTY) || res == Err(Errno::ENOSYS)); } @@ -342,7 +341,6 @@ mod linux_ioctls { #[cfg(target_os = "freebsd")] mod freebsd_ioctls { use std::mem; - use std::os::unix::io::AsRawFd; use libc::termios; use tempfile::tempfile; @@ -359,7 +357,7 @@ mod freebsd_ioctls { #[test] fn test_ioctl_none() { let file = tempfile().unwrap(); - let res = unsafe { tiocnxcl(file.as_raw_fd()) }; + let res = unsafe { tiocnxcl(&file) }; assert_eq!(res, Err(Errno::ENOTTY)); } @@ -368,7 +366,7 @@ mod freebsd_ioctls { fn test_ioctl_read() { let file = tempfile().unwrap(); let mut termios = unsafe { mem::zeroed() }; - let res = unsafe { tiocgeta(file.as_raw_fd(), &mut termios) }; + let res = unsafe { tiocgeta(&file, &mut termios) }; assert_eq!(res, Err(Errno::ENOTTY)); } @@ -377,7 +375,7 @@ mod freebsd_ioctls { fn test_ioctl_write_ptr() { let file = tempfile().unwrap(); let termios: termios = unsafe { mem::zeroed() }; - let res = unsafe { tiocseta(file.as_raw_fd(), &termios) }; + let res = unsafe { tiocseta(&file, &termios) }; assert_eq!(res, Err(Errno::ENOTTY)); } } diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 5a423c3066..694289b58d 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -1789,10 +1789,10 @@ pub fn test_syscontrol() { SockProtocol::KextControl, ) .expect("socket failed"); - SysControlAddr::from_name(fd.as_raw_fd(), "com.apple.net.utun_control", 0) + SysControlAddr::from_name(&fd, "com.apple.net.utun_control", 0) .expect("resolving sys_control name failed"); assert_eq!( - SysControlAddr::from_name(fd.as_raw_fd(), "foo.bar.lol", 0).err(), + SysControlAddr::from_name(&fd, "foo.bar.lol", 0).err(), Some(Errno::ENOENT) ); diff --git a/test/sys/test_sockopt.rs b/test/sys/test_sockopt.rs index 5b06a5c13d..1f64ba69da 100644 --- a/test/sys/test_sockopt.rs +++ b/test/sys/test_sockopt.rs @@ -967,12 +967,9 @@ fn test_utun_ifname() { .unwrap(); let unit = 123; - let addr = SysControlAddr::from_name( - fd.as_raw_fd(), - "com.apple.net.utun_control", - unit, - ) - .unwrap(); + let addr = + SysControlAddr::from_name(&fd, "com.apple.net.utun_control", unit) + .unwrap(); connect(fd.as_raw_fd(), &addr).unwrap();