Skip to content

Commit

Permalink
fix: skiping ifconf and adding debug trait to ifconf
Browse files Browse the repository at this point in the history
  • Loading branch information
Brijeshkrishna committed Oct 22, 2023
1 parent a25fe4d commit 2b34fd0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4041,6 +4041,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)
});
Expand Down
30 changes: 25 additions & 5 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,17 +792,21 @@ s_no_extra_traits! {
pub ifr_ifru: ::sockaddr,
}

#[cfg(libc_union)]
pub union __c_anonymous_ifc_ifcu {
ifcu_buf: *mut ::c_char,
ifcu_req: *mut ::ifreq,
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). */
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 {
Expand Down Expand Up @@ -1241,7 +1245,23 @@ cfg_if! {
.finish()
}
}

#[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")
Expand Down

0 comments on commit 2b34fd0

Please sign in to comment.