From: Gabor Szabo Date: Wed, 18 Jul 2007 08:47:40 +0000 (+0300) Subject: gethostbyname() example X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d760c846dd64642dd0b62a13fbbc003a481c1224;p=p5sagit%2Fp5-mst-13.2.git gethostbyname() example From: "Gabor Szabo" Message-ID: p4raw-id: //depot/perl@31623 --- 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,