mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2025-07-17 05:04:59 +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:
@ -382,11 +382,11 @@ BUF *IkeBuildNatOaPayload(IKE_PACKET_NAT_OA_PAYLOAD *t)
|
||||
|
||||
if (IsIP6(&t->IpAddress))
|
||||
{
|
||||
WriteBuf(ret, t->IpAddress.ipv6_addr, 16);
|
||||
WriteBuf(ret, t->IpAddress.address, sizeof(t->IpAddress.address));
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteBuf(ret, t->IpAddress.addr, 4);
|
||||
WriteBuf(ret, IPV4(t->IpAddress.address), IPV4_SIZE);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -1233,8 +1233,8 @@ bool IkeParseIdPayload(IKE_PACKET_ID_PAYLOAD *t, BUF *b)
|
||||
return false;
|
||||
}
|
||||
|
||||
Zero(&ip, sizeof(ip));
|
||||
Zero(&subnet, sizeof(subnet));
|
||||
ZeroIP4(&ip);
|
||||
ZeroIP4(&subnet);
|
||||
|
||||
// Convert to string
|
||||
Zero(t->StrData, sizeof(t->StrData));
|
||||
@ -1247,9 +1247,9 @@ bool IkeParseIdPayload(IKE_PACKET_ID_PAYLOAD *t, BUF *b)
|
||||
break;
|
||||
|
||||
case IKE_ID_IPV4_ADDR:
|
||||
if (t->IdData->Size == 4)
|
||||
if (t->IdData->Size == IPV4_SIZE)
|
||||
{
|
||||
Copy(ip.addr, t->IdData->Buf, 4);
|
||||
Copy(IPV4(ip.address), t->IdData->Buf, IPV4_SIZE);
|
||||
|
||||
IPToStr(t->StrData, sizeof(t->StrData), &ip);
|
||||
}
|
||||
@ -1265,12 +1265,12 @@ bool IkeParseIdPayload(IKE_PACKET_ID_PAYLOAD *t, BUF *b)
|
||||
break;
|
||||
|
||||
case IKE_ID_IPV4_ADDR_SUBNET:
|
||||
if (t->IdData->Size == 8)
|
||||
if (t->IdData->Size == IPV4_SIZE * 2)
|
||||
{
|
||||
char ipstr[MAX_SIZE];
|
||||
char subnetstr[MAX_SIZE];
|
||||
Copy(ip.addr, t->IdData->Buf, 4);
|
||||
Copy(subnet.addr, ((UCHAR *)t->IdData->Buf) + 4, 4);
|
||||
Copy(IPV4(ip.address), t->IdData->Buf, IPV4_SIZE);
|
||||
Copy(IPV4(subnet.address), ((BYTE *)t->IdData->Buf) + IPV4_SIZE, IPV4_SIZE);
|
||||
|
||||
IPToStr(ipstr, sizeof(ipstr), &ip);
|
||||
MaskToStr(subnetstr, sizeof(subnetstr), &subnet);
|
||||
|
Reference in New Issue
Block a user