Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

gethostbyname: What does $aliases look like?

by Skeeve (Parson)
on Sep 14, 2009 at 06:34 UTC ( [id://795065]=perlquestion: print w/replies, xml ) Need Help??

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

I wrote a small script where I use

($name, $aliases, $addrtype, $length, @addrs) = gethostbyname $host;
and since I don't have any host having more than 2 names (i.e. 1 alias) I don't know what $aliases would look like, had the machine 3 or more names.

Are the names in a string? Space seperated? Komma seperated?

Or wil $aliases be a reference to an array?

Can someone please enlighten me?


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re: gethostbyname: What does $aliases look like?
by tomfahle (Priest) on Sep 14, 2009 at 07:32 UTC

    Just add some aliases where it doesn't hurt and it's easy to figure out. (I use a tiny virtual machine for this purpose.)

    #!/usr/bin/perl use strict; use warnings; use Dumpvalue; # Core Module, dumps like the debugger my $dumper = new Dumpvalue; my $host = shift; my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($host) or + die "Can't resolve $host $!\n"; print "$aliases\n"; $dumper->dumpValue(\$aliases);

    My /etc/hosts file

    127.0.0.1 localhost tf-laptop my-laptop

    Running the above code with the argument localhost yields:

    $ perl gethostbyname.pl localhost tf-laptop my-laptop -> 'tf-laptop my-laptop'

    $aliases is a string holding the aliases seperated by whitespace.

    Hth
    Thomas

Re: gethostbyname: What does $aliases look like?
by ikegami (Patriarch) on Sep 14, 2009 at 06:58 UTC

    An array of strings, I would suppose, like the system call.

    Then again, Perl doesn't return an array when there's only one alias. Maybe it returns one at most?

    $ perl -MData::Dumper -e'print Dumper $_ for (gethostbyname $ARGV[0])[ +0,1]' www.google.com $VAR1 = 'www.l.google.com'; $VAR1 = 'www.google.com';

    Update: They are space-joined. From pp_sys.c:

    PUSHs(space_join_names_mortal(hent->h_aliases));
      Thanks, ikegami

      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://795065]
Approved by ELISHEVA
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-25 11:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found