anti-ping 0.1.2

A library for ICMP, UDP, and TCP ping functionality
Documentation
//! # Ping Library
//!
//! A comprehensive library for network connectivity testing using ICMP, UDP, and TCP protocols.
//!
//! ## Features
//!
//! - **ICMP Ping**: Traditional ping using ICMP echo requests
//! - **UDP Ping**: Connectivity testing using UDP packets with ICMP error responses
//! - **TCP Ping**: Connection-based testing using TCP handshakes
//! - **Cross-platform**: Works on Unix-like systems with appropriate permissions
//! - **Async Support**: Non-blocking operations for high-performance applications
//!
//! ## Examples
//!
//! ### Simple ICMP ping
//!
//! ```rust,no_run
//! use anti_ping::{PingConfig, Pinger, PingMode};
//! use std::net::Ipv4Addr;
//!
//! let config = PingConfig {
//!     target: Ipv4Addr::new(8, 8, 8, 8),
//!     count: 4,
//!     ..Default::default()
//! };
//!
//! let mut pinger = Pinger::new(config, PingMode::Icmp)?;
//! let results = pinger.ping_all()?;
//! println!("Ping completed: {} packets sent", results.packets_transmitted);
//! # Ok::<(), anti_ping::PingError>(())
//! ```
//!
//! ### UDP connectivity test
//!
//! ```rust,no_run
//! use anti_ping::{PingConfig, Pinger, PingMode};
//! use std::net::Ipv4Addr;
//!
//! let config = PingConfig {
//!     target: Ipv4Addr::new(1, 1, 1, 1),
//!     count: 1,
//!     ..Default::default()
//! };
//!
//! let mut pinger = Pinger::new(config, PingMode::Udp)?;
//! let reply = pinger.ping_once()?;
//! println!("UDP ping RTT: {:?}", reply.rtt);
//! # Ok::<(), anti_ping::PingError>(())
//! ```

// Re-export items from the shared common crate
pub use anti_common as common;
pub mod icmp;
pub mod pinger;
pub mod tcp;
pub mod udp;

// Re-export main types for convenience
pub use common::{
    calculate_checksum, resolve_hostname, PingConfig, PingError, PingMode, PingReply, PingResult,
    PingStatistics,
};

pub use icmp::{IcmpPacket, IcmpSocket};
pub use pinger::{Pinger, PingerBuilder};
pub use tcp::TcpPinger;
pub use udp::UdpPinger;

// Re-export constants
pub use common::{icmp as icmp_constants, ports};

/// Library version
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg(test)]
mod tests {
    use super::*;
    use std::net::Ipv4Addr;

    #[test]
    fn test_ping_config_default() {
        let config = PingConfig::default();
        assert_eq!(config.target, Ipv4Addr::new(127, 0, 0, 1));
        assert_eq!(config.count, 4);
        assert_eq!(config.packet_size, 64);
    }

    #[test]
    fn test_ping_modes() {
        assert_eq!(PingMode::Icmp.to_string(), "ICMP");
        assert_eq!(PingMode::Udp.to_string(), "UDP");
        assert_eq!(PingMode::Tcp.to_string(), "TCP");
    }
}