feat(driver/net): 实现Loopback网卡接口 (#845)

* 初步实现loopback设备
This commit is contained in:
SMALLC
2024-07-22 16:22:45 +08:00
committed by GitHub
parent ef2a79be60
commit 1ea2daad81
10 changed files with 613 additions and 5 deletions

View File

@ -0,0 +1,25 @@
use std::net::UdpSocket;
use std::str;
fn main() -> std::io::Result<()> {
let socket = UdpSocket::bind("127.0.0.1:34254")?;
socket.connect("127.0.0.1:34254")?;
let msg = "Hello, loopback!";
socket.send(msg.as_bytes())?;
let mut buf = [0; 1024];
let (amt, _src) = socket.recv_from(&mut buf)?;
let received_msg = str::from_utf8(&buf[..amt]).expect("Could not read buffer as UTF-8");
println!("Sent: {}", msg);
println!("Received: {}", received_msg);
assert_eq!(
msg, received_msg,
"The sent and received messages do not match!"
);
Ok(())
}