From 66c4a5e6ae498391e304b6b4386ce113b8381078 Mon Sep 17 00:00:00 2001 From: brijesh Date: Sat, 28 Oct 2023 22:30:00 +0530 Subject: [PATCH] feat: Added ifconf struct --- libc-test/build.rs | 2 ++ libc-test/semver/linux.txt | 1 + src/unix/linux_like/linux/mod.rs | 34 ++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index cd1750d118ec0..28e4d9ec0fd0c 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -4058,6 +4058,8 @@ fn test_linux(target: &str) { (struct_ == "sockaddr_vm" && field == "svm_zero") || // the `ifr_ifru` field is an anonymous union (struct_ == "ifreq" && field == "ifr_ifru") || + // the `ifc_ifcu` field is an anonymous union + (struct_ == "ifconf" && field == "ifc_ifcu") || // glibc uses a single array `uregs` instead of individual fields. (struct_ == "user_regs" && arm) }); diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 320be0f529f61..27a4a591399a0 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -3211,6 +3211,7 @@ if_freenameindex if_nameindex ifaddrs ifreq +ifconf in6_ifreq in6_pktinfo in6_rtmsg diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 53977182cc8fa..c6f37a70d2f20 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -792,6 +792,23 @@ s_no_extra_traits! { pub ifr_ifru: ::sockaddr, } + #[cfg(libc_union)] + pub union __c_anonymous_ifc_ifcu { + pub ifcu_buf: *mut ::c_char, + pub ifcu_req: *mut ::ifreq, + } + + /* Structure used in SIOCGIFCONF request. Used to retrieve interface + configuration for machine (useful for programs which must know all + networks accessible). */ + pub struct ifconf { + pub ifc_len: ::c_int, /* Size of buffer. */ + #[cfg(libc_union)] + pub ifc_ifcu: __c_anonymous_ifc_ifcu, + #[cfg(not(libc_union))] + pub ifc_ifcu: *mut ::ifreq, + } + pub struct hwtstamp_config { pub flags: ::c_int, pub tx_type: ::c_int, @@ -1229,6 +1246,23 @@ cfg_if! { } } + #[cfg(libc_union)] + impl ::fmt::Debug for __c_anonymous_ifc_ifcu { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ifr_ifru") + .field("ifcu_buf", unsafe { &self.ifcu_buf }) + .field("ifcu_req", unsafe { &self.ifcu_req }) + .finish() + } + } + impl ::fmt::Debug for ifconf { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ifconf") + .field("ifc_len", &self.ifc_len) + .field("ifc_ifcu", &self.ifc_ifcu) + .finish() + } + } impl ::fmt::Debug for hwtstamp_config { fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { f.debug_struct("hwtstamp_config")