Factor out the "raw_socket" and "tap_interface" features

This makes it possible to build smoltcp with the "std" feature on platforms
without libc, such as redox.
This commit is contained in:
Egor Karavaev 2017-06-15 13:12:11 +03:00 committed by whitequark
parent f29b610801
commit 59fc0c0358
7 changed files with 32 additions and 18 deletions

View File

@ -2,13 +2,13 @@ language: rust
matrix:
include:
- rust: stable
env: FEATURES='std' MODE='test'
env: FEATURES='std raw_socket tap_interface' MODE='test'
- rust: beta
env: FEATURES='std' MODE='test'
env: FEATURES='std raw_socket tap_interface' MODE='test'
- rust: nightly
env: FEATURES='std' MODE='test'
env: FEATURES='std raw_socket tap_interface' MODE='test'
- rust: nightly
env: FEATURES='std log' MODE='test'
env: FEATURES='std raw_socket tap_interface log' MODE='test'
- rust: nightly
env: FEATURES='alloc collections' MODE='build'
- rust: nightly

View File

@ -23,11 +23,13 @@ env_logger = "0.4"
getopts = "0.2"
[features]
std = ["managed/std", "libc"]
std = ["managed/std"]
alloc = ["managed/alloc"]
collections = ["managed/collections"]
verbose = []
default = ["std", "log", "verbose"]
raw_socket = ["libc"]
tap_interface = ["libc"]
default = ["std", "raw_socket", "tap_interface", "log", "verbose"]
[[example]]
name = "tcpdump"

View File

@ -87,11 +87,16 @@ smoltcp = { version = "0.3", default-features = false, features = ["..."] }
### Feature `std`
The `std` feature enables use of objects and slices owned by the networking stack through a
dependency on `std::boxed::Box` and `std::vec::Vec`. It also enables `smoltcp::phy::RawSocket`
and `smoltcp::phy::TapInterface`, if the platform supports it.
dependency on `std::boxed::Box` and `std::vec::Vec`.
This feature is enabled by default.
### Features `raw_socket` and `tap_interface`
Enable `smoltcp::phy::RawSocket` and `smoltcp::phy::TapInterface`, respectively.
These features are enabled by default.
### Feature `alloc`
The `alloc` feature enables use of objects owned by the networking stack through a dependency

View File

@ -72,7 +72,7 @@ extern crate managed;
#[cfg(any(test, feature = "std"))]
#[macro_use]
extern crate std;
#[cfg(feature = "std")]
#[cfg(any(feature = "raw_socket", feature="tap_interface"))]
extern crate libc;
#[cfg(feature = "alloc")]
extern crate alloc;

View File

@ -102,21 +102,21 @@ impl Drop for EthernetTxBuffer {
use Error;
#[cfg(feature = "std")]
#[cfg(any(feature = "raw_socket", feature="tap_interface"))]
mod sys;
mod tracer;
mod fault_injector;
#[cfg(feature = "std")]
#[cfg(feature = "raw_socket")]
mod raw_socket;
#[cfg(all(feature = "std", target_os = "linux"))]
#[cfg(all(feature = "tap_interface", target_os = "linux"))]
mod tap_interface;
pub use self::tracer::Tracer;
pub use self::fault_injector::FaultInjector;
#[cfg(feature = "std")]
#[cfg(any(feature = "raw_socket"))]
pub use self::raw_socket::RawSocket;
#[cfg(all(feature = "std", target_os = "linux"))]
#[cfg(all(feature = "tap_interface", target_os = "linux"))]
pub use self::tap_interface::TapInterface;
/// A description of device limitations.

View File

@ -1,11 +1,16 @@
use libc;
#[cfg(any(feature = "raw_socket"))]
pub const SIOCGIFMTU: libc::c_ulong = 0x8921;
#[cfg(any(feature = "raw_socket"))]
pub const SIOCGIFINDEX: libc::c_ulong = 0x8933;
#[cfg(any(feature = "raw_socket"))]
pub const ETH_P_ALL: libc::c_short = 0x0003;
#[cfg(feature = "tap_interface")]
pub const TUNSETIFF: libc::c_ulong = 0x400454CA;
#[cfg(feature = "tap_interface")]
pub const IFF_TAP: libc::c_int = 0x0002;
#[cfg(feature = "tap_interface")]
pub const IFF_NO_PI: libc::c_int = 0x1000;
pub const ETH_P_ALL: libc::c_short = 0x0003;

View File

@ -5,12 +5,14 @@ use std::io;
#[path = "linux.rs"]
mod imp;
#[cfg(feature = "raw_socket")]
pub mod raw_socket;
#[cfg(target_os = "linux")]
#[cfg(all(feature = "tap_interface", target_os = "linux"))]
pub mod tap_interface;
#[cfg(feature = "raw_socket")]
pub use self::raw_socket::RawSocketDesc;
#[cfg(target_os = "linux")]
#[cfg(all(feature = "tap_interface", target_os = "linux"))]
pub use self::tap_interface::TapInterfaceDesc;
#[repr(C)]