On 9/24/07, Ruediger Pluem <[EMAIL PROTECTED]> wrote:
>
>
> On 09/23/2007 10:49 PM, Jeff Trawick wrote:
> > On 9/18/07, Plüm, Rüdiger, VF-Group <[EMAIL PROTECTED]> wrote:
> >>
> >>> -----Ursprüngliche Nachricht-----
> >>> Von: Adam Hasselbalch Hansen
> >>> Gesendet: Dienstag, 18. September 2007 12:25
> >>> An: dev@httpd.apache.org
> >>> Betreff: [PATCH 43415] Logging remote port.
> >>>
> >>>
> >>> I have created a patch for httpd 2.2.6, giving the additional
> >>> LogFormat
> >>> directive %R, which logs the port of the host making the request.
> >>>
> >>> This is due to new legislation in Denmark, requiring ISPs and hosting
> >>> companies to log the originating port of all traffic.
> >> 5 comments:
> >
> >> 3. I am not too happy with using %R, but to be honest I have no better 
> >> proposal :-).
> >>    Maybe other have.
> >
> > %{canonical}p          (default)
> > %{local}p
> > %{remote}p
>
> Sounds good to me.

The attached patch works for me (though I haven't yet rebuilt the docs
to see what that looks like).

[EMAIL PROTECTED] httpd]$ egrep
'(^ServerName|^.VirtualHost|^Listen|ports$)'
/scratch/inst/23/conf/httpd.conf
Listen 8089
    LogFormat "%h %l %u %t \"%r\" %>s %b PORTS: %p %{canonical}p
%{local}p %{remote}p %{bogusarg}p" ports
    CustomLog logs/access_log ports
<VirtualHost *:8089>
ServerName localhost:9999
[EMAIL PROTECTED] httpd]$ tail -1 /scratch/inst/23/logs/access_log
127.0.0.1 - - [24/Sep/2007:07:56:55 -0400] "GET / HTTP/1.0" 200 45
PORTS: 9999 9999 8089 65001 bogusarg
-- 
Born in Roswell... married an alien...
Index: modules/loggers/mod_log_config.c
===================================================================
--- modules/loggers/mod_log_config.c    (revision 578767)
+++ modules/loggers/mod_log_config.c    (working copy)
@@ -633,8 +633,22 @@
 
 static const char *log_server_port(request_rec *r, char *a)
 {
-    return apr_psprintf(r->pool, "%u",
-                        r->server->port ? r->server->port : 
ap_default_port(r));
+    apr_port_t port;
+
+    if (*a == '\0' || !strcmp(a, "canonical")) {
+        port = r->server->port ? r->server->port : ap_default_port(r);
+    }
+    else if (!strcmp(a, "remote")) {
+        port = r->connection->remote_addr->port;
+    }
+    else if (!strcmp(a, "local")) {
+        port = r->connection->local_addr->port;
+    }
+    else {
+        /* bogus format */
+        return a;
+    }
+    return pfmt(r->pool, (int)port);
 }
 
 /* This respects the setting of UseCanonicalName so that
Index: docs/manual/mod/mod_log_config.xml
===================================================================
--- docs/manual/mod/mod_log_config.xml  (revision 578767)
+++ docs/manual/mod/mod_log_config.xml  (working copy)
@@ -127,6 +127,12 @@
     <tr><td><code>%p</code></td>
         <td>The canonical port of the server serving the request</td></tr>
 
+    <tr><td><code>%{<var>format</var>}p</code></td>
+        <td>The canonical port of the server serving the request or the
+        server's actual port or the client's actual port.  Valid formats
+        are <code>canonical</code>, <code>local</code>, or <code>remote</code>.
+        </td></tr>
+
     <tr><td><code>%P</code></td>
         <td>The process ID of the child that serviced the request.</td></tr>
 

Reply via email to