Add read and write functions for TunInterface

This adds read and write functionality for TunInterface.
This commit is contained in:
JettChenT 2023-05-29 10:36:10 +08:00 committed by Conrad Kramer
parent 9aa1951575
commit 82c4d218d7
5 changed files with 105 additions and 4 deletions

View file

@ -2,7 +2,7 @@ use fehler::throws;
use socket2::{Domain, SockAddr, Socket, Type};
use std::fs::OpenOptions;
use std::io::Error;
use std::io::{Error, Write};
use std::mem;
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6};
use std::os::fd::RawFd;
@ -140,6 +140,17 @@ impl TunInterface {
}
}
impl Write for TunInterface {
#[throws]
fn write(&mut self, buf: &[u8]) -> usize {
self.socket.send(buf)?
}
fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}
#[cfg(test)]
mod test {
use super::TunInterface;