use std::io::{stdout, Write};
use structopt::StructOpt;
use ethox::managed::{List, Slice};
use ethox::nic::{Device, sys::TapInterface};
use ethox::layer::{arp, eth, ip};
use ethox::wire::{ip::v4::Cidr, ethernet::Address, PayloadMut};
fn main() {
let Config {
name,
host,
hostmac,
gateway,
gatemac,
} = Config::from_args();
let mut eth = eth::Endpoint::new(hostmac);
let mut neighbors = [arp::Neighbor::default(); 5];
let neighbors = {
let mut eth_cache = arp::NeighborCache::new(&mut neighbors[..]);
eth_cache.fill(gateway.address().into(), gatemac, None).unwrap();
eth_cache
};
let mut ip = [ip::Route::new_ipv4_gateway(gateway.address()); 1];
let routes = ip::Routes::import(List::new_full(ip.as_mut().into()));
let mut ip = ip::Endpoint::new(Slice::One(host.into()), routes, neighbors);
let mut interface = TapInterface::new(&name, vec![0; 1 << 14])
.expect("Couldn't initialize interface");
let out = stdout();
let mut out = out.lock();
out.write_all(b"Started arp endpoint\n").unwrap();
loop {
let result = interface.rx(1, eth.recv(ip.recv_with(drop_packet)));
if let Ok(1) = result {
out.write_all(b".").unwrap();
out.flush().unwrap();
}
result.unwrap_or_else(|err| {
panic!("Error during receive {:?} {:?}", err, interface.last_err());
});
}
}
#[derive(StructOpt)]
struct Config {
name: String,
host: Cidr,
hostmac: Address,
gateway: Cidr,
gatemac: Address,
}
fn drop_packet<P: PayloadMut>(_: ip::InPacket<P>) { }