How to get ip of the user?

Asked by Dajan Zvekic

Hi,

Is it possible to get the IP address of the user who requested page in the adapter? If it is how can i do it?

e.g. I am requesting page: https://answers.launchpad.net/ecap/, and in adapter I want to get to my IP.

Question information

Language:
English Edit question
Status:
Solved
For:
eCAP Edit question
Assignee:
No assignee Edit question
Solved by:
Alex Rousskov
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Alex Rousskov (rousskov) said :
#1

Alex Rousskov suggests this article as an answer to your question:
FAQ #1516: “How to get the HTTP client IP address?”.

Revision history for this message
Dajan Zvekic (dajann) said :
#2

Hi,

After installing new versions of libecap and squid, I cant run squid at all.
When i run it i am getting this error:
    ./squid: error while loading shared libraries: libecap.so.2: cannot open shared object file: No such file or directory
Do you have an idea what is going on?

Revision history for this message
Dajan Zvekic (dajann) said :
#3

Ok, found the problem.
I needed to refresh lib cache manually.

Revision history for this message
Dajan Zvekic (dajann) said :
#4

Hi,

Please, can you explain in more details how to get to the Ip.
Because there is no member libecap::host::Xaction::option();

I only found libecap::Options and cfg object which is passed to method configure.
I was thinking i need code like this:

const libecap::Name metaIp = libecap::Name("metaClientIp");
const libecap::Area area = cfg.option(metaIp);
libecap::AreaDetails *details = area.details.get();

?? that is what i can do with this cfg object in configure method.
Also, I need IP in Xaction::start() method.

Revision history for this message
Alex Rousskov (rousskov) said :
#5

libecap::host::Xaction inherits the pure virtual option() method the from libecap::Options parent. Host applications implement that method to provide adapters with transaction-specific meta-information. If your adapter calls this method with libecap::metaClientIp name as a parameter, it may get the client IP address string back.

For more information, please see libecap/host/xaction.h, libecap/common/options.h, and libecap/common/names.h.

Revision history for this message
Dajan Zvekic (dajann) said :
#6

Hi Alex,

I'm using 3p2-ecap squid and in adapter I have line: libecap::Area area = hostx->option(libecap::metaClientIp) and when I debbug adapter every time this area object and area.details object is empty.
Am I doing something wrong? You said that adapter "may" get IP, well if this option() method is implemented adapter should get ip with above call? or not? I suppose 3p2-ecap squid implements this method?

Thank you in advance for your answer.

Revision history for this message
Best Alex Rousskov (rousskov) said :
#7

Yes, 3p2-ecap (and Squid v3.2.0.6) support libecap::metaClientIp reporting.

Did you set adaptation_send_client_ip option in squid.conf to on? If not, please do.

Revision history for this message
Dajan Zvekic (dajann) said :
#8

Thanks Alex Rousskov, that solved my question.