Skip to content

Commit

Permalink
Merge pull request #6 from xmh0511/wintun
Browse files Browse the repository at this point in the history
Try creating tun again
  • Loading branch information
xmh0511 authored Dec 3, 2024
2 parents 0c607ec + 4dbf4dd commit b7d90a9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/platform/windows/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Device {
let device = if layer == Layer::L3 {
let wintun_file = &config.platform_config.wintun_file;
let wintun = unsafe { load_from_path(wintun_file)? };

let mut attempts = 0;
let adapter = loop {
let default_name = format!("tun{count}");
let name = config.name.as_deref().unwrap_or(&default_name);
Expand All @@ -167,7 +167,17 @@ impl Device {
if guid.is_none() {
guid.replace(hash_name(name));
}
break wintun::Adapter::create(&wintun, name, name, guid)?;
match wintun::Adapter::create(&wintun, name, name, guid) {
Ok(adapter) => break adapter,
Err(e) => {
if attempts > 3 {
Err(e)?
} else {
count += 1;
attempts += 1;
}
}
}
}
}
};
Expand Down

0 comments on commit b7d90a9

Please sign in to comment.