Add specification to vesad
Fix piping Fix bug where resources are not closed Add arpd Remove question_mark features
This commit is contained in:
parent
05a5c52f68
commit
ad448956d6
1 changed files with 359 additions and 92 deletions
38
schemes/arpd/src/main.rs
Normal file
38
schemes/arpd/src/main.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
extern crate syscall;
|
||||
|
||||
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) {
|
||||
loop {
|
||||
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 mut response = Arp {
|
||||
header: packet.header,
|
||||
data: packet.data.clone(),
|
||||
};
|
||||
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 };
|
||||
|
||||
let _ = syscall::write(link, &response.to_bytes());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let _ = syscall::close(link);
|
||||
}
|
||||
panic!("ARP: Failed to open ethernet");
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue