diff options
author | Gabor Szabo <szabgab@gmail.com> | 2007-07-18 11:47:40 +0300 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2007-07-18 08:17:47 +0000 |
commit | d760c846dd64642dd0b62a13fbbc003a481c1224 (patch) | |
tree | 6488695a1a1a784744bc3f9161f8c92eb6259915 /pod | |
parent | cf3e690a4b2b2f28a63d4d27ef9dd5cd98719cd6 (diff) | |
download | perl-d760c846dd64642dd0b62a13fbbc003a481c1224.tar.gz |
gethostbyname() example
From: "Gabor Szabo" <szabgab@gmail.com>
Message-ID: <d8a74af10707172247v2f761bebs30d054eddbe5861@mail.gmail.com>
p4raw-id: //depot/perl@31623
Diffstat (limited to 'pod')
-rw-r--r-- | pod/perlfunc.pod | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index c96596fcd6..1afa901c76 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -2230,6 +2230,18 @@ The Socket library makes this slightly easier: # or going the other way $straddr = inet_ntoa($iaddr); +In the opposite way, to resolve a hostname to the IP address +you can write this: + + use Socket; + $packed_ip = gethostbyname("www.perl.org"); + if (defined $packed_ip) { + $ip_address = inet_ntoa($packed_ip); + } + +Make sure <gethostbyname()> is called in SCALAR context and that +its return value is checked for definedness. + If you get tired of remembering which element of the return list contains which return value, by-name interfaces are provided in standard modules: C<File::stat>, C<Net::hostent>, C<Net::netent>, |