Skip to content

Commit 0b34501

Browse files
committed
Ignore padding for sockaddr_nl struct
`nl_pad` field does not contain any actual data, so using it for comparison or hashing doesn't make sense. Instead manually implement extra traits ignoring this field.
1 parent 7d235af commit 0b34501

File tree

3 files changed

+96
-21
lines changed

3 files changed

+96
-21
lines changed

src/fuchsia/mod.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,6 @@ s! {
366366
pub ai_next: *mut addrinfo,
367367
}
368368

369-
pub struct sockaddr_nl {
370-
pub nl_family: ::sa_family_t,
371-
nl_pad: ::c_ushort,
372-
pub nl_pid: u32,
373-
pub nl_groups: u32
374-
}
375-
376369
pub struct sockaddr_ll {
377370
pub sll_family: ::c_ushort,
378371
pub sll_protocol: ::c_ushort,
@@ -971,6 +964,13 @@ s_no_extra_traits! {
971964
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
972965
pad: [::c_long; 4],
973966
}
967+
968+
pub struct sockaddr_nl {
969+
pub nl_family: ::sa_family_t,
970+
nl_pad: ::c_ushort,
971+
pub nl_pid: u32,
972+
pub nl_groups: u32
973+
}
974974
}
975975

976976
cfg_if! {
@@ -1239,6 +1239,31 @@ cfg_if! {
12391239
self.mq_curmsgs.hash(state);
12401240
}
12411241
}
1242+
1243+
impl PartialEq for sockaddr_nl {
1244+
fn eq(&self, other: &sockaddr_nl) -> bool {
1245+
self.nl_family == other.nl_family &&
1246+
self.nl_pid == other.nl_pid &&
1247+
self.nl_groups == other.nl_groups
1248+
}
1249+
}
1250+
impl Eq for sockaddr_nl {}
1251+
impl ::fmt::Debug for sockaddr_nl {
1252+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1253+
f.debug_struct("sockaddr_nl")
1254+
.field("nl_family", &self.nl_family)
1255+
.field("nl_pid", &self.nl_pid)
1256+
.field("nl_groups", &self.nl_groups)
1257+
.finish()
1258+
}
1259+
}
1260+
impl ::hash::Hash for sockaddr_nl {
1261+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1262+
self.nl_family.hash(state);
1263+
self.nl_pid.hash(state);
1264+
self.nl_groups.hash(state);
1265+
}
1266+
}
12421267
}
12431268
}
12441269

src/unix/notbsd/mod.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ s! {
6161
pub ai_next: *mut addrinfo,
6262
}
6363

64-
pub struct sockaddr_nl {
65-
pub nl_family: ::sa_family_t,
66-
nl_pad: ::c_ushort,
67-
pub nl_pid: u32,
68-
pub nl_groups: u32
69-
}
70-
7164
pub struct sockaddr_ll {
7265
pub sll_family: ::c_ushort,
7366
pub sll_protocol: ::c_ushort,
@@ -249,6 +242,13 @@ s_no_extra_traits!{
249242
pub machine: [::c_char; 65],
250243
pub domainname: [::c_char; 65]
251244
}
245+
246+
pub struct sockaddr_nl {
247+
pub nl_family: ::sa_family_t,
248+
nl_pad: ::c_ushort,
249+
pub nl_pid: u32,
250+
pub nl_groups: u32
251+
}
252252
}
253253

254254
cfg_if! {
@@ -394,6 +394,31 @@ cfg_if! {
394394
self.domainname.hash(state);
395395
}
396396
}
397+
398+
impl PartialEq for sockaddr_nl {
399+
fn eq(&self, other: &sockaddr_nl) -> bool {
400+
self.nl_family == other.nl_family &&
401+
self.nl_pid == other.nl_pid &&
402+
self.nl_groups == other.nl_groups
403+
}
404+
}
405+
impl Eq for sockaddr_nl {}
406+
impl ::fmt::Debug for sockaddr_nl {
407+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
408+
f.debug_struct("sockaddr_nl")
409+
.field("nl_family", &self.nl_family)
410+
.field("nl_pid", &self.nl_pid)
411+
.field("nl_groups", &self.nl_groups)
412+
.finish()
413+
}
414+
}
415+
impl ::hash::Hash for sockaddr_nl {
416+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
417+
self.nl_family.hash(state);
418+
self.nl_pid.hash(state);
419+
self.nl_groups.hash(state);
420+
}
421+
}
397422
}
398423
}
399424

src/unix/uclibc/mod.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,6 @@ s! {
8080
pub ai_next: *mut addrinfo,
8181
}
8282

83-
pub struct sockaddr_nl {
84-
pub nl_family: ::sa_family_t,
85-
nl_pad: ::c_ushort,
86-
pub nl_pid: u32,
87-
pub nl_groups: u32
88-
}
89-
9083
pub struct sockaddr_ll {
9184
pub sll_family: ::c_ushort,
9285
pub sll_protocol: ::c_ushort,
@@ -368,6 +361,13 @@ s_no_extra_traits! {
368361
pub mq_curmsgs: ::c_long,
369362
pad: [::c_long; 4]
370363
}
364+
365+
pub struct sockaddr_nl {
366+
pub nl_family: ::sa_family_t,
367+
nl_pad: ::c_ushort,
368+
pub nl_pid: u32,
369+
pub nl_groups: u32
370+
}
371371
}
372372

373373
cfg_if! {
@@ -399,6 +399,31 @@ cfg_if! {
399399
self.mq_curmsgs.hash(state);
400400
}
401401
}
402+
403+
impl PartialEq for sockaddr_nl {
404+
fn eq(&self, other: &sockaddr_nl) -> bool {
405+
self.nl_family == other.nl_family &&
406+
self.nl_pid == other.nl_pid &&
407+
self.nl_groups == other.nl_groups
408+
}
409+
}
410+
impl Eq for sockaddr_nl {}
411+
impl ::fmt::Debug for sockaddr_nl {
412+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
413+
f.debug_struct("sockaddr_nl")
414+
.field("nl_family", &self.nl_family)
415+
.field("nl_pid", &self.nl_pid)
416+
.field("nl_groups", &self.nl_groups)
417+
.finish()
418+
}
419+
}
420+
impl ::hash::Hash for sockaddr_nl {
421+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
422+
self.nl_family.hash(state);
423+
self.nl_pid.hash(state);
424+
self.nl_groups.hash(state);
425+
}
426+
}
402427
}
403428
}
404429

0 commit comments

Comments
 (0)