Fix: Wrong function call in std::net under unix target
This commit is contained in:
@@ -6,15 +6,15 @@ use pnet::packet::icmpv6::{Icmpv6Packet, Icmpv6Types};
|
||||
use pnet::packet::ip::IpNextHeaderProtocols;
|
||||
#[cfg(unix)]
|
||||
use pnet::transport::{
|
||||
icmp_packet_iter, icmpv6_packet_iter, transport_channel, TransportChannelType,
|
||||
TransportProtocol,
|
||||
TransportChannelType, TransportProtocol, icmp_packet_iter, icmpv6_packet_iter,
|
||||
transport_channel,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use socket2::{Domain, Protocol, Socket, Type};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::time::{Duration, Instant};
|
||||
use thiserror::Error;
|
||||
use tokio::net::{lookup_host, TcpStream};
|
||||
use tokio::net::{TcpStream, lookup_host};
|
||||
use tokio::time::timeout;
|
||||
use wtfnet_geoip::GeoIpRecord;
|
||||
|
||||
@@ -117,18 +117,19 @@ pub async fn ping(
|
||||
.kind(surge_ping::ICMP::V6)
|
||||
.build(),
|
||||
};
|
||||
let client = surge_ping::Client::new(&config)
|
||||
.map_err(|err| ProbeError::Ping(err.to_string()))?;
|
||||
let mut pinger = client
|
||||
.pinger(addr, surge_ping::PingIdentifier(0))
|
||||
.await;
|
||||
let client =
|
||||
surge_ping::Client::new(&config).map_err(|err| ProbeError::Ping(err.to_string()))?;
|
||||
let mut pinger = client.pinger(addr, surge_ping::PingIdentifier(0)).await;
|
||||
let timeout_dur = Duration::from_millis(timeout_ms);
|
||||
|
||||
for seq in 0..count {
|
||||
let seq = seq as u16;
|
||||
let start = Instant::now();
|
||||
let response =
|
||||
timeout(timeout_dur, pinger.ping(surge_ping::PingSequence(seq), &[0; 8])).await;
|
||||
let response = timeout(
|
||||
timeout_dur,
|
||||
pinger.ping(surge_ping::PingSequence(seq), &[0; 8]),
|
||||
)
|
||||
.await;
|
||||
match response {
|
||||
Ok(Ok((_packet, _))) => {
|
||||
let rtt = start.elapsed().as_millis();
|
||||
@@ -250,9 +251,8 @@ pub async fn tcp_trace(
|
||||
for ttl in 1..=max_hops {
|
||||
let addr = socket_addr;
|
||||
let start = Instant::now();
|
||||
let result = tokio::task::spawn_blocking(move || {
|
||||
tcp_connect_with_ttl(addr, ttl, timeout_dur)
|
||||
})
|
||||
let result =
|
||||
tokio::task::spawn_blocking(move || tcp_connect_with_ttl(addr, ttl, timeout_dur))
|
||||
.await
|
||||
.map_err(|err| ProbeError::Io(err.to_string()))?;
|
||||
|
||||
@@ -385,11 +385,7 @@ async fn resolve_one(target: &str) -> Result<IpAddr, ProbeError> {
|
||||
.ok_or_else(|| ProbeError::Resolve("no address found".to_string()))
|
||||
}
|
||||
|
||||
fn tcp_connect_with_ttl(
|
||||
addr: SocketAddr,
|
||||
ttl: u8,
|
||||
timeout: Duration,
|
||||
) -> Result<(), ProbeError> {
|
||||
fn tcp_connect_with_ttl(addr: SocketAddr, ttl: u8, timeout: Duration) -> Result<(), ProbeError> {
|
||||
let domain = match addr.ip() {
|
||||
IpAddr::V4(_) => Domain::IPV4,
|
||||
IpAddr::V6(_) => Domain::IPV6,
|
||||
@@ -441,11 +437,11 @@ fn udp_trace_hop_v4(
|
||||
) -> Result<(Option<IpAddr>, bool), ProbeError> {
|
||||
let protocol =
|
||||
TransportChannelType::Layer4(TransportProtocol::Ipv4(IpNextHeaderProtocols::Icmp));
|
||||
let (_tx, mut rx) = transport_channel(4096, protocol)
|
||||
.map_err(|err| ProbeError::Io(err.to_string()))?;
|
||||
let (_tx, mut rx) =
|
||||
transport_channel(4096, protocol).map_err(|err| ProbeError::Io(err.to_string()))?;
|
||||
|
||||
let socket = std::net::UdpSocket::bind("0.0.0.0:0")
|
||||
.map_err(|err| ProbeError::Io(err.to_string()))?;
|
||||
let socket =
|
||||
std::net::UdpSocket::bind("0.0.0.0:0").map_err(|err| ProbeError::Io(err.to_string()))?;
|
||||
socket
|
||||
.set_ttl(u32::from(ttl))
|
||||
.map_err(|err| ProbeError::Io(err.to_string()))?;
|
||||
@@ -472,13 +468,13 @@ fn udp_trace_hop_v6(
|
||||
) -> Result<(Option<IpAddr>, bool), ProbeError> {
|
||||
let protocol =
|
||||
TransportChannelType::Layer4(TransportProtocol::Ipv6(IpNextHeaderProtocols::Icmpv6));
|
||||
let (_tx, mut rx) = transport_channel(4096, protocol)
|
||||
.map_err(|err| ProbeError::Io(err.to_string()))?;
|
||||
let (_tx, mut rx) =
|
||||
transport_channel(4096, protocol).map_err(|err| ProbeError::Io(err.to_string()))?;
|
||||
|
||||
let socket = std::net::UdpSocket::bind("[::]:0")
|
||||
.map_err(|err| ProbeError::Io(err.to_string()))?;
|
||||
let socket =
|
||||
std::net::UdpSocket::bind("[::]:0").map_err(|err| ProbeError::Io(err.to_string()))?;
|
||||
socket
|
||||
.set_unicast_hops_v6(u32::from(ttl))
|
||||
.set_multicast_hops_v6(u32::from(ttl))
|
||||
.map_err(|err| ProbeError::Io(err.to_string()))?;
|
||||
let _ = socket.send_to(&[0u8; 4], addr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user