From 19d7e36adbd16c477eafff7aa829ee0c96e1ba3e Mon Sep 17 00:00:00 2001 From: Kerry Jiang Date: Sat, 17 Aug 2024 10:00:02 -0700 Subject: [PATCH] changed to other way to read ipv6 addresses --- .../ProxyProtocol/ProxyProtocolV2PartReader.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/SuperSocket.ProtoBase/ProxyProtocol/ProxyProtocolV2PartReader.cs b/src/SuperSocket.ProtoBase/ProxyProtocol/ProxyProtocolV2PartReader.cs index a95c424f0..60aaf93e6 100644 --- a/src/SuperSocket.ProtoBase/ProxyProtocol/ProxyProtocolV2PartReader.cs +++ b/src/SuperSocket.ProtoBase/ProxyProtocol/ProxyProtocolV2PartReader.cs @@ -12,6 +12,8 @@ class ProxyProtocolV2PartReader : ProxyProtocolPackagePartReader _bufferPool = ArrayPool.Shared; public override bool Process(TPackageInfo package, object filterContext, ref SequenceReader reader, out IPackagePartReader nextPartReader, out bool needMoreData) @@ -93,21 +95,18 @@ public override bool Process(TPackageInfo package, object filterContext, ref Seq } else if (proxyInfo.AddressFamily == AddressFamily.InterNetworkV6) { - var addressBuffer = _bufferPool.Rent(IPV6_ADDRESS_LEN); + var addressBuffer = _bufferPool.Rent(IPV6_ADDRESS_ALL_LEN); try { - var addressBufferSpan = addressBuffer.AsSpan().Slice(0, IPV6_ADDRESS_LEN); - - var sequenceToRead = reader.UnreadSequence; + var addressBufferSpan = addressBuffer.AsSpan().Slice(0, IPV6_ADDRESS_ALL_LEN); - sequenceToRead.Slice(0, IPV6_ADDRESS_LEN).CopyTo(addressBufferSpan); - proxyInfo.SourceIPAddress = new IPAddress(addressBufferSpan); + reader.TryCopyTo(addressBufferSpan); - sequenceToRead.Slice(IPV6_ADDRESS_LEN, IPV6_ADDRESS_LEN).CopyTo(addressBufferSpan); - proxyInfo.DestinationIPAddress = new IPAddress(addressBufferSpan); + proxyInfo.SourceIPAddress = new IPAddress(addressBufferSpan.Slice(0, IPV6_ADDRESS_LEN)); + proxyInfo.DestinationIPAddress = new IPAddress(addressBufferSpan.Slice(IPV6_ADDRESS_LEN)); - reader.Advance(IPV6_ADDRESS_LEN * 2); + reader.Advance(IPV6_ADDRESS_ALL_LEN); } finally {