gethostbyaddr 
Author Message
 gethostbyaddr

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.

So far, it looks like this :


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....

Any hints would be appreciated - thanks in advance.

------------------------------------------------------
SYS1501-216: Could not locate coffee - Operator halted
------------------------------------------------------
Z. Horvat
Rechenzentrum Universitaet Konstanz
7750 Konstanz
+49(0)7531-88-2405


-------------------------------------------------------



Sun, 05 Mar 1995 19:06:43 GMT  
 gethostbyaddr
Just wanted to add that i'm using Perl on AIX 3.1

------------------------------------------------------
SYS1501-216: Could not locate coffee - Operator halted
------------------------------------------------------
Z. Horvat
Rechenzentrum Universitaet Konstanz
7750 Konstanz
+49(0)7531-88-2405


-------------------------------------------------------



Sun, 05 Mar 1995 19:12:30 GMT  
 gethostbyaddr

: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.



Sun, 05 Mar 1995 23:01:09 GMT  
 gethostbyaddr

Looking for a gethostbyaddr..

This one's been posted by Tom Christiansen, I think..
--------------------------------------------

#!/usr/bin/perl

    split(/\./);



Quote:
}

--------------------------------------------

Marty.
---------------------=============***O***=============-------------------------
Martin J. Gleeson  | Computer Science, Melbourne Uni, Oz |    ...  __o    Outta

"We gladly feast on those who would subdue us." - Addams |  ....(_)/(_)..  way!
 "I can't give you brains, but I can give you a diploma." - The Wizard of Oz
---------------------=============***O***=============-------------------------



Mon, 06 Mar 1995 00:14:32 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. HELP! with gethostbyaddr

2. gethostbyaddr not working in perl5.00401?

3. gethostbyaddr

4. gethostbyaddr usage

5. gethostbyaddr does not work in IRIX 5.2

6. Problems with GETHOSTBYADDR()

7. gethostbyaddr()

8. gethostbyaddr: Format of first parameter?

9. IP address for gethostbyaddr()

10. Unexpected results from gethostbyaddr()

11. gethostbyaddr()

12. using gethostbyaddr in PERL

 

 
Powered by phpBB® Forum Software