Skip to content

Commit 933263e

Browse files
committed
Make ifaddrs.ifa_ifu an union
1 parent db7918b commit 933263e

File tree

4 files changed

+81
-18
lines changed

4 files changed

+81
-18
lines changed

libc-test/build.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,6 @@ fn test_netbsd(target: &str) {
973973
});
974974

975975
cfg.skip_field_type(move |struct_, field| {
976-
// This is a weird union, don't check the type.
977-
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
978976
// sighandler_t type is super weird
979977
(struct_ == "sigaction" && field == "sa_sigaction") ||
980978
// aio_buf is "volatile void*" and Rust doesn't understand volatile
@@ -1174,8 +1172,6 @@ fn test_dragonflybsd(target: &str) {
11741172
});
11751173

11761174
cfg.skip_field_type(move |struct_, field| {
1177-
// This is a weird union, don't check the type.
1178-
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
11791175
// sighandler_t type is super weird
11801176
(struct_ == "sigaction" && field == "sa_sigaction") ||
11811177
// aio_buf is "volatile void*" and Rust doesn't understand volatile
@@ -1506,11 +1502,6 @@ fn test_android(target: &str) {
15061502
}
15071503
});
15081504

1509-
cfg.skip_field_type(move |struct_, field| {
1510-
// This is a weird union, don't check the type.
1511-
struct_ == "ifaddrs" && field == "ifa_ifu"
1512-
});
1513-
15141505
cfg.skip_field(move |struct_, field| {
15151506
// this is actually a union on linux, so we can't represent it well and
15161507
// just insert some padding.
@@ -1986,6 +1977,9 @@ fn test_emscripten(target: &str) {
19861977
});
19871978

19881979
cfg.skip_struct(move |ty| {
1980+
if ty.starts_with("__c_anonymous_") {
1981+
return true;
1982+
}
19891983
match ty {
19901984
// FIXME: It was removed in
19911985
// emscripten-core/emscripten@953e414
@@ -2029,9 +2023,6 @@ fn test_emscripten(target: &str) {
20292023
});
20302024

20312025
cfg.skip_field_type(move |struct_, field| {
2032-
// This is a weird union, don't check the type.
2033-
// FIXME: is this necessary?
2034-
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
20352026
// sighandler_t type is super weird
20362027
// FIXME: is this necessary?
20372028
(struct_ == "sigaction" && field == "sa_sigaction") ||

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 {
@@ -974,6 +974,11 @@ s_no_extra_traits! {
974974
pub sival_int: ::int,
975975
pub sival_ptr: *mut ::c_void,
976976
}
977+
978+
pub union __c_anonymous_ifa_ifu {
979+
ifu_broadaddr: *mut sockaddr,
980+
ifu_dstaddr: *mut sockaddr,
981+
}
977982
}
978983

979984
cfg_if! {
@@ -1320,6 +1325,25 @@ cfg_if! {
13201325
unsafe { (self.sival_ptr as usize).hash(state) };
13211326
}
13221327
}
1328+
1329+
impl PartialEq for __c_anonymous_ifa_ifu {
1330+
fn eq(&self, other: &__c_anonymous_ifa_ifu) -> bool {
1331+
unsafe { self.ifu_dstaddr == other.ifu_dstaddr }
1332+
}
1333+
}
1334+
impl Eq for __c_anonymous_ifa_ifu {}
1335+
impl ::fmt::Debug for __c_anonymous_ifa_ifu {
1336+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1337+
f.debug_struct("ifa_ifu")
1338+
.field("ifu_dstaddr", unsafe { &self.ifu_dstaddr } )
1339+
.finish()
1340+
}
1341+
}
1342+
impl ::hash::Hash for __c_anonymous_ifa_ifu {
1343+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1344+
unsafe { self.ifu_dstaddr.hash(state) };
1345+
}
1346+
}
13231347
}
13241348
}
13251349

src/unix/linux_like/mod.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ s! {
157157
pub ifa_flags: ::c_uint,
158158
pub ifa_addr: *mut ::sockaddr,
159159
pub ifa_netmask: *mut ::sockaddr,
160-
pub ifa_ifu: *mut ::sockaddr, // FIXME This should be a union
161-
pub ifa_data: *mut ::c_void
160+
pub ifa_ifu: __c_anonymous_ifa_ifu,
161+
pub ifa_data: *mut ::c_void,
162162
}
163163

164164
pub struct in6_rtmsg {
@@ -252,6 +252,11 @@ s_no_extra_traits! {
252252
#[cfg(target_pointer_width = "32")]
253253
__unused1: [::c_int; 12]
254254
}
255+
256+
pub union __c_anonymous_ifa_ifu {
257+
ifu_broadaddr: *mut sockaddr,
258+
ifu_dstaddr: *mut sockaddr,
259+
}
255260
}
256261

257262
cfg_if! {
@@ -427,6 +432,25 @@ cfg_if! {
427432
self.sigev_notify_thread_id.hash(state);
428433
}
429434
}
435+
436+
impl PartialEq for __c_anonymous_ifa_ifu {
437+
fn eq(&self, other: &__c_anonymous_ifa_ifu) -> bool {
438+
unsafe { self.ifu_dstaddr == other.ifu_dstaddr }
439+
}
440+
}
441+
impl Eq for __c_anonymous_ifa_ifu {}
442+
impl ::fmt::Debug for __c_anonymous_ifa_ifu {
443+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
444+
f.debug_struct("ifa_ifu")
445+
.field("ifu_dstaddr", unsafe { &self.ifu_dstaddr } )
446+
.finish()
447+
}
448+
}
449+
impl ::hash::Hash for __c_anonymous_ifa_ifu {
450+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
451+
unsafe { self.ifu_dstaddr.hash(state) };
452+
}
453+
}
430454
}
431455
}
432456

src/unix/uclibc/mod.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ s! {
184184
pub ifa_flags: ::c_uint,
185185
pub ifa_addr: *mut ::sockaddr,
186186
pub ifa_netmask: *mut ::sockaddr,
187-
pub ifa_ifu: *mut ::sockaddr, // FIXME This should be a union
188-
pub ifa_data: *mut ::c_void
187+
pub ifa_ifu: __c_anonymous_ifa_ifu,
188+
pub ifa_data: *mut ::c_void,
189189
}
190190

191191
pub struct pthread_rwlockattr_t {
@@ -436,6 +436,11 @@ s_no_extra_traits! {
436436
#[cfg(target_pointer_width = "32")]
437437
__unused1: [::c_int; 12]
438438
}
439+
440+
pub union __c_anonymous_ifa_ifu {
441+
ifu_broadaddr: *mut sockaddr,
442+
ifu_dstaddr: *mut sockaddr,
443+
}
439444
}
440445

441446
cfg_if! {
@@ -522,6 +527,25 @@ cfg_if! {
522527
self.sigev_notify_thread_id.hash(state);
523528
}
524529
}
530+
531+
impl PartialEq for __c_anonymous_ifa_ifu {
532+
fn eq(&self, other: &__c_anonymous_ifa_ifu) -> bool {
533+
unsafe { self.ifu_dstaddr == other.ifu_dstaddr }
534+
}
535+
}
536+
impl Eq for __c_anonymous_ifa_ifu {}
537+
impl ::fmt::Debug for __c_anonymous_ifa_ifu {
538+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
539+
f.debug_struct("ifa_ifu")
540+
.field("ifu_dstaddr", unsafe { &self.ifu_dstaddr } )
541+
.finish()
542+
}
543+
}
544+
impl ::hash::Hash for __c_anonymous_ifa_ifu {
545+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
546+
unsafe { self.ifu_dstaddr.hash(state) };
547+
}
548+
}
525549
}
526550
}
527551

0 commit comments

Comments
 (0)