in reply to Re^2: IO Socket - Detect inbound IP
in thread IO Socket - Detect inbound IP

You are mistaken. It does indeed work. Don't blame the tool if you don't understand its output.

The address is returned in its packed form. Each character of the string is one of the octets. Pass it to inet_ntoa to convert it to the dotted address form. Aforementioned peerhost does this for you.

Replies are listed 'Best First'.
Re^4: IO Socket - Detect inbound IP
by Anonymous Monk on Jan 25, 2011 at 21:27 UTC
    here it is.
    my ($new_sock, $client_addr) = $sock->accept(); my $peerhost = $sock->peeraddr(); my $addr = inet_ntoa($peerhost); print "$addr\n"; print $client_addr\n"; while(<$new_sock>) { print $_; } close($sock);

      $sock isn't connected to anything. That's why you're getting

      Use of uninitialized value in subroutine entry Bad arg length for Socket::inet_ntoa, length is 0, should be 4

      $! contains the following, but you might not have known that peeraddr sets it on error.

      Transport endpoint is not connected

      You want to know to whom $new_sock is connected.

A reply falls below the community's threshold of quality. You may see it by logging in.