From d760c846dd64642dd0b62a13fbbc003a481c1224 Mon Sep 17 00:00:00 2001 From: Gabor Szabo Date: Wed, 18 Jul 2007 11:47:40 +0300 Subject: [PATCH] gethostbyname() example From: "Gabor Szabo" Message-ID: p4raw-id: //depot/perl@31623 --- pod/perlfunc.pod | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index c96596f..1afa901 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 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, C, C, -- 1.8.3.1