#![no_std] #![no_main] use lancer_user::net; use lancer_user::syscall; #[unsafe(no_mangle)] pub extern "C" fn lancer_main() -> ! { let (rx, tx) = match net::init() { Some(pair) => pair, None => { lancer_user::show!(net, error, "netsock init failed"); syscall::exit(); } }; if !net::has_relay() { lancer_user::io::write_bytes(b"networking not available (use SSH)\n"); syscall::exit(); } let mut args_buf = [0u8; 64]; let _ = net::recv_args(&rx, &mut args_buf); net::send_request(&tx, &[net::MSG_ARP_REQUEST]); let mut resp = [0u8; 64]; let mut done = false; core::iter::from_fn(|| match done { true => None, false => { let n = net::recv_response_blocking(&rx, &mut resp); match n < 1 { true => None, false => match resp[0] { net::MSG_ARP_DONE => { done = true; None } net::MSG_ARP_ENTRY if n >= 12 => { let mut out = [0u8; 64]; let mut pos = 0usize; let ip_len = net::write_ip_decimal(&mut out[pos..], &resp[1..5]); pos += ip_len; (pos..18).for_each(|i| { out[i] = b' '; }); pos = pos.max(18); pos = write_mac(&mut out, pos, &resp[5..11]); (pos..pos + 4).for_each(|i| { out[i] = b' '; }); pos += 4; let age_secs = ((resp[11] as u16) << 8) | resp[12] as u16; let age_len = net::write_u16_decimal(&mut out[pos..], age_secs); pos += age_len; out[pos] = b's'; pos += 1; out[pos] = b'\n'; pos += 1; lancer_user::io::write_bytes(&out[..pos]); Some(()) } _ => Some(()), }, } } }) .take(16) .count(); syscall::exit() } fn write_mac(buf: &mut [u8], start: usize, mac: &[u8]) -> usize { let hex = |n: u8| -> u8 { match n < 10 { true => b'0' + n, false => b'a' + (n - 10), } }; let mut p = start; (0..6).for_each(|i| { if i > 0 { buf[p] = b':'; p += 1; } buf[p] = hex(mac[i] >> 4); buf[p + 1] = hex(mac[i] & 0x0f); p += 2; }); p }