Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use socket instead of ping command when pinging on android #7728

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions talpid-wireguard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ rand = "0.8.5"
surge-ping = "0.8.0"
rand_chacha = "0.3.1"
wireguard-go-rs = { path = "../wireguard-go-rs"}

[target.'cfg(target_os="android")'.dependencies]
duct = "0.13"

[target.'cfg(not(target_os="android"))'.dependencies]
byteorder = "1"
internet-checksum = "0.2"
socket2 = { workspace = true, features = ["all"] }
Expand Down
72 changes: 0 additions & 72 deletions talpid-wireguard/src/connectivity/pinger/android.rs

This file was deleted.

14 changes: 11 additions & 3 deletions talpid-wireguard/src/connectivity/pinger/icmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,19 @@ impl Pinger {
/// Creates a new `Pinger`.
pub fn new(
addr: Ipv4Addr,
#[cfg(not(target_os = "windows"))] interface_name: String,
#[cfg(any(target_os = "linux", target_os = "macos"))] interface_name: String,
) -> Result<Self> {
let addr = SocketAddr::new(addr.into(), 0);
let sock =
Socket::new(Domain::IPV4, Type::RAW, Some(Protocol::ICMPV4)).map_err(Error::Open)?;
let sock = Socket::new(
Domain::IPV4,
if cfg!(target_os = "android") {
Type::DGRAM
} else {
Type::RAW
},
Some(Protocol::ICMPV4),
)
.map_err(Error::Open)?;
sock.set_nonblocking(true).map_err(Error::Open)?;

#[cfg(target_os = "linux")]
Expand Down
12 changes: 3 additions & 9 deletions talpid-wireguard/src/connectivity/pinger/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#[cfg(target_os = "android")]
#[path = "android.rs"]
mod imp;
mod icmp;

#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[path = "icmp.rs"]
mod imp;

pub use imp::Error;
pub use icmp::Error;

/// Trait for sending ICMP requests to get some traffic from a remote server
#[async_trait::async_trait]
Expand All @@ -22,7 +16,7 @@ pub fn new_pinger(
addr: std::net::Ipv4Addr,
#[cfg(any(target_os = "linux", target_os = "macos"))] interface_name: String,
) -> Result<Box<dyn Pinger>, Error> {
Ok(Box::new(imp::Pinger::new(
Ok(Box::new(icmp::Pinger::new(
addr,
#[cfg(any(target_os = "linux", target_os = "macos"))]
interface_name,
Expand Down
Loading