On 10/12/03 8:36 pm, D.Kreft <[EMAIL PROTECTED]> wrote:

> On Wed, 10 Dec 2003, Chris Ridd did scribble:
> 
>> On 10/12/03 7:58 pm, D.Kreft <[EMAIL PROTECTED]> wrote:
>> 
>>> On Wed, 10 Dec 2003, Chris Ridd did scribble:
>>> 
>>>> $ldap->socket->peername returns the peer address and port. $ldap->socket's
>>>> documented as well ;-)
>>> 
>>> I just grepped the perldocs for Net::LDAP (v0.2701) and didn't see any
>>> mention of 'peername' or 'socket'. Am I missing something, or has
>>> documentation for this little "trick" been added since 0.2701?
>> 
>> Good point - I'm using 0.30. The socket method existed in 0.2701 (I just
>> checked), but wasn't documented until more recently (I didn't check when).
>> It returns an IO::Socket object, which you can call peername on:
>> 
>> my ($port,$iaddr) = sockaddr_in($ldap->socket->peername);
>> my $peerhost = gethostbyaddr($iaddr, AF_INET);
>> my $peerstraddr = inet_ntoa($iaddr);
>> 
>> (Code stolen from 'perldoc -f getpeername')
> 
> Oh man, that's ugly.

Yep. You'd probably only need
inet_ntoa((sockaddr_in($ldap->socket->peername))[1]) but that's even harder
to read.

> Sure would be nice to have a *clean* way to get it direct from Net::LDAP
> itself (and not from a Socket class). :-)

IMO some kind of wrappers around peername belong in the Socket class, but
perhaps the author of both modules has some opinions ;-)

Cheers,

Chris

Reply via email to