Skip to content

Commit

Permalink
adding apple ifreq
Browse files Browse the repository at this point in the history
close #3371
  • Loading branch information
devnexen committed Oct 6, 2023
1 parent 017bf5f commit 19ff828
Show file tree
Hide file tree
Showing 3 changed files with 247 additions and 3 deletions.
14 changes: 12 additions & 2 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ fn test_apple(target: &str) {
}

cfg.skip_struct(move |ty| {
if ty.starts_with("__c_anonymous_") {
return true;
}
match ty {
// FIXME: actually a union
"sigval" => true,
Expand All @@ -310,8 +313,13 @@ fn test_apple(target: &str) {
}
});

cfg.skip_type(move |ty| match ty {
_ => false,
cfg.skip_type(move |ty| {
if ty.starts_with("__c_anonymous_") {
return true;
}
match ty {
_ => false,
}
});

cfg.skip_const(move |name| {
Expand Down Expand Up @@ -364,6 +372,8 @@ fn test_apple(target: &str) {
("__darwin_arm_neon_state64", "__v") => true,
// MAXPATHLEN is too big for auto-derive traits on arrays.
("vnode_info_path", "vip_path") => true,
("ifreq", "ifr_ifru") => true,
("ifkpi", "ifk_data") => true,
_ => false,
}
});
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/apple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,8 @@ if_freenameindex
if_msghdr
if_nameindex
ifaddrs
ifkpi
ifreq
image_offset
in6_pktinfo
in_pktinfo
Expand Down
234 changes: 233 additions & 1 deletion src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ s! {
pub struct sockaddr_ndrv {
pub snd_len: ::c_uchar,
pub snd_family: ::c_uchar,
pub snd_name: [::c_uchar; 16] // IFNAMSIZ from if.h
pub snd_name: [::c_uchar; ::IFNAMSIZ],
}

// sys/socket.h
Expand Down Expand Up @@ -1419,6 +1419,52 @@ s_no_extra_traits! {
pub svm_port: ::c_uint,
pub svm_cid: ::c_uint,
}

pub struct ifdevmtu {
pub ifdm_current: ::c_int,
pub ifdm_min: ::c_int,
pub ifdm_max: ::c_int,
}

#[cfg(libc_union)]
pub union __c_anonymous_ifk_data {
pub ifk_ptr: *mut ::c_void,
pub ifk_value: ::c_int,
}

#[cfg_attr(libc_packedN, repr(packed(4)))]
pub struct ifkpi {
pub ifk_module_id: ::c_uint,
pub ifk_type: ::c_uint,
#[cfg(libc_union)]
pub ifk_data: __c_anonymous_ifk_data,
}

#[cfg(libc_union)]
pub union __c_anonymous_ifr_ifru {
pub ifru_addr: ::sockaddr,
pub ifru_dstaddr: ::sockaddr,
pub ifru_broadaddr: ::sockaddr,
pub ifru_flags: ::c_short,
pub ifru_metrics: ::c_int,
pub ifru_mtu: ::c_int,
pub ifru_phys: ::c_int,
pub ifru_media: ::c_int,
pub ifru_intval: ::c_int,
pub ifru_data: *mut ::c_char,
pub ifru_devmtu: ifdevmtu,
pub ifru_kpi: ifkpi,
pub ifru_wake_flags: u32,
pub ifru_route_refcnt: u32,
pub ifru_cap: [::c_int; 2],
pub ifru_functional_type: u32,
}

pub struct ifreq {
pub ifr_name: [::c_char; ::IFNAMSIZ],
#[cfg(libc_union)]
pub ifr_ifru: __c_anonymous_ifr_ifru,
}
}

impl siginfo_t {
Expand Down Expand Up @@ -2767,6 +2813,192 @@ cfg_if! {
svm_cid.hash(state);
}
}

impl PartialEq for ifdevmtu {
fn eq(&self, other: &ifdevmtu) -> bool {
self.ifdm_current == other.ifdm_current
&& self.ifdm_min == other.ifdm_min
&& self.ifdm_max == other.ifdm_max
}
}

impl Eq for ifdevmtu {}

impl ::fmt::Debug for ifdevmtu {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("ifdevmtu")
.field("ifdm_current", &self.ifdm_current)
.field("ifdm_min", &self.ifdm_min)
.field("ifdm_max", &self.ifdm_max)
.finish()
}
}

impl ::hash::Hash for ifdevmtu {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.ifdm_current.hash(state);
self.ifdm_min.hash(state);
self.ifdm_max.hash(state);
}
}

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

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

#[cfg(libc_union)]
impl ::fmt::Debug for __c_anonymous_ifk_data {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("__c_anonymous_ifk_data")
.field("ifk_ptr", unsafe { &self.ifk_ptr })
.field("ifk_value", unsafe { &self.ifk_value })
.finish()
}
}
#[cfg(libc_union)]
impl ::hash::Hash for __c_anonymous_ifk_data {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
unsafe {
self.ifk_ptr.hash(state);
self.ifk_value.hash(state);
}
}
}

impl PartialEq for ifkpi {
fn eq(&self, other: &ifkpi) -> bool {
self.ifk_module_id == other.ifk_module_id
&& self.ifk_type == other.ifk_type
}
}

impl Eq for ifkpi {}

impl ::fmt::Debug for ifkpi {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("ifkpi")
.field("ifk_module_id", &self.ifk_module_id)
.field("ifk_type", &self.ifk_type)
.finish()
}
}

impl ::hash::Hash for ifkpi {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.ifk_module_id.hash(state);
self.ifk_type.hash(state);
#[cfg(libc_union)]
self.ifk_data.hash(state);
}
}

#[cfg(libc_union)]
impl PartialEq for __c_anonymous_ifr_ifru {
fn eq(&self, other: &__c_anonymous_ifr_ifru) -> bool {
unsafe {
self.ifru_addr == other.ifru_addr
&& self.ifru_dstaddr == other.ifru_dstaddr
&& self.ifru_broaddr == other.ifru_broaddr
&& self.ifru_flags == other.ifru_flags
&& self.ifru_metrics == other.ifru_metrics
&& self.ifru_mtu == other.ifru_mtu
&& self.ifru_phys == other.ifru_phys
&& self.ifru_media == other.ifru_media
&& self.ifru_intval == other.ifru_intval
&& self.ifru_data == other.ifru_data
&& self.ifru_devmtu == other.ifru_devmtu
&& self.ifru_kpi == other.ifru_kpi
&& self.ifru_wake_flags == other.ifru_wake_flags
&& self.ifru_route_refcnt == other.ifru_route_refcnt
&& self.ifru_cap.iter().zip(other.ifru_cap.iter()).all(|(a,b)| a == b)
&& self.ifru_functional_type == other.ifru_functional_type
}
}
}

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

#[cfg(libc_union)]
impl ::fmt::Debug for __c_anonymous_ifr_ifru {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("__c_anonymous_ifr_ifru")
.field("ifru_addr", unsafe { &self.ifru_addr })
.field("ifru_dstaddr", unsafe { &self.ifru_dstaddr })
.field("ifru_broaddr", unsafe { &self.ifru_broaddr })
.field("ifru_flags", unsafe { &self.ifru_flags })
.field("ifru_metrics", unsafe { &self.ifru_metrics })
.field("ifru_mtu", unsafe { &self.ifru_mtu })
.field("ifru_phys", unsafe { &self.ifru_phys })
.field("ifru_media", unsafe { &self.ifru_media })
.field("ifru_intval", unsafe { &self.ifru_intval })
.field("ifru_data", unsafe { &self.ifru_data })
.field("ifru_devmtu", unsafe { &self.ifru_devmtu })
.field("ifru_kpi", unsafe { &self.ifru_kpi })
.field("ifru_wake_flags", unsafe { &self.ifru_wake_flags })
.field("ifru_route_refcnt", unsafe { &self.ifru_route_refcnt })
.field("ifru_cap", unsafe { &self.ifru_cap })
.field("ifru_functional_type", unsafe { &self.ifru_functional_type })
.finish()
}
}

#[cfg(libc_union)]
impl ::hash::Hash for ifkpi {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
unsafe {
self.ifru_addr.hash(state);
self.ifru_dstaddr.hash(state);
self.ifru_broaddr.hash(state);
self.ifru_flags.hash(state);
self.ifru_metrics.hash(state);
self.ifru_mtu.hash(state);
self.ifru_phys.hash(state);
self.ifru_media.hash(state);
self.ifru_intval.hash(state);
self.ifru_data.hash(state);
self.ifru_devmtu.hash(state);
self.ifru_kpi.hash(state);
self.ifru_wake_flags.hash(state);
self.ifru_route_refcnt.hash(state);
self.ifru_cap.hash(state);
self.ifru_functional_type.hash(state);
}
}
}

impl PartialEq for ifreq {
fn eq(&self, other: &ifreq) -> bool {
self.ifr_name == other.ifr_name
}
}

impl Eq for ifreq {}

impl ::fmt::Debug for ifreq {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("ifreq")
.field("ifr_name", &self.ifr_name)
.finish()
}
}

impl ::hash::Hash for ifreq {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.ifr_name.hash(state);
#[cfg(libc_union)]
self.ifr_ifru.hash(state);
}
}
}
}

Expand Down

0 comments on commit 19ff828

Please sign in to comment.