fn write_packet(&self, buf: &[u8], pi: Self::PktInfo) -> Result<usize, io::Error> {
        use libc::iovec;

        let hdr = pi.to_be_bytes();
        let iovs = [
            iovec {
                iov_base: hdr.as_ptr() as _,
                iov_len: hdr.len(),
            },
            iovec {
                iov_base: buf.as_ptr() as _,
                iov_len: buf.len(),
            },
        ];

        let idx = match self.packet_info {
            true => 0,
            false => 1,
        };

        // SAFETY: self.fd is guarenteed to be a valid/opened file descripter
        //         buf is guarenteed to be a valid u8 pointer with a set length
        match unsafe { libc::writev(self.fd, &iovs[idx] as *const _, (iovs.len() - idx) as _) } {
            -1 => Err(io::Error::last_os_error()),
            n => Ok(n as usize),
        }
    }
/// Writes a packet to the TUN device
///
/// # Arguments
/// * `buf` - Buffer to write
/// * `pi` - Packet information (address family of packet)
Writes a packet to the TUN device
Writes a packet to the TUN device
fn write_packet(&self, buf: &[u8], pi: Self::PktInfo) -> Result<usize, io::Error> {
        use libc::iovec;
        let hdr = pi.to_be_bytes();
        let iovs = [
            iovec {
                iov_base: hdr.as_ptr() as _,
                iov_len: hdr.len(),
            },
            iovec {
                iov_base: buf.as_ptr() as _,
                iov_len: buf.len(),
            },
        ];
        let idx = match self.packet_info {
            true => 0,
            false => 1,
        };
        // SAFETY: self.fd is guarenteed to be a valid/opened file descripter
        //         buf is guarenteed to be a valid u8 pointer with a set length
        match unsafe { libc::writev(self.fd, &iovs[idx] as *const _, (iovs.len() - idx) as _) } {
            -1 => Err(io::Error::last_os_error()),
            n => Ok(n as usize),
        }
    }
fn write_packet ( & self , buf : & [ u8 ] , pi : Self :: PktInfo ) -> Result < usize , io :: Error > { use libc :: iovec ; let hdr = pi . to_be_bytes ( ) ; let iovs = [ iovec { iov_base : hdr . as_ptr ( ) as _ , iov_len : hdr . len ( ) , } , iovec { iov_base : buf . as_ptr ( ) as _ , iov_len : buf . len ( ) , } , ] ; let idx = match self . packet_info { true => 0 , false => 1 , } ; // SAFETY: self.fd is guarenteed to be a valid/opened file descripter //         buf is guarenteed to be a valid u8 pointer with a set length match unsafe { libc :: writev ( self . fd , & iovs [ idx ] as * const _ , ( iovs . len ( ) - idx ) as _ ) } { - 1 => Err ( io :: Error :: last_os_error ( ) ) , n => Ok ( n as usize ) , } }
Writes a packet to the TUN device
Writes a packet to the TUN device
&self
buf
&[u8]
pi
Self::PktInfo
&self
buf
&[u8]
pi
Self::PktInfo