Programming Perl

Programming PerlSearch this book
Previous: 3.2.47 gethostbyaddrChapter 3
Next: 3.2.49 gethostent

3.2.48 gethostbyname

gethostbyname NAME

This function does the same thing as gethostbyname(3): it translates a network hostname to its corresponding addresses (and other names). The return value in list context is:

($name, $aliases, $addrtype, $length, @addrs)

where @addrs is a list of raw addresses. In the Internet domain, each address is four bytes long, and can be unpacked by saying something like:

($a, $b, $c, $d) = unpack('C4', $addrs[0]);

In scalar context, gethostbyname returns only the host address. See the section on "Sockets" in Chapter 6 for another approach.

Previous: 3.2.47 gethostbyaddrProgramming PerlNext: 3.2.49 gethostent
3.2.47 gethostbyaddrBook Index3.2.49 gethostent