Skip to content

Commit

Permalink
revert GetIPv4AddressRanges/GetIPv6AddressRanges changes (incorrect s…
Browse files Browse the repository at this point in the history
…truct alignment)
  • Loading branch information
aspriddell committed May 1, 2024
1 parent 7f85578 commit dbf86d3
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions DragonFruit.OnionFruit.Web.Worker/Sources/LocationDbSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,15 @@ private static unsafe int BuildUnmanagedNetworkStructArray(ILocationDatabase net
}
}

private static unsafe NetworkAddressRangeInfo[] GetIPv4AddressRanges(IntPtr startPtr, nint length)
private static unsafe NetworkAddressRangeInfo[] GetIPv4AddressRanges(IntPtr start, nint length)
{
var v4NetworkRanges = new NetworkAddressRangeInfo[length];
var start = (IPv4NetworkRange*)startPtr;

Span<byte> v4AddressBytes = stackalloc byte[4];
var v4NetworkRanges = new NetworkAddressRangeInfo[length];

for (var i = 0; i < length; i++)
{
var entry = *(start + i);
var entry = *(IPv4NetworkRange*)(start + sizeof(IPv4NetworkRange) * i);

var startAddress = ParseAddress(v4AddressBytes, entry.start_address);
var endAddress = ParseAddress(v4AddressBytes, entry.end_address);

Expand All @@ -176,16 +175,15 @@ private static unsafe NetworkAddressRangeInfo[] GetIPv4AddressRanges(IntPtr star
return v4NetworkRanges;
}

private static unsafe NetworkAddressRangeInfo[] GetIPv6AddressRanges(IntPtr startPtr, nint length)
private static unsafe NetworkAddressRangeInfo[] GetIPv6AddressRanges(IntPtr start, nint length)
{
var v6NetworkRanges = new NetworkAddressRangeInfo[length];
var start = (IPv4NetworkRange*)startPtr;

Span<byte> v6AddressBytes = stackalloc byte[16];

for (var i = 0; i < length; i++)
{
var entry = *(start + i);
var entry = *(IPv6NetworkRange*)(start + sizeof(IPv6NetworkRange) * i);

var startAddress = ParseAddress(v6AddressBytes, entry.start_address);
var endAddress = ParseAddress(v6AddressBytes, entry.end_address);

Expand Down

0 comments on commit dbf86d3

Please sign in to comment.