Skip to content

Commit

Permalink
Fix error[E0308]: mismatched types on illumos +
Browse files Browse the repository at this point in the history
solaris

error[E0308]: mismatched types
   --> pnet_datalink/src/lib.rs:239:22
    |
239 |         self.flags & (pnet_sys::IFF_UP as u32) != 0
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found `u32`

error[E0277]: no implementation for `u64 & u32`
   --> pnet_datalink/src/lib.rs:239:20
    |
239 |         self.flags & (pnet_sys::IFF_UP as u32) != 0
    |                    ^ no implementation for `u64 & u32`
    |
    = help: the trait `BitAnd<u32>` is not implemented for `u64`
...
  • Loading branch information
teutat3s committed Apr 11, 2022
1 parent f7aa541 commit 854efcd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
25 changes: 17 additions & 8 deletions pnet_datalink/src/lib.rs
Expand Up @@ -230,48 +230,57 @@ pub struct NetworkInterface {
/// IP addresses and netmasks for the interface.
pub ips: Vec<IpNetwork>,
/// Operating system specific flags for the interface.
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
pub flags: u32,
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
pub flags: u64,
}

/// Type alias for an `InterfaceType`.
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
pub type InterfaceType = u32;
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
pub type InterfaceType = u64;

impl NetworkInterface {
pub fn is_up(&self) -> bool {
self.flags & (pnet_sys::IFF_UP as u32) != 0
self.flags & (pnet_sys::IFF_UP as InterfaceType) != 0
}

pub fn is_broadcast(&self) -> bool {
self.flags & (pnet_sys::IFF_BROADCAST as u32) != 0
self.flags & (pnet_sys::IFF_BROADCAST as InterfaceType) != 0
}

/// Is the interface a loopback interface?
pub fn is_loopback(&self) -> bool {
self.flags & (pnet_sys::IFF_LOOPBACK as u32) != 0
self.flags & (pnet_sys::IFF_LOOPBACK as InterfaceType) != 0
}

pub fn is_point_to_point(&self) -> bool {
self.flags & (pnet_sys::IFF_POINTOPOINT as u32) != 0
self.flags & (pnet_sys::IFF_POINTOPOINT as InterfaceType) != 0
}

pub fn is_multicast(&self) -> bool {
self.flags & (pnet_sys::IFF_MULTICAST as u32) != 0
self.flags & (pnet_sys::IFF_MULTICAST as InterfaceType) != 0
}

/// Triggered when the driver has signated netif_carrier_on
/// Check <https://www.kernel.org/doc/html/latest/networking/operstates.html> for more information
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn is_lower_up(&self) -> bool {
self.flags & (pnet_sys::IFF_LOWER_UP as u32) != 0
self.flags & (pnet_sys::IFF_LOWER_UP as InterfaceType) != 0
}

/// Triggered when the driver has signated netif_dormant_on
/// Check <https://www.kernel.org/doc/html/latest/networking/operstates.html> for more information
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn is_dormant(&self) -> bool {
self.flags & (pnet_sys::IFF_DORMANT as u32) != 0
self.flags & (pnet_sys::IFF_DORMANT as InterfaceType) != 0
}

#[cfg(unix)]
pub fn is_running(&self) -> bool {
self.flags & (pnet_sys::IFF_RUNNING as u32) != 0
self.flags & (pnet_sys::IFF_RUNNING as InterfaceType) != 0
}
}

Expand Down
8 changes: 6 additions & 2 deletions pnet_sys/src/unix.rs
Expand Up @@ -30,6 +30,10 @@ pub mod public {
pub type TvUsecType = libc::c_long;
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "netbsd"))]
pub type TvUsecType = libc::c_int;
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
pub type InAddrType = libc::c_uint;
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
pub type InAddrType = libc::c_ulonglong;

pub const AF_INET: libc::c_int = libc::AF_INET;
pub const AF_INET6: libc::c_int = libc::AF_INET6;
Expand Down Expand Up @@ -206,8 +210,8 @@ pub mod public {
use self::public::*;

#[inline(always)]
pub fn ipv4_addr(addr: InAddr) -> u32 {
(addr.s_addr as u32).to_be()
pub fn ipv4_addr(addr: InAddr) -> InAddrType {
(addr.s_addr as InAddrType).to_be()
}

#[inline(always)]
Expand Down

0 comments on commit 854efcd

Please sign in to comment.