Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Feb 1999 09:21:55 -0500
From:      Robert Beer <r-beer@onu.edu>
To:        "Randy A. Katz" <randyk@ccsales.com>, questions@FreeBSD.ORG
Subject:   Re: A Perl Question
Message-ID:  <l0310280eb2e0aecb0390@[140.228.15.35]>
In-Reply-To: <3.0.5.32.19990205001838.03baa980@ccsales.com>

next in thread | previous in thread | raw e-mail | index | archive | help
At 3:18 AM -0500 2/5/1999, Randy A. Katz wrote:
>I'm trying to use gethostbyaddr and it is returning blank:
>
>$ipaddress = "216.0.22.30";
>($name, $aliases, $addrtype, $length, @addrs) =
>gethostbyaddr($ipaddress,AF_INET);  
>print "Name: $name\n";
>print "Aliases: $aliases\n";
>print "Type: $addrtype\n";
>print "Length: $length\n";
>foreach $p (@addrs) {
>  print "A:$p\n";
>}
>exit;
>
>I grepped for AF_INET in /usr/include and there is nothing there, I did a
>man on gethostbyaddr and AF_INET is the only parameter listed for type???

Here is an example I had:

#!/usr/local/bin/perl
for (@ARGV) {
    split(/\./);
    splice(@_, $#_, 0, (0) x (4-@_));  # inet_addr conversion
    @hostent = gethostbyaddr(pack(C4, @_), 2);
    printf "[%s] is %s\n", join('.', @_), $hostent[0] || "<UNKNOWN>";
}

It looks like the IP address format is your problem.

---
Bob Beer <r-beer@onu.edu>
Ohio Northern University, Academic Computer Services, Ada, OH  45810



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?l0310280eb2e0aecb0390>