Skip to content

Commit 31d0fbb

Browse files
committed
Make ifaddrs.ifa_ifu an union
1 parent c5c79b2 commit 31d0fbb

File tree

3 files changed

+55
-16
lines changed

3 files changed

+55
-16
lines changed

libc-test/build.rs

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

978978
cfg.skip_field_type(move |struct_, field| {
979-
// This is a weird union, don't check the type.
980-
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
981979
// sighandler_t type is super weird
982980
(struct_ == "sigaction" && field == "sa_sigaction") ||
983981
// aio_buf is "volatile void*" and Rust doesn't understand volatile
@@ -1178,8 +1176,6 @@ fn test_dragonflybsd(target: &str) {
11781176
});
11791177

11801178
cfg.skip_field_type(move |struct_, field| {
1181-
// This is a weird union, don't check the type.
1182-
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
11831179
// sighandler_t type is super weird
11841180
(struct_ == "sigaction" && field == "sa_sigaction") ||
11851181
// aio_buf is "volatile void*" and Rust doesn't understand volatile
@@ -1510,11 +1506,6 @@ fn test_android(target: &str) {
15101506
}
15111507
});
15121508

1513-
cfg.skip_field_type(move |struct_, field| {
1514-
// This is a weird union, don't check the type.
1515-
struct_ == "ifaddrs" && field == "ifa_ifu"
1516-
});
1517-
15181509
cfg.skip_field(move |struct_, field| {
15191510
// this is actually a union on linux, so we can't represent it well and
15201511
// just insert some padding.
@@ -1991,6 +1982,9 @@ fn test_emscripten(target: &str) {
19911982
});
19921983

19931984
cfg.skip_struct(move |ty| {
1985+
if ty.starts_with("__c_anonymous_") {
1986+
return true;
1987+
}
19941988
match ty {
19951989
// FIXME: It was removed in
19961990
// emscripten-core/emscripten@953e414
@@ -2034,9 +2028,6 @@ fn test_emscripten(target: &str) {
20342028
});
20352029

20362030
cfg.skip_field_type(move |struct_, field| {
2037-
// This is a weird union, don't check the type.
2038-
// FIXME: is this necessary?
2039-
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
20402031
// sighandler_t type is super weird
20412032
// FIXME: is this necessary?
20422033
(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

0 commit comments

Comments
 (0)