:I'm really stuck on this :
:
:I just wanted to write a little function which should return the name of the host on a given IP-Adress.
:print "$name $aliases\n";
:
:doesn't matter what adress i give to pack, i always have
: loopback localhost
:for $name and $aliases.
:
:Maybe this is a dumb question, but i'm using perl for one day now....
Pretty good for just a day, I'd say.
The first problem is that pack() returns a scalar. It's unpack() who
returns a list.
Now, the gethostbyaddr routine and its allies are just hooks into the C
routines, so you'll have to pack up your 4 byte IP address to pass to
gethostbyaddr.
So, try something more like this:
$AF_INET = 2; # may this never change
= gethostbyaddr($net, $AF_UNIX);
Here's a little program that takes a list of IP addrs and
gives you their hostnames. The splice() magic is to handle
things that like 127.1 or 10.2 -- we zero-fill from the middle.
This was one of the tooloff problems, and is admittedly more
complex than mailing ches, which was Doug McIlroy's solution. :-)
#!/usr/bin/perl
$AF_UNIX= 2; $IP_FMT = 'C4';
split(/\./);
}
--tom
--
Steinbach's Guideline for Systems Programming
Never test for an error condition you don't know how to handle.