#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AddressWithListOfOpenLocalLayer4Ports<A>
{
ipAddress: A,
whitelistOfPorts: HashSet<Layer4Port>,
}
impl<A> AddressWithListOfOpenLocalLayer4Ports<A>
{
#[inline(always)]
pub fn new(ipAddress: A, whitelistOfPorts: HashSet<Layer4Port>) -> Self
{
AddressWithListOfOpenLocalLayer4Ports
{
ipAddress: ipAddress,
whitelistOfPorts: whitelistOfPorts,
}
}
#[inline(always)]
pub fn blockedPortsForTldk(&self) -> TldkBlockedPortsList
{
const MinimumPortInclusive: usize = 1;
const MaximumPortExclusive: usize = 65536;
let mut blockedPorts = Vec::with_capacity(MaximumPortExclusive - self.whitelistOfPorts.len());
blockedPorts.push(0);
for port in MinimumPortInclusive..MaximumPortExclusive
{
let port = port as u16;
if !self.whitelistOfPorts.contains(&Layer4Port::convertFromTcpOrUdpOrSctpPortValueInLayer4Header(port).unwrap())
{
blockedPorts.push(port);
}
}
blockedPorts.sort();
return blockedPorts
}
}
impl AddressWithListOfOpenLocalLayer4Ports<Ipv4Addr>
{
#[inline(always)]
pub fn in_addr(&self) -> in_addr
{
IpV4HostAddress::from_Ipv4Addr_to_in_addr(&self.ipAddress)
}
}
impl AddressWithListOfOpenLocalLayer4Ports<Ipv6Addr>
{
#[inline(always)]
pub fn in6_addr(&self) -> in6_addr
{
IpV6HostAddress::from_Ipv6Addr_to_in6_addr(&self.ipAddress)
}
}