RE: Re: HTTP server storing client's IP address?
"Jesus Manuel Conejo Sarabia" <[email protected]>
| Newsgroups | gmane.comp.hardware.rabbit-semiconductor |
|---|---|
| Message-ID | <002301cdb905$ef95cf40$cec16dc0$@com> |
Hi Raquel,
See this routine:
xmem void ip_to_bytes(longword ip){
ip1_ee = (byte)(ip >> 24);
ip2_ee = (byte)(ip >> 16);
ip3_ee = (byte)(ip >> 8);
ip4_ee = (byte)(ip);
}
xmem void analiza_ip_externa(tcp_Socket *s){
struct sockaddr sock_addr;
auto longword mi_ip;
auto unsigned char ip_externa[17];
if(0 == getpeername((tcp_Socket *) s,&sock_addr,NULL)){
ip_to_bytes(sock_addr.s_ip);
mi_ip = inet_addr(nip);
sprintf(ip_externa,"%d.%d.%d.%d",ip1_ee,ip2_ee,ip3_ee,ip4_ee);
}
}
Where ip1_ee,..,ip4_ee are global variables. As you can see all the info is
in the socket. If what you want is to know the IP address of the client that
is watching your Rabbit web site perhaps you can call this routine from
submit(HttpState* state) and using &state->s like your argument .
Hope this helps
Jesus
De: [email protected] [mailto:[email protected]] En
nombre de racqueldesign
Enviado el: viernes, 02 de noviembre de 2012 15:12
Para: [email protected]
Asunto: [rabbit-semi] Re: HTTP server storing client's IP address?
Hi Jesus,
Thanks for telling about the getpeername but I first need to know the name
of the socket. For example:
void main()
{
sock_init_or_exit(1);
http_init();
tcp_reserveport(80);
while (1)
{
http_handler();
}
}
I am guessing the http_init() setup the socket. Am i right or am I missing
something? I need my .cgi handler to get its client's ip address. Is there
also a function the returns a pointer to the current socket? I think that
might solve my problem with your advice.
--- In [email protected] <mailto:rabbit-semi%40yahoogroups.com> ,
"Jesus Manuel Conejo Sarabia" <jmconejo@...> wrote:
>
>
>
> Hi racquel,
>
> Yes!, using getpeername function from Dynamic C.
>
>
>
> Regards
>
> Jesus
>
>
>
>
>
>
>
>
>
> De: [email protected] <mailto:rabbit-semi%40yahoogroups.com>
[mailto:[email protected] <mailto:rabbit-semi%40yahoogroups.com> ]
En
> nombre de racqueldesign
> Enviado el: viernes, 02 de noviembre de 2012 13:45
> Para: [email protected] <mailto:rabbit-semi%40yahoogroups.com>
> Asunto: [rabbit-semi] HTTP server storing client's IP address?
>
>
>
>
>
> I have a HTTP Server running on the rabbit board but I don't know how to
> store the IP Address of any user that send an HTTP REQUEST. My question
is:
> is there a easy way for a server to acquire the IP address of its client?
>