Skip to content

Commit 0fe8625

Browse files
committed
adding ifreq struct for openbsd
1 parent 0dbadb4 commit 0fe8625

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

libc-test/build.rs

+14
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,19 @@ fn test_openbsd(target: &str) {
522522
"sys/param.h",
523523
}
524524

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

libc-test/semver/openbsd.txt

+1
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

+72
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,12 @@ 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+
}
536542
}
537543

538544
impl siginfo_t {
@@ -608,6 +614,18 @@ s_no_extra_traits! {
608614
align: [::c_char; 160],
609615
}
610616

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

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

0 commit comments

Comments
 (0)