in reply to Re^2: Getting client ip address from socket connect
in thread Getting client ip address from socket connect

sorry
using use IO::Socket::INET;

my $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $serverport, Listen => SOMAXCONN, Reuse => 1); die "can't setup server" unless $server; my $remotehost; &writelog("$date: INFO: Server $0 started accepting clients connection +s"); while ($client = $server->accept()) { $client->autoflush(1); $remotehost = $client->peeraddr; } But i get this in the log 01/11/2005/ 14:42: INFO: New client connection from Μφ

Replies are listed 'Best First'.
Re^4: Getting client ip address from socket connect
by tirwhan (Abbot) on Nov 01, 2005 at 15:11 UTC

    Yes, that's because peeraddr() returns the raw in_addr struct. Either convert it to a string with

    $remotehost=inet_ntoa($client->peeraddr);

    or use

    $remotehost=$client->peerhost;
    like I suggested in my node.

    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
Re^4: Getting client ip address from socket connect
by Spidy (Chaplain) on Nov 01, 2005 at 17:11 UTC
    One thing that I would change is the die unless that you have, you could probably rewrite that to this:
    my $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $serverport, Listen => SOMAXCONN, Reuse => 1) or die("Can't setup server: $!");

    I'm not 100% sure that that will work though, I haven't really gone near IO::Socket.
    Spidy