Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: smoltcp-rs/smoltcp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c104859011d8
Choose a base ref
...
head repository: smoltcp-rs/smoltcp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b4b97ec88fc4
Choose a head ref
  • 4 commits
  • 10 files changed
  • 1 contributor

Commits on Dec 31, 2016

  1. Verified

    This commit was signed with the committer’s verified signature.
    makenowjust Hiroya Fujinami
    Copy the full SHA
    754883c View commit details

Commits on Jan 1, 2017

  1. Fix silliness in docs.

    whitequark committed Jan 1, 2017
    Copy the full SHA
    327b91c View commit details
  2. Copy the full SHA
    657658d View commit details

Commits on Jan 10, 2017

  1. Use the managed crate.

    whitequark committed Jan 10, 2017
    Copy the full SHA
    b4b97ec View commit details
Showing with 39 additions and 123 deletions.
  1. +3 −2 Cargo.toml
  2. +4 −4 examples/server.rs
  3. +2 −1 src/iface/arp_cache.rs
  4. +7 −7 src/iface/ethernet.rs
  5. +1 −4 src/lib.rs
  6. +0 −83 src/managed.rs
  7. +18 −20 src/phy/mod.rs
  8. +1 −1 src/socket/tcp.rs
  9. +2 −1 src/socket/udp.rs
  10. +1 −0 src/wire/mod.rs
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ license = "0BSD"

[dependencies]
byteorder = { version = "1.0", default-features = false }
managed = { version = "0.1", default-features = false }
log = { version = "0.3", default-features = false, optional = true }
libc = { version = "0.2.18", optional = true }

@@ -20,7 +21,7 @@ env_logger = "0.3"
getopts = "0.2"

[features]
use_std = ["libc"]
use_alloc = []
use_std = ["managed/use_std", "libc"]
use_alloc = ["managed/use_alloc"]
use_log = ["log"]
default = ["use_std", "use_log"]
8 changes: 4 additions & 4 deletions examples/server.rs
Original file line number Diff line number Diff line change
@@ -82,11 +82,11 @@ fn main() {
let tcp2_tx_buffer = TcpSocketBuffer::new(vec![0; 128]);
let tcp2_socket = TcpSocket::new(tcp2_rx_buffer, tcp2_tx_buffer);

let hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]);
let hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]);
let protocol_addrs = [IpAddress::v4(192, 168, 69, 1)];
let sockets = vec![udp_socket, tcp1_socket, tcp2_socket];
let mut iface = EthernetInterface::new(device, arp_cache,
hardware_addr, protocol_addrs, sockets);
let sockets = vec![udp_socket, tcp1_socket, tcp2_socket];
let mut iface = EthernetInterface::new(device, hardware_addr, protocol_addrs,
arp_cache, sockets);

let mut tcp_6969_connected = false;
loop {
3 changes: 2 additions & 1 deletion src/iface/arp_cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use Managed;
use managed::Managed;

use wire::{EthernetAddress, IpAddress};

/// An Address Resolution Protocol cache.
14 changes: 7 additions & 7 deletions src/iface/ethernet.rs
Original file line number Diff line number Diff line change
@@ -20,32 +20,32 @@ use super::{ArpCache};
#[derive(Debug)]
pub struct Interface<'a, 'b: 'a,
DeviceT: Device,
ArpCacheT: ArpCache,
ProtocolAddrsT: BorrowMut<[IpAddress]>,
ArpCacheT: ArpCache,
SocketsT: BorrowMut<[Socket<'a, 'b>]>
> {
device: DeviceT,
arp_cache: ArpCacheT,
hardware_addr: EthernetAddress,
protocol_addrs: ProtocolAddrsT,
arp_cache: ArpCacheT,
sockets: SocketsT,
phantom: PhantomData<Socket<'a, 'b>>
}

impl<'a, 'b: 'a,
DeviceT: Device,
ArpCacheT: ArpCache,
ProtocolAddrsT: BorrowMut<[IpAddress]>,
ArpCacheT: ArpCache,
SocketsT: BorrowMut<[Socket<'a, 'b>]>
> Interface<'a, 'b, DeviceT, ArpCacheT, ProtocolAddrsT, SocketsT> {
> Interface<'a, 'b, DeviceT, ProtocolAddrsT, ArpCacheT, SocketsT> {
/// Create a network interface using the provided network device.
///
/// # Panics
/// See the restrictions on [set_hardware_addr](#method.set_hardware_addr)
/// and [set_protocol_addrs](#method.set_protocol_addrs) functions.
pub fn new(device: DeviceT, arp_cache: ArpCacheT, hardware_addr: EthernetAddress,
protocol_addrs: ProtocolAddrsT, sockets: SocketsT) ->
Interface<'a, 'b, DeviceT, ArpCacheT, ProtocolAddrsT, SocketsT> {
pub fn new(device: DeviceT, hardware_addr: EthernetAddress, protocol_addrs: ProtocolAddrsT,
arp_cache: ArpCacheT, sockets: SocketsT) ->
Interface<'a, 'b, DeviceT, ProtocolAddrsT, ArpCacheT, SocketsT> {
Self::check_hardware_addr(&hardware_addr);
Self::check_protocol_addrs(protocol_addrs.borrow());
Interface {
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -68,6 +68,7 @@
//! of a packet, it is still logged correctly and in full.
extern crate byteorder;
extern crate managed;
#[cfg(any(test, feature = "use_std"))]
#[macro_use]
extern crate std;
@@ -90,15 +91,11 @@ macro_rules! net_trace {

use core::fmt;

mod managed;

pub mod phy;
pub mod wire;
pub mod iface;
pub mod socket;

pub use managed::Managed;

/// The error type for the networking stack.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Error {
83 changes: 0 additions & 83 deletions src/managed.rs

This file was deleted.

38 changes: 18 additions & 20 deletions src/phy/mod.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,8 @@
//! It also provides the _middleware interfaces_ [Tracer](struct.Tracer.html) and
//! [FaultInjector](struct.FaultInjector.html), to facilitate debugging.
//!
//! # Examples
// https://github.com/rust-lang/rust/issues/38740
//! <h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
//!
//! An implementation of the [Device](trait.Device.html) trait for a simple hardware
//! Ethernet controller could look as follows:
@@ -19,7 +20,6 @@ use std::slice;
use smoltcp::Error;
use smoltcp::phy::Device;
const MTU: usize = 1536;
const TX_BUFFERS: [*mut u8; 2] = [0x10000000 as *mut u8, 0x10001000 as *mut u8];
const RX_BUFFERS: [*mut u8; 2] = [0x10002000 as *mut u8, 0x10003000 as *mut u8];
@@ -28,6 +28,11 @@ fn rx_full() -> bool {
false
}
fn rx_length() -> usize {
/* platform-specific code to determine the length of an incoming packet */
0
}
fn rx_setup(buf: *mut u8) {
/* platform-specific code to receive a packet into a buffer */
}
@@ -42,22 +47,23 @@ fn tx_setup(buf: *const u8) {
}
struct EthernetDevice {
tx_next: usize,
rx_next: usize
tx_next: usize,
rx_next: usize
}
impl Device for EthernetDevice {
type RxBuffer = &'static [u8];
type TxBuffer = EthernetTxBuffer;
fn mtu(&self) -> usize { MTU }
fn mtu(&self) -> usize { 1536 }
fn receive(&mut self) -> Result<Self::RxBuffer, Error> {
if rx_full() {
let index = self.rx_next;
let length = rx_length();
let index = self.rx_next;
self.rx_next = (self.rx_next + 1) % RX_BUFFERS.len();
rx_setup(RX_BUFFERS[self.rx_next]);
Ok(unsafe { slice::from_raw_parts(RX_BUFFERS[index], MTU) })
Ok(unsafe { slice::from_raw_parts(RX_BUFFERS[index], length) })
} else {
Err(Error::Exhausted)
}
@@ -67,33 +73,25 @@ impl Device for EthernetDevice {
if tx_empty() {
let index = self.tx_next;
self.tx_next = (self.tx_next + 1) % TX_BUFFERS.len();
Ok(EthernetTxBuffer {
buffer: unsafe { slice::from_raw_parts_mut(TX_BUFFERS[index], length) },
length: length,
})
Ok(EthernetTxBuffer(unsafe { slice::from_raw_parts_mut(TX_BUFFERS[index], length) }))
} else {
Err(Error::Exhausted)
}
}
}
struct EthernetTxBuffer {
buffer: &'static mut [u8],
length: usize
}
struct EthernetTxBuffer(&'static mut [u8]);
impl AsRef<[u8]> for EthernetTxBuffer {
fn as_ref(&self) -> &[u8] { &self.buffer[..self.length] }
fn as_ref(&self) -> &[u8] { self.0 }
}
impl AsMut<[u8]> for EthernetTxBuffer {
fn as_mut(&mut self) -> &mut [u8] { &mut self.buffer[..self.length] }
fn as_mut(&mut self) -> &mut [u8] { self.0 }
}
impl Drop for EthernetTxBuffer {
fn drop(&mut self) {
tx_setup(self.buffer.as_ptr())
}
fn drop(&mut self) { tx_setup(self.0.as_ptr()) }
}
```
*/
2 changes: 1 addition & 1 deletion src/socket/tcp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::fmt;
use managed::Managed;

use Error;
use Managed;
use wire::{IpProtocol, IpAddress, IpEndpoint};
use wire::{TcpSeqNumber, TcpPacket, TcpRepr, TcpControl};
use socket::{Socket, IpRepr, IpPayload};
3 changes: 2 additions & 1 deletion src/socket/udp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use managed::Managed;

use Error;
use Managed;
use wire::{IpProtocol, IpEndpoint};
use wire::{UdpPacket, UdpRepr};
use socket::{Socket, IpRepr, IpPayload};
1 change: 1 addition & 0 deletions src/wire/mod.rs
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
//! of possible field values, it provides a compact, high-level representation
//! of packet data that can be parsed from and emitted into a sequence of octets.
//! This happens through the `Repr` family of enums, e.g. [ArpRepr](enum.ArpRepr.html).
// https://github.com/rust-lang/rust/issues/38739
//! </ul>
//!
//! The functions in the `wire` module are designed for robustness and use together with