lib.rs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #![feature(associated_consts, const_fn, step_by, intrinsics)]
  2. #![no_std]
  3. extern crate byteorder;
  4. #[cfg(any(test, feature = "std"))]
  5. #[macro_use]
  6. extern crate std;
  7. #[cfg(feature = "std")]
  8. extern crate libc;
  9. use core::fmt;
  10. mod managed;
  11. pub mod phy;
  12. pub mod wire;
  13. pub mod iface;
  14. pub mod socket;
  15. pub use managed::Managed;
  16. /// The error type for the networking stack.
  17. #[derive(Debug, PartialEq, Eq, Clone, Copy)]
  18. pub enum Error {
  19. /// An incoming packet could not be parsed, or an outgoing packet could not be emitted
  20. /// because a field was out of bounds for the underlying buffer.
  21. Truncated,
  22. /// An incoming packet could not be recognized and was dropped.
  23. /// E.g. a packet with an unknown EtherType.
  24. Unrecognized,
  25. /// An incoming packet was recognized but contained invalid data.
  26. /// E.g. a packet with IPv4 EtherType but containing a value other than 4
  27. /// in the version field.
  28. Malformed,
  29. /// An incoming packet had an incorrect checksum and was dropped.
  30. Checksum,
  31. /// An incoming packet has been fragmented and was dropped.
  32. Fragmented,
  33. /// An outgoing packet could not be sent because a protocol address could not be mapped
  34. /// to hardware address. E.g. an IPv4 packet did not have an Ethernet address
  35. /// corresponding to its IPv4 destination address.
  36. Unaddressable,
  37. /// A buffer for incoming packets is empty, or a buffer for outgoing packets is full.
  38. Exhausted,
  39. /// An incoming packet does not match the socket endpoint.
  40. Rejected,
  41. #[doc(hidden)]
  42. __Nonexhaustive
  43. }
  44. impl fmt::Display for Error {
  45. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  46. match self {
  47. &Error::Truncated => write!(f, "truncated packet"),
  48. &Error::Unrecognized => write!(f, "unrecognized packet"),
  49. &Error::Malformed => write!(f, "malformed packet"),
  50. &Error::Checksum => write!(f, "checksum error"),
  51. &Error::Fragmented => write!(f, "fragmented packet"),
  52. &Error::Unaddressable => write!(f, "unaddressable destination"),
  53. &Error::Exhausted => write!(f, "buffer space exhausted"),
  54. &Error::Rejected => write!(f, "rejected by socket"),
  55. &Error::__Nonexhaustive => unreachable!()
  56. }
  57. }
  58. }