Skip to content

Commit bd46159

Browse files
committed
Auto merge of #3384 - devnexen:ifreq_openbsd, r=JohnTitor
adding ifreq struct for openbsd
2 parents ebf01ce + 9f5ee91 commit bd46159

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

libc-test/build.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,19 @@ fn test_openbsd(target: &str) {
523523
"sys/param.h",
524524
}
525525

526+
cfg.skip_type(move |ty| {
527+
if ty.starts_with("__c_anonymous_") {
528+
return true;
529+
}
530+
match ty {
531+
_ => false,
532+
}
533+
});
534+
526535
cfg.skip_struct(move |ty| {
536+
if ty.starts_with("__c_anonymous_") {
537+
return true;
538+
}
527539
match ty {
528540
// FIXME: actually a union
529541
"sigval" => true,
@@ -597,6 +609,8 @@ fn test_openbsd(target: &str) {
597609
// conflicting with `p_type` macro from <resolve.h>.
598610
("Elf32_Phdr", "p_type") => true,
599611
("Elf64_Phdr", "p_type") => true,
612+
// ifr_ifru is defined is an union
613+
("ifreq", "ifr_ifru") => true,
600614
_ => false,
601615
}
602616
});

libc-test/semver/openbsd.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,7 @@ if_freenameindex
10831083
if_msghdr
10841084
if_nameindex
10851085
ifaddrs
1086+
ifreq
10861087
in6_pktinfo
10871088
initgroups
10881089
ip_mreqn

src/unix/bsd/netbsdlike/openbsd/mod.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,14 @@ s! {
533533
pub key: *mut ::c_char,
534534
pub data: *mut ::c_void,
535535
}
536+
537+
pub struct ifreq {
538+
pub ifr_name: [::c_char; ::IFNAMSIZ],
539+
#[cfg(libc_union)]
540+
pub ifr_ifru: __c_anonymous_ifr_ifru,
541+
#[cfg(not(libc_union))]
542+
pub ifr_ifru: ::sockaddr,
543+
}
536544
}
537545

538546
impl siginfo_t {
@@ -608,6 +616,18 @@ s_no_extra_traits! {
608616
align: [::c_char; 160],
609617
}
610618

619+
#[cfg(libc_union)]
620+
pub union __c_anonymous_ifr_ifru {
621+
pub ifru_addr: ::sockaddr,
622+
pub ifru_dstaddr: ::sockaddr,
623+
pub ifru_broadaddr: ::sockaddr,
624+
pub ifru_flags: ::c_short,
625+
pub ifru_metric: ::c_int,
626+
pub ifru_vnetid: i64,
627+
pub ifru_media: u64,
628+
pub ifru_data: *mut ::c_char,
629+
pub ifru_index: ::c_uint,
630+
}
611631
}
612632

613633
cfg_if! {
@@ -814,6 +834,60 @@ cfg_if! {
814834
unsafe { self.align.hash(state) };
815835
}
816836
}
837+
838+
#[cfg(libc_union)]
839+
impl PartialEq for __c_anonymous_ifr_ifru {
840+
fn eq(&self, other: &__c_anonymous_ifr_ifru) -> bool {
841+
unsafe {
842+
self.ifru_addr == other.ifru_addr
843+
&& self.ifru_dstaddr == other.ifru_dstaddr
844+
&& self.ifru_broadaddr == other.ifru_broadaddr
845+
&& self.ifru_flags == other.ifru_flags
846+
&& self.ifru_metric == other.ifru_metric
847+
&& self.ifru_vnetid == other.ifru_vnetid
848+
&& self.ifru_media == other.ifru_media
849+
&& self.ifru_data == other.ifru_data
850+
&& self.ifru_index == other.ifru_index
851+
}
852+
}
853+
}
854+
855+
#[cfg(libc_union)]
856+
impl Eq for __c_anonymous_ifr_ifru {}
857+
858+
#[cfg(libc_union)]
859+
impl ::fmt::Debug for __c_anonymous_ifr_ifru {
860+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
861+
f.debug_struct("__c_anonymous_ifr_ifru")
862+
.field("ifru_addr", unsafe { &self.ifru_addr })
863+
.field("ifru_dstaddr", unsafe { &self.ifru_dstaddr })
864+
.field("ifru_broadaddr", unsafe { &self.ifru_broadaddr })
865+
.field("ifru_flags", unsafe { &self.ifru_flags })
866+
.field("ifru_metric", unsafe { &self.ifru_metric })
867+
.field("ifru_vnetid", unsafe { &self.ifru_vnetid })
868+
.field("ifru_media", unsafe { &self.ifru_media })
869+
.field("ifru_data", unsafe { &self.ifru_data })
870+
.field("ifru_index", unsafe { &self.ifru_index })
871+
.finish()
872+
}
873+
}
874+
875+
#[cfg(libc_union)]
876+
impl ::hash::Hash for __c_anonymous_ifr_ifru {
877+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
878+
unsafe {
879+
self.ifru_addr.hash(state);
880+
self.ifru_dstaddr.hash(state);
881+
self.ifru_broadaddr.hash(state);
882+
self.ifru_flags.hash(state);
883+
self.ifru_metric.hash(state);
884+
self.ifru_vnetid.hash(state);
885+
self.ifru_media.hash(state);
886+
self.ifru_data.hash(state);
887+
self.ifru_index.hash(state);
888+
}
889+
}
890+
}
817891
}
818892
}
819893

0 commit comments

Comments
 (0)