How to get ip of the user?

Asked by Dajan Zvekic on 2011-03-17

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:
2011-04-07
Last query:
2011-04-07
Last reply:
2011-04-05

This question was reopened

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?”.

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?

Dajan Zvekic (dajann) said : #3

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

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.

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.

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.

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.

Dajan Zvekic (dajann) said : #8

Thanks Alex Rousskov, that solved my question.