Skip to content

Commit

Permalink
Auto merge of #2653 - devnexen:fbsd_ifreq_ifconf, r=Amanieu
Browse files Browse the repository at this point in the history
freebsd add ifconf data.
  • Loading branch information
bors committed Jan 26, 2022
2 parents 7f1da49 + 619119e commit 526cb13
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2316,6 +2316,7 @@ fn test_freebsd(target: &str) {
("if_data", "__ifi_epoch") => true,
("if_data", "__ifi_lastchange") => true,
("ifreq", "ifr_ifru") => true,
("ifconf", "ifc_ifcu") => true,

// anonymous struct
("devstat", "dev_links") => true,
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/freebsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,8 @@ idtype_t
if_freenameindex
if_nameindex
ifaddrs
ifconf
ifreq
in6_pktinfo
initgroups
ip_mreqn
Expand Down
44 changes: 44 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,13 @@ s! {
pub sc_ngroups: ::c_int,
pub sc_groups: [::gid_t; 1],
}

pub struct ifconf {
pub ifc_len: ::c_int,
#[cfg(libc_union)]
pub ifc_ifcu: __c_anonymous_ifc_ifcu,
}

}

s_no_extra_traits! {
Expand Down Expand Up @@ -1142,6 +1149,12 @@ s_no_extra_traits! {
pub ifr_ifru: ::sockaddr,
}

#[cfg(libc_union)]
pub union __c_anonymous_ifc_ifcu {
pub ifcu_buf: ::caddr_t,
pub ifcu_req: *mut ifreq,
}

pub struct ifstat {
/// if name, e.g. "en0"
pub ifs_name: [::c_char; ::IFNAMSIZ as usize],
Expand Down Expand Up @@ -1549,6 +1562,37 @@ cfg_if! {
}
}

#[cfg(libc_union)]
impl Eq for __c_anonymous_ifc_ifcu {}

#[cfg(libc_union)]
impl PartialEq for __c_anonymous_ifc_ifcu {
fn eq(&self, other: &__c_anonymous_ifc_ifcu) -> bool {
unsafe {
self.ifcu_buf == other.ifcu_buf &&
self.ifcu_req == other.ifcu_req
}
}
}

#[cfg(libc_union)]
impl ::fmt::Debug for __c_anonymous_ifc_ifcu {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("ifc_ifcu")
.field("ifcu_buf", unsafe { &self.ifcu_buf })
.field("ifcu_req", unsafe { &self.ifcu_req })
.finish()
}
}

#[cfg(libc_union)]
impl ::hash::Hash for __c_anonymous_ifc_ifcu {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
unsafe { self.ifcu_buf.hash(state) };
unsafe { self.ifcu_req.hash(state) };
}
}

impl PartialEq for ifstat {
fn eq(&self, other: &ifstat) -> bool {
let self_ascii: &[::c_char] = &self.ascii;
Expand Down

0 comments on commit 526cb13

Please sign in to comment.