use crate::types::tcp_state::TcpState;
use std::net::IpAddr;
#[derive(Clone, Debug, PartialEq)]
pub struct SocketInfo {
pub protocol_socket_info: ProtocolSocketInfo,
pub associated_pids: Vec<u32>,
#[cfg(any(target_os = "linux", target_os = "android"))]
pub inode: u32,
#[cfg(any(target_os = "linux", target_os = "android"))]
pub uid: u32,
}
#[derive(Clone, Debug, PartialEq)]
pub enum ProtocolSocketInfo {
Tcp(TcpSocketInfo),
Udp(UdpSocketInfo),
}
#[derive(Clone, Debug, PartialEq)]
pub struct TcpSocketInfo {
pub local_addr: IpAddr,
pub local_port: u16,
pub remote_addr: IpAddr,
pub remote_port: u16,
pub state: TcpState,
}
#[derive(Clone, Debug, PartialEq)]
pub struct UdpSocketInfo {
pub local_addr: IpAddr,
pub local_port: u16,
}
impl SocketInfo {
pub fn local_addr(&self) -> IpAddr {
match &self.protocol_socket_info {
ProtocolSocketInfo::Tcp(s) => s.local_addr,
ProtocolSocketInfo::Udp(s) => s.local_addr,
}
}
pub fn local_port(&self) -> u16 {
match &self.protocol_socket_info {
ProtocolSocketInfo::Tcp(s) => s.local_port,
ProtocolSocketInfo::Udp(s) => s.local_port,
}
}
}