2016-12-12 15:19:53 +08:00
|
|
|
#![feature(associated_consts)]
|
|
|
|
extern crate smoltcp;
|
|
|
|
|
|
|
|
use std::env;
|
2016-12-12 20:30:35 +08:00
|
|
|
use smoltcp::phy::{Tracer, TapInterface};
|
2016-12-14 09:59:47 +08:00
|
|
|
use smoltcp::wire::{EthernetFrame, EthernetAddress, InternetAddress};
|
|
|
|
use smoltcp::iface::{SliceArpCache, EthernetInterface};
|
2016-12-12 15:19:53 +08:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let ifname = env::args().nth(1).unwrap();
|
|
|
|
|
|
|
|
let hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]);
|
2016-12-14 09:59:47 +08:00
|
|
|
let protocol_addrs = [InternetAddress::ipv4([192, 168, 69, 1])];
|
2016-12-12 15:19:53 +08:00
|
|
|
|
|
|
|
let device = TapInterface::new(ifname.as_ref()).unwrap();
|
2016-12-12 20:30:35 +08:00
|
|
|
let device = Tracer::<_, EthernetFrame<&[u8]>>::new(device);
|
2016-12-12 15:19:53 +08:00
|
|
|
|
|
|
|
let mut arp_cache_data = [Default::default(); 8];
|
|
|
|
let arp_cache = SliceArpCache::new(&mut arp_cache_data);
|
|
|
|
let mut iface = EthernetInterface::new(device, arp_cache);
|
|
|
|
|
|
|
|
iface.set_hardware_addr(hardware_addr);
|
|
|
|
iface.set_protocol_addrs(&protocol_addrs);
|
|
|
|
|
|
|
|
loop {
|
|
|
|
match iface.poll() {
|
|
|
|
Ok(()) => (),
|
|
|
|
Err(e) => println!("{}", e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|