1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2025-07-07 00:04:57 +03:00

Change IP structure so that IPv4 addresses are stored in RFC3493 format

In addition to saving 4 bytes for each instantiation, this change makes IP-related operations faster and clearer.

https://tools.ietf.org/html/rfc3493.html#section-3.7
This commit is contained in:
Davide Beatrici
2021-04-07 21:24:55 +02:00
parent 01663f836d
commit 1708998a11
21 changed files with 295 additions and 403 deletions

View File

@ -2255,15 +2255,14 @@ bool NnParseDnsResponsePacket(UCHAR *data, UINT size, IP *ret_ip)
if (r != NULL)
{
if (tp == 0x0001 && cl == 0x0001 && r->Size == 4)
if (tp == 0x0001 && cl == 0x0001 && r->Size == IPV4_SIZE)
{
ret = true;
if (ret_ip != NULL)
{
Zero(ret_ip, sizeof(IP));
Copy(ret_ip->addr, r->Buf, 4);
ZeroIP4(ret_ip);
Copy(IPV4(ret_ip->address), r->Buf, IPV4_SIZE);
}
}
@ -3708,10 +3707,10 @@ bool ArpaToIP(IP *ip, char *str)
{
// Convert the token [0, 1, 2, 3] to IP
UINT i;
Zero(ip, sizeof(IP));
for (i = 0; i < 4; i++)
ZeroIP4(ip);
for (i = 0; i < IPV4_SIZE; ++i)
{
ip->addr[i] = (UCHAR)ToInt(token->Token[3 - i]);
IPV4(ip->address)[i] = (UCHAR)ToInt(token->Token[3 - i]);
}
ret = true;
}
@ -5536,7 +5535,7 @@ void VirtualTcpReceived(VH *v, UINT src_ip, UINT dest_ip, void *data, UINT size,
}
UINTToIP(&ip1, src_ip);
UINTToIP(&ip2, dest_ip);
if (ip1.addr[0] == 127 || ip2.addr[0] == 127)
if (IsLocalHostIP4(&ip1) || IsLocalHostIP4(&ip2))
{
// Loopback IP address can not be specified
return;