aisk / rust-ping

MIT License
21 stars 19 forks source link

With a correct request and response on dgramsock: DecodeV4Error #23

Open PlexSheep opened 2 weeks ago

PlexSheep commented 2 weeks ago

Using ping::dgramsock::ping, I get a DecodeV4Error, even though I can see with Wireshark that the request and response have no error. Pinging with the same address (1.1.1.1) with the ping shell command from iputils works without error.

How I use it:

use std::net::IpAddr;

use crate::errors::CheckError;
use crate::TIMEOUT; // std::time::Duration

pub fn just_ping(remote: IpAddr) -> Result<u16, CheckError> {
    let now = std::time::Instant::now();
    match ping::dgramsock::ping(remote, Some(TIMEOUT), None, None, None, None) {
        Ok(_) => Ok(now.elapsed().as_millis() as u16),
        Err(e) => {
            eprintln!("Error while makeing the ping check: {e}");
            Err(e.into())
        }
    }
}

ICMP Packets in Wireshark

Request

Frame 63: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on interface enxc025a5e765ed, id 0
Ethernet II, Src: Dell_e7:65:ed (c0:25:a5:e7:65:ed), Dst: AVMAudio_2a:2e:aa (44:4e:6d:2a:2e:aa)
Internet Protocol Version 4, Src: 192.168.178.65, Dst: 1.1.1.1
Internet Control Message Protocol
    Type: 8 (Echo (ping) request)
    Code: 0
    Checksum: 0x3aa3 [correct]
    [Checksum Status: Good]
    Identifier (BE): 31 (0x001f)
    Identifier (LE): 7936 (0x1f00)
    Sequence Number (BE): 1 (0x0001)
    Sequence Number (LE): 256 (0x0100)
    [Response frame: 64]
    Data (24 bytes)
        Data: 26a93b714e93eb7a8655955c6710ca17b34556758d713d0d
        [Length: 24]

Reply

Frame 64: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on interface enxc025a5e765ed, id 0
Ethernet II, Src: AVMAudio_2a:2e:aa (44:4e:6d:2a:2e:aa), Dst: Dell_e7:65:ed (c0:25:a5:e7:65:ed)
Internet Protocol Version 4, Src: 1.1.1.1, Dst: 192.168.178.65
Internet Control Message Protocol
    Type: 0 (Echo (ping) reply)
    Code: 0
    Checksum: 0x42a3 [correct]
    [Checksum Status: Good]
    Identifier (BE): 31 (0x001f)
    Identifier (LE): 7936 (0x1f00)
    Sequence Number (BE): 1 (0x0001)
    Sequence Number (LE): 256 (0x0100)
    [Request frame: 63]
    [Response time: 18,721 ms]
    Data (24 bytes)
        Data: 26a93b714e93eb7a8655955c6710ca17b34556758d713d0d
        [Length: 24]
PlexSheep commented 2 weeks ago

Update: also does not work when I ping 127.0.0.1, but the rawsock variant works.