Skip to content

Commit 94f06b3

Browse files
committed
adding ethhdr type for linux/android for proper packet filtering.
[ref](https://docs.huihoo.com/doxygen/linux/kernel/3.7/structethhdr.html)
1 parent 5a9e1db commit 94f06b3

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

libc-test/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,8 @@ fn test_android(target: &str) {
21472147
(struct_ == "sigaction" && field == "sa_sigaction") ||
21482148
// signalfd had SIGSYS fields added in Android 4.19, but CI does not have that version yet.
21492149
(struct_ == "signalfd_siginfo" && field == "ssi_call_addr") ||
2150+
// FIXME: `h_proto` is of type __be16 big endian version of __u16
2151+
(struct_ == "ethhdr" && field == "h_proto") ||
21502152
// FIXME(android): Seems the type has been changed on NDK r26b
21512153
(struct_ == "flock64" && (field == "l_start" || field == "l_len"))
21522154
});

libc-test/semver/android.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,6 +3423,7 @@ epoll_create1
34233423
epoll_ctl
34243424
epoll_event
34253425
epoll_wait
3426+
ethhdr
34263427
eventfd
34273428
eventfd_read
34283429
eventfd_write

libc-test/semver/linux-gnu.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ dlvsym
593593
eaccess
594594
endutxent
595595
epoll_pwait2
596+
ethhdr
596597
euidaccess
597598
execveat
598599
explicit_bzero

src/unix/linux_like/android/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub type __u16 = c_ushort;
4747
pub type __s16 = c_short;
4848
pub type __u32 = c_uint;
4949
pub type __s32 = c_int;
50+
pub type __be16 = __u16;
5051

5152
// linux/elf.h
5253

@@ -620,6 +621,15 @@ s_no_extra_traits! {
620621
pub ifc_len: c_int,
621622
pub ifc_ifcu: __c_anonymous_ifc_ifcu,
622623
}
624+
625+
// linux/if_ether.h
626+
627+
#[repr(C, packed)]
628+
pub struct ethhdr {
629+
pub h_dest: [c_uchar; crate::ETH_ALEN as usize],
630+
pub h_source: [c_uchar; crate::ETH_ALEN as usize],
631+
pub h_proto: crate::__be16,
632+
}
623633
}
624634

625635
cfg_if! {

src/unix/linux_like/linux/gnu/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub type __rlimit_resource_t = c_uint;
77
pub type Lmid_t = c_long;
88
pub type regoff_t = c_int;
99
pub type __kernel_rwf_t = c_int;
10+
pub type __be16 = crate::__u16;
1011

1112
cfg_if! {
1213
if #[cfg(doc)] {
@@ -379,6 +380,15 @@ s_no_extra_traits! {
379380
__pad: [c_char; 4],
380381
__glibc_reserved: [c_char; 32],
381382
}
383+
384+
// linux/if_ether.h
385+
386+
#[repr(C, packed)]
387+
pub struct ethhdr {
388+
pub h_dest: [c_uchar; crate::ETH_ALEN as usize],
389+
pub h_source: [c_uchar; crate::ETH_ALEN as usize],
390+
pub h_proto: crate::__be16,
391+
}
382392
}
383393

384394
// Internal, for casts to access union fields

0 commit comments

Comments
 (0)