Skip to content

Commit

Permalink
Merge pull request #883 from iamleot/netbsd-support
Browse files Browse the repository at this point in the history
Add support for NetBSD
  • Loading branch information
thvdveld authored Jan 4, 2024
2 parents 2e7003f + eca92ad commit e2ea63a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/phy/sys/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ use crate::phy::Medium;
use crate::wire::ETHERNET_HEADER_LEN;

/// set interface
#[cfg(any(target_os = "macos", target_os = "openbsd"))]
#[cfg(any(target_os = "macos", target_os = "netbsd", target_os = "openbsd"))]
const BIOCSETIF: libc::c_ulong = 0x8020426c;
/// get buffer length
#[cfg(any(target_os = "macos", target_os = "openbsd"))]
#[cfg(any(target_os = "macos", target_os = "netbsd", target_os = "openbsd"))]
const BIOCGBLEN: libc::c_ulong = 0x40044266;
/// set immediate/nonblocking read
#[cfg(any(target_os = "macos", target_os = "openbsd"))]
#[cfg(any(target_os = "macos", target_os = "netbsd", target_os = "openbsd"))]
const BIOCIMMEDIATE: libc::c_ulong = 0x80044270;
/// set bpf_hdr struct size
#[cfg(target_os = "macos")]
#[cfg(any(target_os = "macos", target_os = "netbsd"))]
const SIZEOF_BPF_HDR: usize = 18;
/// set bpf_hdr struct size
#[cfg(target_os = "openbsd")]
const SIZEOF_BPF_HDR: usize = 24;
/// The actual header length may be larger than the bpf_hdr struct due to aligning
/// see https://github.com/openbsd/src/blob/37ecb4d066e5566411cc16b362d3960c93b1d0be/sys/net/bpf.c#L1649
/// and https://github.com/apple/darwin-xnu/blob/8f02f2a044b9bb1ad951987ef5bab20ec9486310/bsd/net/bpf.c#L3580
#[cfg(any(target_os = "macos", target_os = "openbsd"))]
/// and https://github.com/NetBSD/src/blob/13d937d9ba3db87c9a898a40a8ed9d2aab2b1b95/sys/net/bpf.c#L1988
#[cfg(any(target_os = "macos", target_os = "netbsd", target_os = "openbsd"))]
const BPF_HDRLEN: usize = (((SIZEOF_BPF_HDR + ETHERNET_HEADER_LEN) + mem::align_of::<u32>() - 1)
& !(mem::align_of::<u32>() - 1))
- ETHERNET_HEADER_LEN;
Expand Down Expand Up @@ -167,7 +168,7 @@ mod test {
use super::*;

#[test]
#[cfg(target_os = "macos")]
#[cfg(any(target_os = "macos", target_os = "netbsd"))]
fn test_aligned_bpf_hdr_len() {
assert_eq!(18, BPF_HDRLEN);
}
Expand Down

0 comments on commit e2ea63a

Please sign in to comment.