[Perl] gethostbyaddr function

Discussion in 'Web Design & Coding' started by Geffy, Feb 13, 2005.

  1. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    I cant seem to figure out the proper usage of the Perl gethostbyaddr function, from what I can tell I have to use Socket, but then I am not sure exactly what the ADDRTYPE parameter is supposed to be

    10.10.10.10 is an IP address which does have a reverse dns address on my local network

    Code:
    #!/usr/bin/perl -w
    use Socket;
    my $ip = "10.10.10.10";
    my $addr = gethostbyaddr($ip, AF_INET);
    print $addr;
    if I do that I get an error, uninitialised value line 5 which is the print line

    if I do either of the following I get nothing being returned
    Code:
    #!/usr/bin/perl -w
    use Socket;
    my $ip = "10.10.10.10";
    my @addr = gethostbyaddr($ip, AF_INET);
    
    foreach (@addr) {
        print;
    }
    or
    Code:
    #!/usr/bin/perl -w
    use Socket;
    my $ip = "10.10.10.10";
    my @addr = gethostbyaddr($ip, AF_INET);
    print @addr;
    I cant seem to get any of them to work, the choice of AF_INET was from search results turned up by Google

    Any help much appreciated
     
  2. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
  3. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    thanks