aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs
diff options
context:
space:
mode:
authorVooDooS <thevoodoos@gmail.com>2019-04-11 17:13:40 +0200
committerVooDooS <thevoodoos@gmail.com>2019-04-11 17:49:18 +0200
commit56d1050bac3a56249acd7f3b3615f796683e0783 (patch)
tree44b2e4e2aed035d8c87454a07347f38d263e28ce /Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs
parenta6e1b23eb04d620e241e4babbcb6ee0ffbf156a9 (diff)
Replace custom ip "normalization" by methods from `IPAddress`
Diffstat (limited to 'Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs')
-rw-r--r--Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs21
1 files changed, 10 insertions, 11 deletions
diff --git a/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs b/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs
index 957371df6..d153a85a3 100644
--- a/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs
+++ b/Emby.Server.Implementations/SocketSharp/WebSocketSharpRequest.cs
@@ -62,10 +62,10 @@ namespace Emby.Server.Implementations.SocketSharp
temp = CheckBadChars(GetHeader(HeaderNames.XRealIP).AsSpan());
if (temp.Length != 0)
{
- return remoteIp = NormalizeIp(temp).ToString();
+ return remoteIp = NormalizeIp(temp.ToString()).ToString();
}
- return remoteIp = NormalizeIp(request.HttpContext.Connection.RemoteIpAddress.ToString().AsSpan()).ToString();
+ return remoteIp = NormalizeIp(request.HttpContext.Connection.RemoteIpAddress).ToString();
}
}
@@ -137,22 +137,21 @@ namespace Emby.Server.Implementations.SocketSharp
return name;
}
- private ReadOnlySpan<char> NormalizeIp(ReadOnlySpan<char> ip)
+ private IPAddress NormalizeIp(IPAddress ip)
{
- if (ip.Length != 0 && !ip.IsWhiteSpace())
+ if (ip.IsIPv4MappedToIPv6)
{
- // Handle ipv4 mapped to ipv6
- const string srch = "::ffff:";
- var index = ip.IndexOf(srch.AsSpan(), StringComparison.OrdinalIgnoreCase);
- if (index == 0)
- {
- ip = ip.Slice(srch.Length);
- }
+ return ip.MapToIPv4();
}
return ip;
}
+ private IPAddress NormalizeIp(string sip)
+ {
+ return NormalizeIp(IPAddress.Parse(sip));
+ }
+
public string[] AcceptTypes => request.Headers.GetCommaSeparatedValues(HeaderNames.Accept);
private Dictionary<string, object> items;