Skip to content

Commit

Permalink
Factor out the "raw_socket" and "tap_interface" features
Browse files Browse the repository at this point in the history
This makes it possible to build smoltcp with the "std" feature on platforms
without libc, such as redox.
batonius authored and whitequark committed Jun 15, 2017
1 parent 22772f0 commit 80c20ad
Showing 7 changed files with 32 additions and 18 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 5 additions & 5 deletions src/phy/mod.rs
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 7 additions & 2 deletions src/phy/sys/linux.rs
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 4 additions & 2 deletions src/phy/sys/mod.rs
Original file line number Diff line number Diff line change
@@ -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)]

0 comments on commit 80c20ad

Please sign in to comment.