muaddib2 has asked for the wisdom of the Perl Monks concerning the following question:

Hello all I am trying to write simple perl script to to ip resolution to Domain names this is the script
#/usr/bin/perl use warnings; use Socket; print "Ip address "; my $ipaddr = <STDIN>;#/usr/bin/perl use warnings; use Socket; print "Ip address "; my $ipaddr = <STDIN>; $peer_host = gethostbyaddr($ipaddr, AF_INET); $peer_addr = inet_ntoa($peer_host); print $peer_addr;
The error that I am getting is
Use of uninitialized value in subroutine entry at huh2 line 7, <STDIN> + line 1. Bad arg length for Socket::inet_ntoa, length is 0, should be 4 at huh2 + line 7, <STDIN> line 1. Use of uninitialized value in subroutine entry at huh2 line 7, <STDIN> + line 1. Bad arg length for Socket::inet_ntoa, length is 0, should be 4 at huh2 + line 7, <STDIN> line 1. Use of uninitialized value in subroutine entry at huh2 line 7, <STDIN> + line 1. Bad arg length for Socket::inet_ntoa, length is 0, should be 4 at huh2 + line 7, <STDIN> line 1. $peer_host = gethostbyaddr($ipaddr, AF_INET); $peer_addr = inet_ntoa($peer_host); print $peer_addr;
(edited 2001-04-24 by tilly to add code tags)

Replies are listed 'Best First'.
(Ovid)Re: DNS resolver
by Ovid (Cardinal) on Apr 25, 2001 at 02:51 UTC
    Are you just trying to get the host/domain name? Since you already have the IP address (from STDIN), this will print the host/domain name:
    #/usr/bin/perl use warnings; use strict; use Socket; print "Ip address "; my $ipaddr = <STDIN>; my $peer_host = gethostbyaddr(inet_aton($ipaddr), AF_INET); print $peer_host;
    Obviously, you'll want to validate the IP address.

    The errors were caused by inet_ntoa expecting a packed IP address for an argument.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.