in reply to Re: gethostbyname not working
in thread gethostbyname not working

You can simply use
my $addr = gethostbyname($hostname);
instead of
my $addr = (gethostbyname($hostname))[4];
When used in scalar context, gethostbyname returns the address, which would have prevented your earlier bug.

Replies are listed 'Best First'.
Re: Re: Re: gethostbyname not working
by nick (Sexton) on Mar 27, 2001 at 03:54 UTC
    This is what I did at first, that was the problem (if you look at my original post). what's the difference?
      You weren't unpacking the address.
      You still need to unpack the results.

      A complete example would be:

      my $hostname = 'yahoo.com'; my $addr = gethostbyname($hostname); my ($a,$b,$c,$d) = unpack('C4',$addr); print "$a.$b.$c.$d\n";

      Signature void where prohibited by law.
Re: Re: Re: gethostbyname not working
by myocom (Deacon) on Mar 27, 2001 at 03:10 UTC

    Ah, so it does! Thanks for the tip!