Question

Well I know that I should have tried a lot before asking here, but my problem is. It's hard to get structured reference of fcgi documentation. So i hope you won't downvote me that much, even in aspect of little lack of self study.

I'm trying to find a way to archive the IP of the requesting client.

As I guess (if I understood right) I could request the HTTP header of the connection by the FCGX_stream handle. But I would prefer a easier way if there is one.

My first try was checking it about the getenv as provided in the first fcgi tutorial, but as I tryed it as described here:

https://stackoverflow.com/a/4107212/2003898

It compiled fine, but on first request my fcgi app just crashed. (but it wouldn't solve my problem anyway as I figured out the get env is just requesting MY, so the host ones, env's)

I were also trying arround with the

*FCGX_GetParam(const char *name, FCGX_ParamArray envp);

function. But either I'm to stupid to use or it is also just providing my local evniroment and not the POST side's one.

So if anyone could tell me how to acces those data (prefered without extracting from HTTP header) or how to use FCGX_GetParam to acces it, I would be thankfull.

EDIT:

#include "fcgi_stdio.h"
#include <stdlib.h>
int main()
{       
    int count = 0;
    while(FCGI_Accept() >= 0)
    {
        for (count = 0; environ[count] != NULL; count++)
        {
            printf("%s\n", environ[i]);
        }
    }

    return 0;
}
Was it helpful?

Solution

Use getenv("REMOTE_ADDR")

The remote IP address isn't included in the HTTP headers anyway

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top