//! `ifconfig` (alias `ip`): show the network card and our IP address. //! //! eth0: virtio-net MAC 52:54:00:12:34:56 IRQ 11 //! inet 10.0.2.15/24 gateway 10.0.2.2 DNS 10.0.2.3 (DHCP) //! RX 12 packets (2 KiB) TX 9 packets (1 KiB) #![no_std] #![no_main] #[macro_use] #[path = "../../../rbrt/ulib.rs"] mod ulib; use ulib::Ip; fn main() -> i64 { let mut info = ulib::netinfo(); if info.present == 0 { eprintln!("ifconfig: no network card (QEMU needs -device virtio-net-pci)"); return 1; } // Right after boot DHCP may still be running: give it up to 3 s. for _ in 0..30 { if info.configured != 0 { break; } ulib::sleep_ms(100); info = ulib::netinfo(); } let m = info.mac; println!( "eth0: virtio-net MAC {:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x} IRQ {}", m[0], m[1], m[2], m[3], m[4], m[5], info.irq ); if info.configured != 0 { println!( " inet {}/{} gateway {} DNS {} (DHCP)", Ip(info.address), info.prefix_len, Ip(info.gateway), Ip(info.dns) ); } else { println!(" no address yet (waiting for DHCP)"); } println!( " RX {} packets ({} KiB) TX {} packets ({} KiB)", info.rx_packets, info.rx_bytes / 1024, info.tx_packets, info.tx_bytes / 1024 ); 0 }