Commit aedd3a6b authored by Jan Moskyto Matejka's avatar Jan Moskyto Matejka Committed by Ondřej Zajíček

Implemented missing prefix manipulation functions

parent 5e173e9f
......@@ -96,6 +96,23 @@ net_validate(const net_addr *N)
}
}
void
net_normalize(net_addr *N)
{
net_addr_union *n = (void *) N;
switch (n->n.type)
{
case NET_IP4:
case NET_VPN4:
return net_normalize_ip4(&n->ip4);
case NET_IP6:
case NET_VPN6:
return net_normalize_ip6(&n->ip6);
}
}
int
net_classify(const net_addr *N)
{
......@@ -114,3 +131,31 @@ net_classify(const net_addr *N)
return 0;
}
int
ipa_in_netX(const ip_addr A, const net_addr *N)
{
switch (N->type)
{
case NET_IP4:
case NET_VPN4:
if (!ipa_is_ip4(A)) return 0;
break;
case NET_IP6:
case NET_VPN6:
if (ipa_is_ip4(A)) return 0;
break;
}
return ipa_zero(ipa_and(ipa_xor(A, net_prefix(N)), ipa_mkmask(net_pxlen(N))));
}
int
net_in_netX(const net_addr *A, const net_addr *N)
{
if (A->type != N->type)
return 0;
return (net_pxlen(N) <= net_pxlen(A)) && ipa_in_netX(net_prefix(A), N);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment