Skip to content

Commit

Permalink
network: force dig to use the records corresponding transport
Browse files Browse the repository at this point in the history
  • Loading branch information
ttrssreal authored and Gerschtli committed Dec 7, 2024
1 parent 20ce75f commit 8eede31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/features/network/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,21 @@ fn essid() -> Option<String> {
}

fn ip_address(address_type: &IpAddress) -> Option<String> {
let command = process::Command::new("dig", &[
let mut command = process::Command::new("dig", &[
// decrease time and tries because commands are executed synchronously
// TODO: make asychronous
"+time=3", // default: 5 seconds
"+tries=1", // default: 3
"@resolver1.opendns.com",
match address_type {
IpAddress::V4 => "A",
IpAddress::V6 => "AAAA",
},
"myip.opendns.com",
"+short",
]);

command.args(match address_type {
IpAddress::V4 => ["A", "-4"],
IpAddress::V6 => ["AAAA", "-6"],
});

let output = command.output().wrap_error(
FEATURE_NAME,
format!("ip address {} could not be fetched", address_type),
Expand Down
8 changes: 8 additions & 0 deletions src/wrapper/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ impl Command {
Self { command }
}

pub(crate) fn args<I, S>(&mut self, args: I)
where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
{
self.command.args(args);
}

pub(crate) fn output(mut self) -> Result<String> {
self.command
.output()
Expand Down

0 comments on commit 8eede31

Please sign in to comment.