Skip to content

Commit

Permalink
Add illumos+solaris support
Browse files Browse the repository at this point in the history
  • Loading branch information
teutat3s committed Apr 11, 2022
1 parent a91a205 commit f7aa541
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
33 changes: 28 additions & 5 deletions pnet_datalink/src/bindings/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ const IOCPARM_MASK: libc::c_ulong = (1 << (IOCPARM_SHIFT as usize)) - 1;
const SIZEOF_TIMEVAL: libc::c_ulong = 16;
const SIZEOF_IFREQ: libc::c_ulong = 32;
const SIZEOF_C_UINT: libc::c_ulong = 4;
#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
#[cfg(any(
target_os = "freebsd",
target_os = "netbsd",
target_os = "illumos",
target_os = "solaris"
))]
const SIZEOF_C_LONG: libc::c_int = 8;

pub const BIOCSETIF: libc::c_ulong =
Expand All @@ -46,7 +51,7 @@ pub const BIOCSHDRCMPLT: libc::c_ulong =
pub const BIOCSRTIMEOUT: libc::c_ulong =
IOC_IN | ((SIZEOF_TIMEVAL & IOCPARM_MASK) << 16) | (('B' as libc::c_ulong) << 8) | 109;

#[cfg(target_os = "freebsd")]
#[cfg(any(target_os = "freebsd", target_os = "illumos", target_os = "solaris"))]
pub const BIOCFEEDBACK: libc::c_ulong =
IOC_IN | ((SIZEOF_C_UINT & IOCPARM_MASK) << 16) | (('B' as libc::c_ulong) << 8) | 124;
#[cfg(target_os = "netbsd")]
Expand All @@ -56,7 +61,12 @@ pub const BIOCFEEDBACK: libc::c_ulong =

pub const DLT_NULL: libc::c_uint = 0;

#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
#[cfg(any(
target_os = "freebsd",
target_os = "netbsd",
target_os = "illumos",
target_os = "solaris"
))]
const BPF_ALIGNMENT: libc::c_int = SIZEOF_C_LONG;
#[cfg(any(target_os = "openbsd", target_os = "macos", target_os = "ios", windows))]
const BPF_ALIGNMENT: libc::c_int = 4;
Expand All @@ -76,7 +86,15 @@ pub struct ifreq {
// sdl_data does not match if_dl.h on OS X, since the size of 12 is a minimum.
// Will be unsafe
// when sdl_nlen > 40.
#[cfg(any(target_os = "openbsd", target_os = "freebsd", target_os = "netbsd", target_os = "macos", target_os = "ios"))]
#[cfg(any(
target_os = "openbsd",
target_os = "freebsd",
target_os = "netbsd",
target_os = "illumos",
target_os = "solaris",
target_os = "macos",
target_os = "ios"
))]
pub struct sockaddr_dl {
pub sdl_len: libc::c_uchar,
pub sdl_family: libc::c_uchar,
Expand All @@ -92,7 +110,12 @@ pub struct sockaddr_dl {
#[cfg(any(
target_os = "freebsd",
target_os = "netbsd",
all(any(target_os = "macos", target_os = "ios"), target_pointer_width = "32"),
target_os = "illumos",
target_os = "solaris",
all(
any(target_os = "macos", target_os = "ios"),
target_pointer_width = "32"
),
windows
))]
#[repr(C)]
Expand Down
2 changes: 2 additions & 0 deletions pnet_datalink/src/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
target_os = "illumos",
target_os = "solaris",
target_os = "macos",
target_os = "ios",
windows
Expand Down
14 changes: 12 additions & 2 deletions pnet_datalink/src/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ impl Default for Config {
// NOTE buffer must be word aligned.
#[inline]
pub fn channel(network_interface: &NetworkInterface, config: Config) -> io::Result<super::Channel> {
#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
#[cfg(any(
target_os = "freebsd",
target_os = "netbsd",
target_os = "illumos",
target_os = "solaris"
))]
fn get_fd(_attempts: usize) -> libc::c_int {
unsafe {
libc::open(
Expand Down Expand Up @@ -106,7 +111,12 @@ pub fn channel(network_interface: &NetworkInterface, config: Config) -> io::Resu
-1
}

#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
#[cfg(any(
target_os = "freebsd",
target_os = "netbsd",
target_os = "illumos",
target_os = "solaris"
))]
fn set_feedback(fd: libc::c_int) -> io::Result<()> {
if unsafe { bpf::ioctl(fd, bpf::BIOCFEEDBACK, &1) } == -1 {
let err = io::Error::last_os_error();
Expand Down
4 changes: 4 additions & 0 deletions pnet_datalink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub mod linux;
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
target_os = "illumos",
target_os = "solaris",
target_os = "macos",
target_os = "ios"
)
Expand All @@ -61,6 +63,8 @@ mod backend;
#[cfg(any(
target_os = "freebsd",
target_os = "netbsd",
target_os = "illumos",
target_os = "solaris",
target_os = "macos",
target_os = "ios"
))]
Expand Down
2 changes: 2 additions & 0 deletions pnet_datalink/src/unix_interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ fn sockaddr_to_network_addr(sa: *const libc::sockaddr) -> (Option<MacAddr>, Opti
target_os = "openbsd",
target_os = "freebsd",
target_os = "netbsd",
target_os = "illumos",
target_os = "solaris",
target_os = "macos",
target_os = "ios"
))]
Expand Down

0 comments on commit f7aa541

Please sign in to comment.