Skip to content

Commit 8472200

Browse files
committed
feat: allow users to use --ipv{4,6} flags to bind to other addresses available on their local interfaces
1 parent bf0d100 commit 8472200

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ Options:
3636
Set the output format [csv, json or json-pretty] > This silences all other output to stdout [default: StdOut]
3737
-v, --verbose
3838
Enable verbose output i.e. print boxplots of the measurements
39-
--ipv4
40-
Force usage of IPv4
41-
--ipv6
42-
Force usage of IPv6
39+
--ipv4 [<IPv4>]
40+
Force IPv4 with provided source IPv4 address or the default IPv4 address bound to the main interface
41+
--ipv6 [<IPv6>]
42+
Force IPv6 with provided source IPv6 address or the default IPv6 address bound to the main interface
4343
-d, --disable-dynamic-max-payload-size
4444
Disables dynamically skipping tests with larger payload sizes if the tests for the previous payload size took longer than 5 seconds
4545
--download-only

examples/simple_speedtest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ fn main() {
77
// define speedtest options
88
let options = SpeedTestCLIOptions {
99
output_format: OutputFormat::None, // don't write to stdout
10-
ipv4: false, // don't force ipv4 usage
11-
ipv6: false, // don't force ipv6 usage
10+
ipv4: None, // don't force ipv4 usage
11+
ipv6: None, // don't force ipv6 usage
1212
verbose: false,
1313
upload_only: false,
1414
download_only: false,

src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ pub struct SpeedTestCLIOptions {
6161
#[arg(short, long)]
6262
pub verbose: bool,
6363

64-
/// Force usage of IPv4
65-
#[arg(long)]
66-
pub ipv4: bool,
64+
/// Force IPv4 with provided source IPv4 address or the default IPv4 address bound to the main interface
65+
#[clap(long, value_name = "IPv4", num_args = 0..=1, default_missing_value = "0.0.0.0", conflicts_with = "ipv6")]
66+
pub ipv4: Option<String>,
6767

68-
/// Force usage of IPv6
69-
#[arg(long)]
70-
pub ipv6: bool,
68+
/// Force IPv6 with provided source IPv6 address or the default IPv6 address bound to the main interface
69+
#[clap(long, value_name = "IPv6", num_args = 0..=1, default_missing_value = "::", conflicts_with = "ipv4")]
70+
pub ipv6: Option<String>,
7171

7272
/// Disables dynamically skipping tests with larger payload sizes if the tests for the previous payload
7373
/// size took longer than 5 seconds

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ fn main() {
2727
println!("Starting Cloudflare speed test");
2828
}
2929
let client;
30-
if options.ipv4 {
30+
if let Some(ref ip) = options.ipv4 {
3131
client = reqwest::blocking::Client::builder()
32-
.local_address("0.0.0.0".parse::<IpAddr>().unwrap())
32+
.local_address(ip.parse::<IpAddr>().expect("Invalid IPv4 address"))
3333
.build();
34-
} else if options.ipv6 {
34+
} else if let Some(ref ip) = options.ipv6 {
3535
client = reqwest::blocking::Client::builder()
36-
.local_address("::".parse::<IpAddr>().unwrap())
36+
.local_address(ip.parse::<IpAddr>().expect("Invalid IPv6 address"))
3737
.build();
3838
} else {
3939
client = reqwest::blocking::Client::builder().build();

0 commit comments

Comments
 (0)