renet/src/lib.rs

82 lines
2.6 KiB
Rust
Raw Normal View History

2016-12-28 07:49:37 +08:00
#![cfg_attr(feature = "use_alloc", feature(alloc))]
2016-12-10 17:23:40 +08:00
#![no_std]
2016-12-11 07:15:26 +08:00
extern crate byteorder;
#[cfg(any(test, feature = "use_std"))]
2016-12-10 17:23:40 +08:00
#[macro_use]
extern crate std;
#[cfg(feature = "use_std")]
2016-12-11 07:15:26 +08:00
extern crate libc;
2016-12-28 07:49:37 +08:00
#[cfg(feature = "use_alloc")]
extern crate alloc;
#[cfg(feature = "use_log")]
2016-12-23 15:59:38 +08:00
#[macro_use(trace, log)]
extern crate log;
macro_rules! net_trace {
($($arg:expr),*) => {
#[cfg(feature = "use_log")]
trace!($($arg),*);
#[cfg(not(feature = "use_log"))]
$( let _ = $arg );*; // suppress unused variable warnings
2016-12-23 15:59:38 +08:00
}
}
2016-12-10 17:23:40 +08:00
2016-12-12 15:19:53 +08:00
use core::fmt;
mod managed;
2016-12-11 02:33:19 +08:00
pub mod phy;
pub mod wire;
2016-12-12 10:39:46 +08:00
pub mod iface;
2016-12-15 01:39:44 +08:00
pub mod socket;
2016-12-12 15:19:53 +08:00
pub use managed::Managed;
2016-12-12 15:19:53 +08:00
/// The error type for the networking stack.
2016-12-16 01:07:56 +08:00
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
2016-12-12 15:19:53 +08:00
pub enum Error {
2016-12-13 07:22:59 +08:00
/// An incoming packet could not be parsed, or an outgoing packet could not be emitted
/// because a field was out of bounds for the underlying buffer.
2016-12-12 15:19:53 +08:00
Truncated,
2016-12-13 01:26:06 +08:00
/// An incoming packet could not be recognized and was dropped.
/// E.g. a packet with an unknown EtherType.
2016-12-12 15:19:53 +08:00
Unrecognized,
/// An incoming packet was recognized but contained invalid data.
/// E.g. a packet with IPv4 EtherType but containing a value other than 4
/// in the version field.
Malformed,
2016-12-13 01:26:06 +08:00
/// An incoming packet had an incorrect checksum and was dropped.
Checksum,
/// An incoming packet has been fragmented and was dropped.
Fragmented,
2016-12-13 07:22:59 +08:00
/// An outgoing packet could not be sent because a protocol address could not be mapped
/// to hardware address. E.g. an IPv4 packet did not have an Ethernet address
/// corresponding to its IPv4 destination address.
Unaddressable,
2016-12-15 01:39:44 +08:00
/// A buffer for incoming packets is empty, or a buffer for outgoing packets is full.
Exhausted,
/// An incoming packet does not match the socket endpoint.
Rejected,
2016-12-12 15:19:53 +08:00
#[doc(hidden)]
__Nonexhaustive
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
2016-12-13 07:22:59 +08:00
&Error::Truncated => write!(f, "truncated packet"),
&Error::Unrecognized => write!(f, "unrecognized packet"),
&Error::Malformed => write!(f, "malformed packet"),
&Error::Checksum => write!(f, "checksum error"),
&Error::Fragmented => write!(f, "fragmented packet"),
&Error::Unaddressable => write!(f, "unaddressable destination"),
2016-12-15 01:39:44 +08:00
&Error::Exhausted => write!(f, "buffer space exhausted"),
&Error::Rejected => write!(f, "rejected by socket"),
2016-12-12 15:19:53 +08:00
&Error::__Nonexhaustive => unreachable!()
}
}
}