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 {