Skip to content

Commit

Permalink
adding ethhdr type for linux/android for proper packet filtering.
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Jan 12, 2025
1 parent 4abcd81 commit ca59df5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3722,6 +3722,7 @@ epoll_params
epoll_pwait
epoll_wait
erand48
ethhdr
eventfd
eventfd_read
eventfd_write
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub type __u16 = c_ushort;
pub type __s16 = c_short;
pub type __u32 = c_uint;
pub type __s32 = c_int;
pub type __be16 = __u16;

// linux/elf.h

Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub type __u16 = c_ushort;
pub type __s16 = c_short;
pub type __u32 = c_uint;
pub type __s32 = c_int;
pub type __be16 = __u16;

pub type Elf32_Half = u16;
pub type Elf32_Word = u32;
Expand Down
34 changes: 34 additions & 0 deletions src/unix/linux_like/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ s_no_extra_traits! {
pub sigev_notify: c_int,
pub _sigev_un: __c_anonymous_sigev_un,
}

#[repr(packed)]
pub struct ethhdr {
pub h_dest: [c_uchar; crate::ETH_ALEN as usize],
pub h_source: [c_uchar; crate::ETH_ALEN as usize],
pub h_proto: crate::__be16,
}
}

cfg_if! {
Expand Down Expand Up @@ -459,6 +466,33 @@ cfg_if! {
.finish()
}
}

impl Eq for ethhdr {}

impl PartialEq for ethhdr {
fn eq(&self, other: &ethhdr) -> bool {
self.h_dest
.iter()
.zip(other.h_dest.iter())
.all(|(a, b)| a == b)
&& self
.h_source
.iter()
.zip(other.h_source.iter())
.all(|(a, b)| a == b)
&& self.h_proto == other.h_proto
}
}

impl fmt::Debug for ethhdr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ethhdr")
.field("h_dest", &self.h_dest)
.field("h_source", &self.h_source)
.field("h_proto", &{ self.h_proto })
.finish()
}
}
}
}

Expand Down

0 comments on commit ca59df5

Please sign in to comment.