Skip to content

Commit 19ff828

Browse files
committed
adding apple ifreq
close #3371
1 parent 017bf5f commit 19ff828

File tree

3 files changed

+247
-3
lines changed

3 files changed

+247
-3
lines changed

libc-test/build.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ fn test_apple(target: &str) {
299299
}
300300

301301
cfg.skip_struct(move |ty| {
302+
if ty.starts_with("__c_anonymous_") {
303+
return true;
304+
}
302305
match ty {
303306
// FIXME: actually a union
304307
"sigval" => true,
@@ -310,8 +313,13 @@ fn test_apple(target: &str) {
310313
}
311314
});
312315

313-
cfg.skip_type(move |ty| match ty {
314-
_ => false,
316+
cfg.skip_type(move |ty| {
317+
if ty.starts_with("__c_anonymous_") {
318+
return true;
319+
}
320+
match ty {
321+
_ => false,
322+
}
315323
});
316324

317325
cfg.skip_const(move |name| {
@@ -364,6 +372,8 @@ fn test_apple(target: &str) {
364372
("__darwin_arm_neon_state64", "__v") => true,
365373
// MAXPATHLEN is too big for auto-derive traits on arrays.
366374
("vnode_info_path", "vip_path") => true,
375+
("ifreq", "ifr_ifru") => true,
376+
("ifkpi", "ifk_data") => true,
367377
_ => false,
368378
}
369379
});

libc-test/semver/apple.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,8 @@ if_freenameindex
19571957
if_msghdr
19581958
if_nameindex
19591959
ifaddrs
1960+
ifkpi
1961+
ifreq
19601962
image_offset
19611963
in6_pktinfo
19621964
in_pktinfo

src/unix/bsd/apple/mod.rs

+233-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ s! {
797797
pub struct sockaddr_ndrv {
798798
pub snd_len: ::c_uchar,
799799
pub snd_family: ::c_uchar,
800-
pub snd_name: [::c_uchar; 16] // IFNAMSIZ from if.h
800+
pub snd_name: [::c_uchar; ::IFNAMSIZ],
801801
}
802802

803803
// sys/socket.h
@@ -1419,6 +1419,52 @@ s_no_extra_traits! {
14191419
pub svm_port: ::c_uint,
14201420
pub svm_cid: ::c_uint,
14211421
}
1422+
1423+
pub struct ifdevmtu {
1424+
pub ifdm_current: ::c_int,
1425+
pub ifdm_min: ::c_int,
1426+
pub ifdm_max: ::c_int,
1427+
}
1428+
1429+
#[cfg(libc_union)]
1430+
pub union __c_anonymous_ifk_data {
1431+
pub ifk_ptr: *mut ::c_void,
1432+
pub ifk_value: ::c_int,
1433+
}
1434+
1435+
#[cfg_attr(libc_packedN, repr(packed(4)))]
1436+
pub struct ifkpi {
1437+
pub ifk_module_id: ::c_uint,
1438+
pub ifk_type: ::c_uint,
1439+
#[cfg(libc_union)]
1440+
pub ifk_data: __c_anonymous_ifk_data,
1441+
}
1442+
1443+
#[cfg(libc_union)]
1444+
pub union __c_anonymous_ifr_ifru {
1445+
pub ifru_addr: ::sockaddr,
1446+
pub ifru_dstaddr: ::sockaddr,
1447+
pub ifru_broadaddr: ::sockaddr,
1448+
pub ifru_flags: ::c_short,
1449+
pub ifru_metrics: ::c_int,
1450+
pub ifru_mtu: ::c_int,
1451+
pub ifru_phys: ::c_int,
1452+
pub ifru_media: ::c_int,
1453+
pub ifru_intval: ::c_int,
1454+
pub ifru_data: *mut ::c_char,
1455+
pub ifru_devmtu: ifdevmtu,
1456+
pub ifru_kpi: ifkpi,
1457+
pub ifru_wake_flags: u32,
1458+
pub ifru_route_refcnt: u32,
1459+
pub ifru_cap: [::c_int; 2],
1460+
pub ifru_functional_type: u32,
1461+
}
1462+
1463+
pub struct ifreq {
1464+
pub ifr_name: [::c_char; ::IFNAMSIZ],
1465+
#[cfg(libc_union)]
1466+
pub ifr_ifru: __c_anonymous_ifr_ifru,
1467+
}
14221468
}
14231469

14241470
impl siginfo_t {
@@ -2767,6 +2813,192 @@ cfg_if! {
27672813
svm_cid.hash(state);
27682814
}
27692815
}
2816+
2817+
impl PartialEq for ifdevmtu {
2818+
fn eq(&self, other: &ifdevmtu) -> bool {
2819+
self.ifdm_current == other.ifdm_current
2820+
&& self.ifdm_min == other.ifdm_min
2821+
&& self.ifdm_max == other.ifdm_max
2822+
}
2823+
}
2824+
2825+
impl Eq for ifdevmtu {}
2826+
2827+
impl ::fmt::Debug for ifdevmtu {
2828+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
2829+
f.debug_struct("ifdevmtu")
2830+
.field("ifdm_current", &self.ifdm_current)
2831+
.field("ifdm_min", &self.ifdm_min)
2832+
.field("ifdm_max", &self.ifdm_max)
2833+
.finish()
2834+
}
2835+
}
2836+
2837+
impl ::hash::Hash for ifdevmtu {
2838+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
2839+
self.ifdm_current.hash(state);
2840+
self.ifdm_min.hash(state);
2841+
self.ifdm_max.hash(state);
2842+
}
2843+
}
2844+
2845+
#[cfg(libc_union)]
2846+
impl PartialEq for __c_anonymous_ifk_data {
2847+
fn eq(&self, other: &__c_anonymous_ifk_data) -> bool {
2848+
unsafe {
2849+
self.ifk_ptr == other.ifk_ptr
2850+
&& self.ifk_value == other.ifk_value
2851+
}
2852+
}
2853+
}
2854+
2855+
#[cfg(libc_union)]
2856+
impl Eq for __c_anonymous_ifk_data {}
2857+
2858+
#[cfg(libc_union)]
2859+
impl ::fmt::Debug for __c_anonymous_ifk_data {
2860+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
2861+
f.debug_struct("__c_anonymous_ifk_data")
2862+
.field("ifk_ptr", unsafe { &self.ifk_ptr })
2863+
.field("ifk_value", unsafe { &self.ifk_value })
2864+
.finish()
2865+
}
2866+
}
2867+
#[cfg(libc_union)]
2868+
impl ::hash::Hash for __c_anonymous_ifk_data {
2869+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
2870+
unsafe {
2871+
self.ifk_ptr.hash(state);
2872+
self.ifk_value.hash(state);
2873+
}
2874+
}
2875+
}
2876+
2877+
impl PartialEq for ifkpi {
2878+
fn eq(&self, other: &ifkpi) -> bool {
2879+
self.ifk_module_id == other.ifk_module_id
2880+
&& self.ifk_type == other.ifk_type
2881+
}
2882+
}
2883+
2884+
impl Eq for ifkpi {}
2885+
2886+
impl ::fmt::Debug for ifkpi {
2887+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
2888+
f.debug_struct("ifkpi")
2889+
.field("ifk_module_id", &self.ifk_module_id)
2890+
.field("ifk_type", &self.ifk_type)
2891+
.finish()
2892+
}
2893+
}
2894+
2895+
impl ::hash::Hash for ifkpi {
2896+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
2897+
self.ifk_module_id.hash(state);
2898+
self.ifk_type.hash(state);
2899+
#[cfg(libc_union)]
2900+
self.ifk_data.hash(state);
2901+
}
2902+
}
2903+
2904+
#[cfg(libc_union)]
2905+
impl PartialEq for __c_anonymous_ifr_ifru {
2906+
fn eq(&self, other: &__c_anonymous_ifr_ifru) -> bool {
2907+
unsafe {
2908+
self.ifru_addr == other.ifru_addr
2909+
&& self.ifru_dstaddr == other.ifru_dstaddr
2910+
&& self.ifru_broaddr == other.ifru_broaddr
2911+
&& self.ifru_flags == other.ifru_flags
2912+
&& self.ifru_metrics == other.ifru_metrics
2913+
&& self.ifru_mtu == other.ifru_mtu
2914+
&& self.ifru_phys == other.ifru_phys
2915+
&& self.ifru_media == other.ifru_media
2916+
&& self.ifru_intval == other.ifru_intval
2917+
&& self.ifru_data == other.ifru_data
2918+
&& self.ifru_devmtu == other.ifru_devmtu
2919+
&& self.ifru_kpi == other.ifru_kpi
2920+
&& self.ifru_wake_flags == other.ifru_wake_flags
2921+
&& self.ifru_route_refcnt == other.ifru_route_refcnt
2922+
&& self.ifru_cap.iter().zip(other.ifru_cap.iter()).all(|(a,b)| a == b)
2923+
&& self.ifru_functional_type == other.ifru_functional_type
2924+
}
2925+
}
2926+
}
2927+
2928+
#[cfg(libc_union)]
2929+
impl Eq for __c_anonymous_ifr_ifru {}
2930+
2931+
#[cfg(libc_union)]
2932+
impl ::fmt::Debug for __c_anonymous_ifr_ifru {
2933+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
2934+
f.debug_struct("__c_anonymous_ifr_ifru")
2935+
.field("ifru_addr", unsafe { &self.ifru_addr })
2936+
.field("ifru_dstaddr", unsafe { &self.ifru_dstaddr })
2937+
.field("ifru_broaddr", unsafe { &self.ifru_broaddr })
2938+
.field("ifru_flags", unsafe { &self.ifru_flags })
2939+
.field("ifru_metrics", unsafe { &self.ifru_metrics })
2940+
.field("ifru_mtu", unsafe { &self.ifru_mtu })
2941+
.field("ifru_phys", unsafe { &self.ifru_phys })
2942+
.field("ifru_media", unsafe { &self.ifru_media })
2943+
.field("ifru_intval", unsafe { &self.ifru_intval })
2944+
.field("ifru_data", unsafe { &self.ifru_data })
2945+
.field("ifru_devmtu", unsafe { &self.ifru_devmtu })
2946+
.field("ifru_kpi", unsafe { &self.ifru_kpi })
2947+
.field("ifru_wake_flags", unsafe { &self.ifru_wake_flags })
2948+
.field("ifru_route_refcnt", unsafe { &self.ifru_route_refcnt })
2949+
.field("ifru_cap", unsafe { &self.ifru_cap })
2950+
.field("ifru_functional_type", unsafe { &self.ifru_functional_type })
2951+
.finish()
2952+
}
2953+
}
2954+
2955+
#[cfg(libc_union)]
2956+
impl ::hash::Hash for ifkpi {
2957+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
2958+
unsafe {
2959+
self.ifru_addr.hash(state);
2960+
self.ifru_dstaddr.hash(state);
2961+
self.ifru_broaddr.hash(state);
2962+
self.ifru_flags.hash(state);
2963+
self.ifru_metrics.hash(state);
2964+
self.ifru_mtu.hash(state);
2965+
self.ifru_phys.hash(state);
2966+
self.ifru_media.hash(state);
2967+
self.ifru_intval.hash(state);
2968+
self.ifru_data.hash(state);
2969+
self.ifru_devmtu.hash(state);
2970+
self.ifru_kpi.hash(state);
2971+
self.ifru_wake_flags.hash(state);
2972+
self.ifru_route_refcnt.hash(state);
2973+
self.ifru_cap.hash(state);
2974+
self.ifru_functional_type.hash(state);
2975+
}
2976+
}
2977+
}
2978+
2979+
impl PartialEq for ifreq {
2980+
fn eq(&self, other: &ifreq) -> bool {
2981+
self.ifr_name == other.ifr_name
2982+
}
2983+
}
2984+
2985+
impl Eq for ifreq {}
2986+
2987+
impl ::fmt::Debug for ifreq {
2988+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
2989+
f.debug_struct("ifreq")
2990+
.field("ifr_name", &self.ifr_name)
2991+
.finish()
2992+
}
2993+
}
2994+
2995+
impl ::hash::Hash for ifreq {
2996+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
2997+
self.ifr_name.hash(state);
2998+
#[cfg(libc_union)]
2999+
self.ifr_ifru.hash(state);
3000+
}
3001+
}
27703002
}
27713003
}
27723004

0 commit comments

Comments
 (0)