You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Bhavna Saini <bh...@gmail.com> on 2012/12/14 06:56:43 UTC

[users@httpd] How to retrieve IP address of incoming packets in text file using httpd source code

Hi,

I am working on Apache httpd web server source code i.e. "httpd-2.2.23" for
my thesis.
I want to retrieve the IP addresses of the Clients from which the requests
are coming to web server and want to save it in a text file. How it can be
done using source code.
Please let me know the file of source code through which i can get it.

Thanks,
Bhavna

Re: [users@httpd] How to retrieve IP address of incoming packets in text file using httpd source code

Posted by Bhavna Saini <bh...@gmail.com>.
I have not used any PHP command up till now. I was trying to make it work
using the apache(httpd) source code itself.
Can it be done without using any script language?? OR by adding some code
lines in the apache source code files itself??

On Thu, Dec 27, 2012 at 1:01 AM, John Iliffe <jo...@iliffe.ca> wrote:

> Maybe I'm missing something following this discussion, but doesn't the
> following PHP command fetch the information you need?  If so, I'm sure the
> same results can be obtained in other scripting languages.
>
>  $_SERVER['REMOTE_ADDR'];
>
> Regards,
>
> John
> ===========================================
> On Wednesday 26 December 2012 11:54:38 Bhavna Saini wrote:
> > Thanks for the info.
> > I have gone through customlog and i understand that it is used to log
> > the IP and other parameters,
> > But I want to compare the IP address of incoming requests with IP
> > address present in a pre-built data structure. After comparing, the
> > request will be served accordingly.
> > Therefore, I need the source code file of apache which accepts requests
> > and through which I can get the IP at the initial stage.
> >
> > It would be really helpful if you could provide me this info.
> >
> > Thanks,
> >
> > -Bhavna
> >
> > On Thu, Dec 20, 2012 at 10:39 PM, Tom Evans
> <te...@googlemail.com>wrote:
> > > On Thu, Dec 20, 2012 at 4:20 PM, Bhavna Saini
> > > <bh...@gmail.com>
> > >
> > > wrote:
> > > > Hi Eric,
> > > >
> > > > In the previous mail you mentioned that "webserver can't write to
> > >
> > > /file.txt
> > >
> > > > from a child process". I couldn't get it properly. Please give some
> > > > more details of it.
> > >
> > > Eric is saying that normally only root can write to the root file
> > > system directory '/', and therefore a child process, typically running
> > > as apache or www, would not be able to write to it.
> > >
> > > > Actually I want to retrieve the IP addresses of incoming requests as
> > >
> > > soon as
> > >
> > > > it reaches the server and want to save it in a file. Please let me
> > > > know using which source code file of apache web server I can
> > > > perform it.
> > > >
> > > > Thanks,
> > > >
> > > > -Bhavna
> > >
> > > Why would you want to edit source code to do that?
> > >
> > > CustomLog logs/ip_request.log "%a %U"
> > >
> > > http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#customlog
> > >
> > > This would create a file at $SERVER_ROOT/logs/ip_request.log with
> > > contents like so:
> > >
> > > 192.168.1.1 /index.html
> > > 192.168.1.10 /favicon.ico
> > >
> > > Cheers
> > >
> > > Tom
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> > > For additional commands, e-mail: users-help@httpd.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] How to retrieve IP address of incoming packets in text file using httpd source code

Posted by "Bouchot j." <bo...@gmail.com>.
Hi Bhavna,

>> I need the source code file of apache which accepts requests and through which I can get the IP at the initial stage.
i think you looking for that <path-to-http-2.2.23>/server/listen.c line 174

   173  #ifdef MPM_ACCEPT_FUNC
   174      server->accept_func = MPM_ACCEPT_FUNC;
   175  #else
   176      server->accept_func = NULL;
   177  #endif

for unix environnment MPM_ACCEPT_FUNC is defined on
<path-to-http-2.2.23>/os/unix/unixd.c

AP_DECLARE(apr_status_t) unixd_accept(void **accepted, ap_listen_rec *lr,
   514                                          apr_pool_t *ptrans)
   515  {
   516      apr_socket_t *csd;
   517      apr_status_t status;
   518  #ifdef _OSD_POSIX
   519      int sockdes;
   520  #endif
   521
   522      *accepted = NULL;
   523      status = apr_socket_accept(&csd, lr->sd, ptrans);
   524      if (status == APR_SUCCESS) {
   525          *accepted = csd;
   526  #ifdef _OSD_POSIX
   527          apr_os_sock_get(&sockdes, csd);
   528          if (sockdes >= FD_SETSIZE) {
   529              ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL,
   530                           "new file descriptor %d is too large;
you probably need "
   531                           "to rebuild Apache with a larger FD_SETSIZE "
   532                           "(currently %d)",
   533                           sockdes, FD_SETSIZE);
   534              apr_socket_close(csd);
   535              return APR_EINTR;
   536          }
   537  #endif

i am newbie on httpd source code but in C language accept is the main
entry of all client so i think is the entry of all client of httpd
and according to  <path-to-apr-1.4.6>/network_io/unix/sockets.c

apr_status_t apr_os_sock_get(apr_os_sock_t *thesock, apr_socket_t *sock)
{
    *thesock = sock->socketdes;
    return APR_SUCCESS;
}

so after this

   527          apr_os_sock_get(&sockdes, csd);
   528          if (sockdes >= FD_SETSIZE) {

you could put your code there. Client socket is sockdes and is correctly set

I hope my help could be useful to you


2012/12/26 Nick Kew <ni...@webthing.com>:
>
> On 26 Dec 2012, at 19:31, John Iliffe wrote:
>
>> Maybe I'm missing something following this discussion, but doesn't the
>> following PHP command fetch the information you need?  If so, I'm sure the
>> same results can be obtained in other scripting languages.
>>
>> $_SERVER['REMOTE_ADDR'];
>
> You may want to update that.
>
> Since 2.4, apache makes the distinction between the the two different
> REMOTE_ADDR candidates: the peer making the TCP connection,
> and the client making the HTTP request.  In other words, the nearest
> proxy and the end-user.  The latter is of course very easy to spoof,
> but is nevertheless the one most applications want.
>
> To the OP, if you can't figure it out from what you've already been told,
> hire a techie.  You probably just want a competent sysop.
>
> --
> Nick Kew
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>



-- 
Jo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to retrieve IP address of incoming packets in text file using httpd source code

Posted by Nick Kew <ni...@webthing.com>.
On 26 Dec 2012, at 19:31, John Iliffe wrote:

> Maybe I'm missing something following this discussion, but doesn't the 
> following PHP command fetch the information you need?  If so, I'm sure the 
> same results can be obtained in other scripting languages.  
> 
> $_SERVER['REMOTE_ADDR'];

You may want to update that.

Since 2.4, apache makes the distinction between the the two different
REMOTE_ADDR candidates: the peer making the TCP connection,
and the client making the HTTP request.  In other words, the nearest
proxy and the end-user.  The latter is of course very easy to spoof,
but is nevertheless the one most applications want.

To the OP, if you can't figure it out from what you've already been told,
hire a techie.  You probably just want a competent sysop.

-- 
Nick Kew

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to retrieve IP address of incoming packets in text file using httpd source code

Posted by John Iliffe <jo...@iliffe.ca>.
Maybe I'm missing something following this discussion, but doesn't the 
following PHP command fetch the information you need?  If so, I'm sure the 
same results can be obtained in other scripting languages.  

 $_SERVER['REMOTE_ADDR'];

Regards,

John
===========================================
On Wednesday 26 December 2012 11:54:38 Bhavna Saini wrote:
> Thanks for the info.
> I have gone through customlog and i understand that it is used to log
> the IP and other parameters,
> But I want to compare the IP address of incoming requests with IP
> address present in a pre-built data structure. After comparing, the
> request will be served accordingly.
> Therefore, I need the source code file of apache which accepts requests
> and through which I can get the IP at the initial stage.
> 
> It would be really helpful if you could provide me this info.
> 
> Thanks,
> 
> -Bhavna
> 
> On Thu, Dec 20, 2012 at 10:39 PM, Tom Evans 
<te...@googlemail.com>wrote:
> > On Thu, Dec 20, 2012 at 4:20 PM, Bhavna Saini
> > <bh...@gmail.com>
> > 
> > wrote:
> > > Hi Eric,
> > > 
> > > In the previous mail you mentioned that "webserver can't write to
> > 
> > /file.txt
> > 
> > > from a child process". I couldn't get it properly. Please give some
> > > more details of it.
> > 
> > Eric is saying that normally only root can write to the root file
> > system directory '/', and therefore a child process, typically running
> > as apache or www, would not be able to write to it.
> > 
> > > Actually I want to retrieve the IP addresses of incoming requests as
> > 
> > soon as
> > 
> > > it reaches the server and want to save it in a file. Please let me
> > > know using which source code file of apache web server I can
> > > perform it.
> > > 
> > > Thanks,
> > > 
> > > -Bhavna
> > 
> > Why would you want to edit source code to do that?
> > 
> > CustomLog logs/ip_request.log "%a %U"
> > 
> > http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#customlog
> > 
> > This would create a file at $SERVER_ROOT/logs/ip_request.log with
> > contents like so:
> > 
> > 192.168.1.1 /index.html
> > 192.168.1.10 /favicon.ico
> > 
> > Cheers
> > 
> > Tom
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> > For additional commands, e-mail: users-help@httpd.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to retrieve IP address of incoming packets in text file using httpd source code

Posted by Bhavna Saini <bh...@gmail.com>.
Thanks for the info.
I have gone through customlog and i understand that it is used to log the
IP and other parameters,
But I want to compare the IP address of incoming requests with IP address
present in a pre-built data structure. After comparing, the request will be
served accordingly.
Therefore, I need the source code file of apache which accepts requests and
through which I can get the IP at the initial stage.

It would be really helpful if you could provide me this info.

Thanks,

-Bhavna

On Thu, Dec 20, 2012 at 10:39 PM, Tom Evans <te...@googlemail.com>wrote:

> On Thu, Dec 20, 2012 at 4:20 PM, Bhavna Saini <bh...@gmail.com>
> wrote:
> > Hi Eric,
> >
> > In the previous mail you mentioned that "webserver can't write to
> /file.txt
> > from a child process". I couldn't get it properly. Please give some more
> > details of it.
>
> Eric is saying that normally only root can write to the root file
> system directory '/', and therefore a child process, typically running
> as apache or www, would not be able to write to it.
>
> >
> > Actually I want to retrieve the IP addresses of incoming requests as
> soon as
> > it reaches the server and want to save it in a file. Please let me know
> > using which source code file of apache web server I can perform it.
> >
> > Thanks,
> >
> > -Bhavna
>
> Why would you want to edit source code to do that?
>
> CustomLog logs/ip_request.log "%a %U"
>
> http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#customlog
>
> This would create a file at $SERVER_ROOT/logs/ip_request.log with
> contents like so:
>
> 192.168.1.1 /index.html
> 192.168.1.10 /favicon.ico
>
> Cheers
>
> Tom
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] How to retrieve IP address of incoming packets in text file using httpd source code

Posted by Tom Evans <te...@googlemail.com>.
On Thu, Dec 20, 2012 at 4:20 PM, Bhavna Saini <bh...@gmail.com> wrote:
> Hi Eric,
>
> In the previous mail you mentioned that "webserver can't write to /file.txt
> from a child process". I couldn't get it properly. Please give some more
> details of it.

Eric is saying that normally only root can write to the root file
system directory '/', and therefore a child process, typically running
as apache or www, would not be able to write to it.

>
> Actually I want to retrieve the IP addresses of incoming requests as soon as
> it reaches the server and want to save it in a file. Please let me know
> using which source code file of apache web server I can perform it.
>
> Thanks,
>
> -Bhavna

Why would you want to edit source code to do that?

CustomLog logs/ip_request.log "%a %U"

http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#customlog

This would create a file at $SERVER_ROOT/logs/ip_request.log with
contents like so:

192.168.1.1 /index.html
192.168.1.10 /favicon.ico

Cheers

Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to retrieve IP address of incoming packets in text file using httpd source code

Posted by Bhavna Saini <bh...@gmail.com>.
Hi Eric,

In the previous mail you mentioned that "webserver can't write to /file.txt
from a child process". I couldn't get it properly. Please give some more
details of it.

Actually I want to retrieve the IP addresses of incoming requests as soon
as it reaches the server and want to save it in a file. Please let me know
using which source code file of apache web server I can perform it.

Thanks,

-Bhavna

On Sat, Dec 15, 2012 at 11:20 PM, Bhavna Saini <bh...@gmail.com>wrote:

>
>
> ---------- Forwarded message ----------
> From: Eric Covener <co...@gmail.com>
> Date: Sat, Dec 15, 2012 at 6:22 PM
> Subject: Re: [users@httpd] How to retrieve IP address of incoming packets
> in text file using httpd source code
> To: users@httpd.apache.org
>
>
> On Sat, Dec 15, 2012 at 5:04 AM, Bhavna Saini <bh...@gmail.com>
> wrote:
> > Thanks Eric. I need.one more help.
> > In mod_log_config file, I found  "r->connection->remote_ip" and
> > "r->connection->local_ip" fields. To retrieve the values of these fields
> i
> > wrote a small code in "mod_log_config" file itself under "static const
> char
> > *log_remote_address(request_rec *r, char *a)" which is as follows:
> > {
> > File *fp;
> > fp=fopen("/file.txt","a");
> > fprintf(fp,"%s",r->connection->remote_ip);
> > flose(fp);
> > }
> >  after that I compiled the whole httpd source code using "make" command,
> it
> > worked fine without any error. Then i sent request to the server from
> > different system, even than the file.txt didn't create nor the IP
> address.
> > Please let me know if I am doing it right or wrong. How do i perform it,
> so
> > that i can get IP addresses of all incoming requests as soon as they
> arrive
> > the server.
> >
>
> Your webserver can't write to /file.txt from a child process.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
>

Re: [users@httpd] How to retrieve IP address of incoming packets in text file using httpd source code

Posted by Eric Covener <co...@gmail.com>.
On Sat, Dec 15, 2012 at 5:04 AM, Bhavna Saini <bh...@gmail.com> wrote:
> Thanks Eric. I need.one more help.
> In mod_log_config file, I found  "r->connection->remote_ip" and
> "r->connection->local_ip" fields. To retrieve the values of these fields i
> wrote a small code in "mod_log_config" file itself under "static const char
> *log_remote_address(request_rec *r, char *a)" which is as follows:
> {
> File *fp;
> fp=fopen("/file.txt","a");
> fprintf(fp,"%s",r->connection->remote_ip);
> flose(fp);
> }
>  after that I compiled the whole httpd source code using "make" command, it
> worked fine without any error. Then i sent request to the server from
> different system, even than the file.txt didn't create nor the IP address.
> Please let me know if I am doing it right or wrong. How do i perform it, so
> that i can get IP addresses of all incoming requests as soon as they arrive
> the server.
>

Your webserver can't write to /file.txt from a child process.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] How to retrieve IP address of incoming packets in text file using httpd source code

Posted by Bhavna Saini <bh...@gmail.com>.
Thanks Eric. I need.one more help.
In mod_log_config file, I found  "r->connection->remote_ip" and
"r->connection->local_ip" fields. To retrieve the values of these fields i
wrote a small code in "mod_log_config" file itself under "static const
char*log_remote_address(request_rec *r,
char *a)" which is as follows:
{
File *fp;
fp=fopen("/file.txt","a");
fprintf(fp,"%s",r->connection->remote_ip);
flose(fp);
}
 after that I compiled the whole httpd source code using "make" command, it
worked fine without any error. Then i sent request to the server from
different system, even than the file.txt didn't create nor the IP address.
Please let me know if I am doing it right or wrong. How do i perform it, so
that i can get IP addresses of all incoming requests as soon as they arrive
the server.

Thanks
-Bhavna
On Fri, Dec 14, 2012 at 6:21 PM, Eric Covener <co...@gmail.com> wrote:

> mod_log_config writes out IP addresses to the log. You could read the
> same data in any hook.
>
> On Fri, Dec 14, 2012 at 12:56 AM, Bhavna Saini <bh...@gmail.com>
> wrote:
> > Hi,
> >
> > I am working on Apache httpd web server source code i.e. "httpd-2.2.23"
> for
> > my thesis.
> > I want to retrieve the IP addresses of the Clients from which the
> requests
> > are coming to web server and want to save it in a text file. How it can
> be
> > done using source code.
> > Please let me know the file of source code through which i can get it.
> >
> > Thanks,
> > Bhavna
>
>
>
> --
> Eric Covener
> covener@gmail.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] How to retrieve IP address of incoming packets in text file using httpd source code

Posted by Eric Covener <co...@gmail.com>.
mod_log_config writes out IP addresses to the log. You could read the
same data in any hook.

On Fri, Dec 14, 2012 at 12:56 AM, Bhavna Saini <bh...@gmail.com> wrote:
> Hi,
>
> I am working on Apache httpd web server source code i.e. "httpd-2.2.23" for
> my thesis.
> I want to retrieve the IP addresses of the Clients from which the requests
> are coming to web server and want to save it in a text file. How it can be
> done using source code.
> Please let me know the file of source code through which i can get it.
>
> Thanks,
> Bhavna



-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org