pub struct VCLTun { /* private fields */ }Expand description
A TUN virtual network interface for capturing and injecting IP packets.
Requires root or CAP_NET_ADMIN. Linux only.
Implementations§
Source§impl VCLTun
impl VCLTun
Sourcepub fn create(config: TunConfig) -> Result<Self, VCLError>
pub fn create(config: TunConfig) -> Result<Self, VCLError>
Create and configure a new TUN interface.
§Errors
Returns VCLError::IoError if:
- Not running as root / missing
CAP_NET_ADMIN - Interface name is invalid or already in use
- TUN driver not available
Sourcepub async fn read_packet(&mut self) -> Result<Vec<u8>, VCLError>
pub async fn read_packet(&mut self) -> Result<Vec<u8>, VCLError>
Read the next IP packet from the TUN interface.
Blocks asynchronously until a packet is available. Returns raw bytes including the IP header.
§Errors
Returns VCLError::IoError on read failure.
Sourcepub async fn write_packet(&mut self, packet: &[u8]) -> Result<(), VCLError>
pub async fn write_packet(&mut self, packet: &[u8]) -> Result<(), VCLError>
Write (inject) a raw IP packet into the TUN interface.
The packet will appear as if it came from the network and will be delivered to the appropriate local socket.
§Errors
Returns VCLError::IoError on write failure.
Sourcepub fn destination(&self) -> Ipv4Addr
pub fn destination(&self) -> Ipv4Addr
Returns the remote destination IP of the TUN interface.
Auto Trait Implementations§
impl Freeze for VCLTun
impl !RefUnwindSafe for VCLTun
impl Send for VCLTun
impl Sync for VCLTun
impl Unpin for VCLTun
impl UnsafeUnpin for VCLTun
impl !UnwindSafe for VCLTun
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more