UserSession: updated code to convert ipv6 mapped ipv4 address.

This commit is contained in:
Shreyas Zare
2023-01-14 13:33:14 +05:30
parent ea55fcd0ce
commit 31f35a5a22

View File

@@ -1,6 +1,6 @@
/*
Technitium DNS Server
Copyright (C) 2022 Shreyas Zare (shreyas@technitium.com)
Copyright (C) 2023 Shreyas Zare (shreyas@technitium.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -56,6 +56,9 @@ namespace DnsServerCore.Auth
if ((tokenName is not null) && (tokenName.Length > 255))
throw new ArgumentOutOfRangeException(nameof(tokenName), "Token name length cannot exceed 255 characters.");
if (remoteAddress.IsIPv4MappedToIPv6)
remoteAddress = remoteAddress.MapToIPv4();
byte[] tokenBytes = new byte[32];
_rng.GetBytes(tokenBytes);
_token = Convert.ToHexString(tokenBytes).ToLower();
@@ -104,6 +107,9 @@ namespace DnsServerCore.Auth
public void UpdateLastSeen(IPAddress remoteAddress, string lastSeenUserAgent)
{
if (remoteAddress.IsIPv4MappedToIPv6)
remoteAddress = remoteAddress.MapToIPv4();
_lastSeen = DateTime.UtcNow;
_lastSeenRemoteAddress = remoteAddress;
_lastSeenUserAgent = lastSeenUserAgent;