shellrow / netdev

Cross-platform library for network interface and gateway. Written in Rust.
MIT License
69 stars 13 forks source link

Fails to build on FreeBSD #49

Closed madisonblue closed 1 year ago

madisonblue commented 1 year ago

Hello,

When I try to build the crate on FreeBSD 13.2 this error pops up(it works just fine on Linux):

default-net-0.20.0/src/bpf/binding.rs:82:1
   |
69 | pub struct bpf_hdr {
   | ------------------ previous definition of the type `bpf_hdr` here
...
82 | pub struct bpf_hdr {
   | ^^^^^^^^^^^^^^^^^^ `bpf_hdr` redefined here
   |
   = note: `bpf_hdr` must be defined only once in the type namespace of this module

There's two distinct definitions of that struct so I assume one applies to some OS(es) but not others

One idea would be to remove

pub struct bpf_hdr {
    pub bh_tstamp: libc::timeval,
    pub bh_caplen: u32,
    pub bh_datalen: u32,
    pub bh_hdrlen: libc::c_ushort,
}

and to add something like this?

#[repr(C)]
pub struct bpf_hdr {
    #[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
    pub bh_tstamp: libc::timeval,
    #[cfg(not(any(target_os = "freebsd", target_os = "netbsd")))]
    pub bh_tstamp: timeval32,
    pub bh_caplen: u32,
    pub bh_datalen: u32,
    pub bh_hdrlen: libc::c_ushort,
}

or maybe the cfg for the struct fields should be the other way around.

thanks very much!

shellrow commented 1 year ago

Thank you for the report ! I addressed a testing shortfall for BSD OS and implemented necessary fixes, including cfg additions. These changes will be part of the next release.