Added XFF header processing. Untested, for lack of proxy.

This commit is contained in:
Diva Canto
2010-09-03 17:18:53 -07:00
parent 107052b23d
commit 8fc68c6d98
6 changed files with 49 additions and 3 deletions

View File

@@ -28,6 +28,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Net.Sockets;
@@ -737,6 +738,7 @@ namespace OpenSim.Framework.Servers.HttpServer
if (methodWasFound)
{
xmlRprcRequest.Params.Add(request.Url); // Param[2]
xmlRprcRequest.Params.Add(request.Headers.Get("X-Forwarded-For")); // Param[3]
try
{

View File

@@ -1495,5 +1495,33 @@ namespace OpenSim.Framework
}
}
/// <summary>
/// Gets the client IP address
/// </summary>
/// <param name="xff"></param>
/// <returns></returns>
public static IPEndPoint GetClientIPFromXFF(string xff)
{
if (xff == string.Empty)
return null;
string[] parts = xff.Split(new char[] { ',' });
if (parts.Length > 0)
{
try
{
return new IPEndPoint(IPAddress.Parse(parts[0]), 0);
}
catch (Exception e)
{
m_log.WarnFormat("[UTIL]: Exception parsing XFF header {0}: {1}", xff, e.Message);
}
}
return null;
}
}
}