This is what I use:

    my $c = $r->connection();
    my $client_addr = $c->client_addr->ip_get();
    my $client_port = $c->client_addr->port();

Regards,

Jie 

* A. Warnier <a...@ice-sa.com> wrote:

> Date: Sat, 29 Oct 2016 21:16:35 +0200
> From: "A. Warnier" <a...@ice-sa.com>
> To: mod_perl list <modperl@perl.apache.org>
> Subject: Apache 2.4, mod_perl 2.0.9, APR::SockAddr->port() missing ?
> User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:38.0) Gecko/20100101
>  Thunderbird/38.5.0
> 
> Hi.
> 
> Apologies to Steve and Torsten for posting this previously to them directly.
> It somehow slipped my mind that this would have been a better place.
> Anyway thus :
> 
> I am in the process of converting some mod_perl AAA code from Apache 2.2 to
> 2.4, and I encounter the following problem :
> 
> Apache error log :
> 
> Can't locate object method "port" via package "APR::SockAddr" at
> /home/mira/EFS/lib/AUTH/SLC.pm line 1184.\
> 
> which corresponds to :
> 
> 1183: my $client_addr = $r->connection->client_addr;
> 1184: $remote_port = $client_addr->port;
> 
> In the Apache 2.2 version, this was :
> 
>    $remote_port = $r->connection->remote_addr->port;
> 
> and worked fine.
> 
> Environment :
> 
> Linux d1s008 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02)
> x86_64 GNU/Linux (Debian "Jessie" as far as I know)
> 
> Apache/2.4.10 (Debian) mod_apreq2-20090110/2.8.0 mod_perl/2.0.9dev
> Perl/v5.20.2 configured -- resuming normal operations
> (apache2 and mod_perl are the standard Debian Jessie apt-get packages)
> 
> 
> I have tried to find clues on the WWW, CPAN etc.. but I do not find anything
> about APR::SockAddr::port(), except this snippet (quite old..) :
> 
> CPAN :
> mod_perl 2.10 Changes :
> ...
> 1.99_14 - May 21, 2004
> 
>     APR::SockAddr::port() accessor is now read-only [Stas]
> 
> Also on the host, the APR::SockAddr module source :
> 
> /usr/lib/x86_64-linux-gnu/perl5/5.20/APR/SockAddr.pm :
> 
> quote
> =item obj: C<$sock_addr>
> ( C<L<APR::SockAddr object|docs::2.0::api::APR::SockAddr>> )
> 
> =item ret: C<$port> ( integer )
> 
> =item since: 2.0.00
> unquote
> 
> .. seems to imply that this should work.
> (And so do
> https://metacpan.org/pod/APR::SockAddr#port
> http://perl.apache.org/docs/2.0/api/APR/SockAddr.html#C_port_
> )
> 
> Am I doing something wrong ?
> 
> More importantly to me right now : how can I get the client's connection
> port number, possibly using a workaround ? I am in control of the Apache
> httpd configuration.
> 
> I do not really care if this is the real client port, or a port of some
> intermediate proxy, as long as it remains consistent across severall
> KeepAlive calls of the same client workstation.
> I need this port number to forward to another module (of which I do not have
> the source), which uses this (and the remote IP), as a kind of persistent
> identifier for the client connection (for Windows WIA authentication).
> 
> The only way I can think of right now, would be to add a request header at
> the httpd level with the remote client IP:port, and then retrieve and decode
> that same header in my AAA module. But that seems a bit convoluted and
> heavy-handed.
> Is there a way in a PerlAuthenHandler to retrieve an "Apache environment
> variable" directly, which would have been set like so ?
> 
> RewriteRule .* - [E=INFO_REMOTE_ADDR:"%{REMOTE_ADDR}\:%{REMOTE_PORT}",NE]
> 
> 
> Thanks in advance
> André Warnier

Reply via email to