kratanet/nat/
key.rs

1use std::fmt::Display;
2
3use smoltcp::wire::{EthernetAddress, IpEndpoint};
4
5#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
6pub enum NatKeyProtocol {
7    Tcp,
8    Udp,
9    Icmp,
10}
11
12#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
13pub struct NatKey {
14    pub protocol: NatKeyProtocol,
15    pub client_mac: EthernetAddress,
16    pub local_mac: EthernetAddress,
17    pub client_ip: IpEndpoint,
18    pub external_ip: IpEndpoint,
19}
20
21impl Display for NatKey {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        write!(
24            f,
25            "{} -> {} {:?} {} -> {}",
26            self.client_mac, self.local_mac, self.protocol, self.client_ip, self.external_ip
27        )
28    }
29}