in reply to gethostbyname returns reverse order of ipaddress expected
Make sure that you check for definedness.#!/usr/bin/perl use strict; use warnings; use Socket; my $packed_ip = gethostbyname('localhost.localdomain'); if (defined $packed_ip) { my $ip_address = inet_ntoa($packed_ip); print $ip_address, "\n"; }
Using Sys::Hostname::FQDN, you can do an ascii-version of Anonymous Monk's post like this:
#!/usr/bin/perl BEGIN { $| = 1; $^W = 1; } use strict; use warnings; use Socket; use Sys::Hostname::FQDN qw( asciihostinfo gethostinfo fqdn short ); my($name,$aliases,$addrtype,$length,@addrs) = asciihostinfo(); print qq|host info short name : |, short(), qq| long name ; |, fqdn(), qq| aliases : |, $aliases, qq| address type : |, $addrtype, qq| address length: |, $length, qq| IP address(es): |; foreach(@addrs) { print "\t$_\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: gethostbyname returns reverse order of ipaddress expected
by anubhavd (Initiate) on Jun 17, 2013 at 22:35 UTC | |
by Anonymous Monk on Jun 18, 2013 at 04:13 UTC | |
by Anonymous Monk on Jun 25, 2013 at 22:20 UTC | |
by Anonymous Monk on Jun 26, 2013 at 02:15 UTC | |
by anubhavd (Initiate) on Jun 26, 2013 at 19:11 UTC |