Skip to content

Commit 9775467

Browse files
committed
Make ifaddrs.ifa_ifu an union
1 parent 442c0de commit 9775467

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

libc-test/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,6 +2778,9 @@ fn test_emscripten(target: &str) {
27782778
});
27792779

27802780
cfg.skip_struct(move |ty| {
2781+
if ty.starts_with("__c_anonymous_") {
2782+
return true;
2783+
}
27812784
match ty {
27822785
// FIXME: It was removed in
27832786
// emscripten-core/emscripten@953e414

src/fuchsia/mod.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ s! {
463463
pub ifa_flags: ::c_uint,
464464
pub ifa_addr: *mut ::sockaddr,
465465
pub ifa_netmask: *mut ::sockaddr,
466-
pub ifa_ifu: *mut ::sockaddr, // FIXME This should be a union
467-
pub ifa_data: *mut ::c_void
466+
pub ifa_ifu: __c_anonymous_ifa_ifu,
467+
pub ifa_data: *mut ::c_void,
468468
}
469469

470470
pub struct passwd {
@@ -979,6 +979,11 @@ s_no_extra_traits! {
979979
pub sival_int: ::int,
980980
pub sival_ptr: *mut ::c_void,
981981
}
982+
983+
pub union __c_anonymous_ifa_ifu {
984+
ifu_broadaddr: *mut sockaddr,
985+
ifu_dstaddr: *mut sockaddr,
986+
}
982987
}
983988

984989
cfg_if! {
@@ -1325,6 +1330,25 @@ cfg_if! {
13251330
unsafe { (self.sival_ptr as usize).hash(state) };
13261331
}
13271332
}
1333+
1334+
impl PartialEq for __c_anonymous_ifa_ifu {
1335+
fn eq(&self, other: &__c_anonymous_ifa_ifu) -> bool {
1336+
unsafe { self.ifu_dstaddr == other.ifu_dstaddr }
1337+
}
1338+
}
1339+
impl Eq for __c_anonymous_ifa_ifu {}
1340+
impl ::fmt::Debug for __c_anonymous_ifa_ifu {
1341+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1342+
f.debug_struct("ifa_ifu")
1343+
.field("ifu_dstaddr", unsafe { &self.ifu_dstaddr } )
1344+
.finish()
1345+
}
1346+
}
1347+
impl ::hash::Hash for __c_anonymous_ifa_ifu {
1348+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1349+
unsafe { self.ifu_dstaddr.hash(state) };
1350+
}
1351+
}
13281352
}
13291353
}
13301354

src/unix/linux_like/mod.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ s! {
160160
pub ifa_flags: ::c_uint,
161161
pub ifa_addr: *mut ::sockaddr,
162162
pub ifa_netmask: *mut ::sockaddr,
163-
pub ifa_ifu: *mut ::sockaddr, // FIXME This should be a union
164-
pub ifa_data: *mut ::c_void
163+
pub ifa_ifu: __c_anonymous_ifa_ifu,
164+
pub ifa_data: *mut ::c_void,
165165
}
166166

167167
pub struct in6_rtmsg {
@@ -255,6 +255,11 @@ s_no_extra_traits! {
255255
#[cfg(target_pointer_width = "32")]
256256
__unused1: [::c_int; 12]
257257
}
258+
259+
pub union __c_anonymous_ifa_ifu {
260+
ifu_broadaddr: *mut sockaddr,
261+
ifu_dstaddr: *mut sockaddr,
262+
}
258263
}
259264

260265
cfg_if! {
@@ -430,6 +435,25 @@ cfg_if! {
430435
self.sigev_notify_thread_id.hash(state);
431436
}
432437
}
438+
439+
impl PartialEq for __c_anonymous_ifa_ifu {
440+
fn eq(&self, other: &__c_anonymous_ifa_ifu) -> bool {
441+
unsafe { self.ifu_dstaddr == other.ifu_dstaddr }
442+
}
443+
}
444+
impl Eq for __c_anonymous_ifa_ifu {}
445+
impl ::fmt::Debug for __c_anonymous_ifa_ifu {
446+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
447+
f.debug_struct("ifa_ifu")
448+
.field("ifu_dstaddr", unsafe { &self.ifu_dstaddr } )
449+
.finish()
450+
}
451+
}
452+
impl ::hash::Hash for __c_anonymous_ifa_ifu {
453+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
454+
unsafe { self.ifu_dstaddr.hash(state) };
455+
}
456+
}
433457
}
434458
}
435459

0 commit comments

Comments
 (0)