Skip to content

Commit

Permalink
Merge pull request #24 from Beepbop0/Beepbop0/check_opening_tun
Browse files Browse the repository at this point in the history
Check that opening /dev/net/tun is ok
  • Loading branch information
yaa110 authored Apr 7, 2024
2 parents aef5a67 + 2a4df76 commit 8892239
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/tun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,17 @@ impl Tun {
fn allocate(params: Params, queues: usize) -> Result<Interface> {
let fds = (0..queues)
.map(|_| unsafe {
libc::open(
let fd = libc::open(
TUN.as_ptr().cast::<c_char>(),
libc::O_RDWR | libc::O_NONBLOCK,
)
);
if fd < 0 {
Err(std::io::Error::last_os_error().into())
} else {
Ok(fd)
}
})
.collect::<Vec<_>>();
.collect::<Result<Vec<_>>>()?;

let iface = Interface::new(
fds,
Expand Down

0 comments on commit 8892239

Please sign in to comment.