Enable arpd, update netutils, remove loop in ethernetd

This commit is contained in:
Jeremy Soller 2016-10-23 15:57:04 -06:00
parent 7f7f5a0078
commit 66bcd0d1ba
6 changed files with 36 additions and 60 deletions

View file

@ -3,4 +3,5 @@ name = "arpd"
version = "0.1.0"
[dependencies]
netutils = { path = "../../programs/netutils/" }
syscall = { path = "../../syscall/" }

View file

@ -1,11 +1,10 @@
extern crate netutils;
extern crate syscall;
use netutils::{getcfg, Ipv4Addr, MacAddr, Arp};
use std::thread;
use common::{MAC_ADDR, IP_ADDR, Arp};
pub mod common;
fn main() {
thread::spawn(move || {
while let Ok(link) = syscall::open("ethernet:/806", syscall::O_RDWR) {
@ -13,7 +12,10 @@ fn main() {
let mut bytes = [0; 65536];
if let Ok(count) = syscall::read(link, &mut bytes) {
if let Some(packet) = Arp::from_bytes(&bytes[..count]) {
if packet.header.oper.get() == 1 && packet.header.dst_ip.equals(unsafe { IP_ADDR }) {
let mac_addr = MacAddr::from_str(&getcfg("mac").expect("arpd: failed to get mac address"));
let ip_addr = Ipv4Addr::from_str(&getcfg("ip").expect("arpd: failed to get ip address"));
if packet.header.oper.get() == 1 && packet.header.dst_ip.equals(ip_addr) {
let mut response = Arp {
header: packet.header,
data: packet.data.clone(),
@ -21,8 +23,8 @@ fn main() {
response.header.oper.set(2);
response.header.dst_mac = packet.header.src_mac;
response.header.dst_ip = packet.header.src_ip;
response.header.src_mac = unsafe { MAC_ADDR };
response.header.src_ip = unsafe { IP_ADDR };
response.header.src_mac = mac_addr;
response.header.src_ip = ip_addr;
let _ = syscall::write(link, &response.to_bytes());
}