1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| #![no_std]
#![no_main]
#[macro_use]
#[path = "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;
}
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
}
|