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: 59dae01e9c4d
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: 7d838b6d9f0e
Choose a head ref
  • 2 commits
  • 10 files changed
  • 1 contributor

Commits on Dec 17, 2016

  1. Working UDP loopback.

    whitequark committed Dec 17, 2016
    Copy the full SHA
    8b89de2 View commit details
  2. Copy the full SHA
    7d838b6 View commit details
Showing with 142 additions and 264 deletions.
  1. +2 −0 Cargo.toml
  2. +13 −0 LICENSE-0BSD
  3. +0 −201 LICENSE-APACHE
  4. +0 −25 LICENSE-MIT
  5. +2 −1 README.md
  6. +23 −4 examples/smoltcpserver.rs
  7. +5 −5 src/iface/ethernet.rs
  8. +45 −11 src/socket/mod.rs
  9. +40 −12 src/socket/udp.rs
  10. +12 −5 src/wire/udp.rs
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@
name = "smoltcp"
version = "0.1.0"
authors = ["whitequark <whitequark@whitequark.org>"]
license = "0BSD"
license-file = "LICENSE-0BSD"

[dependencies]
byteorder = { version = "0.5", default-features = false }
13 changes: 13 additions & 0 deletions LICENSE-0BSD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (C) 2016 whitequark@whitequark.org

Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

201 changes: 0 additions & 201 deletions LICENSE-APACHE

This file was deleted.

25 changes: 0 additions & 25 deletions LICENSE-MIT

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -101,7 +101,8 @@ cargo run --example smoltcpserver -- tap0

It responds to:

* pings (`ping 192.168.69.1`).
* pings (`ping 192.168.69.1`),
* UDP packets on port 6969 (`socat stdio udp4-connect:192.168.69.1:6969 <<<"abcdefg"`).

License
-------
27 changes: 23 additions & 4 deletions examples/smoltcpserver.rs
Original file line number Diff line number Diff line change
@@ -2,10 +2,11 @@
extern crate smoltcp;

use std::env;
use smoltcp::Error;
use smoltcp::phy::{Tracer, TapInterface};
use smoltcp::wire::{EthernetFrame, EthernetAddress, InternetAddress, InternetEndpoint};
use smoltcp::iface::{SliceArpCache, EthernetInterface};
use smoltcp::socket::{Socket, UdpSocket, UdpBuffer, UdpBufferElem};
use smoltcp::socket::{UdpSocket, AsSocket, UdpBuffer, UdpBufferElem};

fn main() {
let ifname = env::args().nth(1).unwrap();
@@ -22,16 +23,34 @@ fn main() {

let udp_rx_buffer = UdpBuffer::new(vec![UdpBufferElem::new(vec![0; 2048])]);
let udp_tx_buffer = UdpBuffer::new(vec![UdpBufferElem::new(vec![0; 2048])]);
let mut udp_socket = UdpSocket::new(endpoint, udp_rx_buffer, udp_tx_buffer);
let udp_socket = UdpSocket::new(endpoint, udp_rx_buffer, udp_tx_buffer);

let mut sockets: [&mut Socket; 1] = [&mut udp_socket];
let mut sockets = [udp_socket];
let mut iface = EthernetInterface::new(device, arp_cache,
hardware_addr, &mut protocol_addrs[..], &mut sockets[..]);

loop {
match iface.poll() {
Ok(()) => (),
Err(e) => println!("{}", e)
Err(e) => println!("error {}", e)
}

let udp_socket = iface.sockets()[0].as_socket();
let client = match udp_socket.recv() {
Ok((endpoint, data)) => {
println!("data {:?} from {}", &data[..8], endpoint);
Some(endpoint)
}
Err(Error::Exhausted) => {
None
}
Err(e) => {
println!("error {}", e);
None
}
};
if let Some(endpoint) = client {
udp_socket.send_slice(endpoint, "hihihi".as_bytes()).unwrap()
}
}
}
10 changes: 5 additions & 5 deletions src/iface/ethernet.rs
Original file line number Diff line number Diff line change
@@ -21,21 +21,21 @@ pub struct Interface<'a,
DeviceT: Device,
ArpCacheT: ArpCache,
ProtocolAddrsT: BorrowMut<[InternetAddress]>,
SocketsT: BorrowMut<[&'a mut Socket]>
SocketsT: BorrowMut<[Socket<'a>]>
> {
device: DeviceT,
arp_cache: ArpCacheT,
hardware_addr: EthernetAddress,
protocol_addrs: ProtocolAddrsT,
sockets: SocketsT,
phantom: PhantomData<&'a mut Socket>
phantom: PhantomData<Socket<'a>>
}

impl<'a,
DeviceT: Device,
ArpCacheT: ArpCache,
ProtocolAddrsT: BorrowMut<[InternetAddress]>,
SocketsT: BorrowMut<[&'a mut Socket]>
SocketsT: BorrowMut<[Socket<'a>]>
> Interface<'a, DeviceT, ArpCacheT, ProtocolAddrsT, SocketsT> {
/// Create a network interface using the provided network device.
///
@@ -106,8 +106,8 @@ impl<'a,
}

/// Get the set of sockets owned by the interface.
pub fn with_sockets<R, F: FnOnce(&mut [&'a mut Socket]) -> R>(&mut self, f: F) -> R {
f(self.sockets.borrow_mut())
pub fn sockets(&mut self) -> &mut [Socket<'a>] {
self.sockets.borrow_mut()
}

/// Receive and process a packet, if available.
Loading