2016-12-13 01:26:06 +08:00
|
|
|
#![feature(associated_consts, const_fn, step_by)]
|
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 = "std"))]
|
2016-12-10 17:23:40 +08:00
|
|
|
#[macro_use]
|
|
|
|
extern crate std;
|
2016-12-11 07:15:26 +08:00
|
|
|
#[cfg(feature = "std")]
|
|
|
|
extern crate libc;
|
2016-12-10 17:23:40 +08:00
|
|
|
|
2016-12-12 15:19:53 +08:00
|
|
|
use core::fmt;
|
|
|
|
|
2016-12-11 02:33:19 +08:00
|
|
|
pub mod phy;
|
2016-12-10 21:13:13 +08:00
|
|
|
pub mod wire;
|
2016-12-12 10:39:46 +08:00
|
|
|
pub mod iface;
|
2016-12-12 15:19:53 +08:00
|
|
|
|
|
|
|
/// The error type for the networking stack.
|
|
|
|
#[derive(Debug)]
|
|
|
|
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.
|
2016-12-13 04:01:38 +08:00
|
|
|
/// E.g. a packet with an unknown EtherType.
|
2016-12-12 15:19:53 +08:00
|
|
|
Unrecognized,
|
2016-12-13 04:01:38 +08:00
|
|
|
/// 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,
|
2016-12-13 04:01:38 +08:00
|
|
|
/// 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-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-12 15:19:53 +08:00
|
|
|
&Error::__Nonexhaustive => unreachable!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|