Programming Perl

Programming PerlSearch this book
Previous: 3.2.46 getgrnamChapter 3
Next: 3.2.48 gethostbyname

3.2.47 gethostbyaddr

gethostbyaddr ADDR, ADDRTYPE

This function does the same thing as gethostbyaddr(3): it translates a packed binary network address to its corresponding names (and alternate addresses). The return value in list context is:

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

where @addrs is a list of packed binary 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, gethostbyaddr returns only the host name. See the section on "Sockets" in Chapter 6 for another approach.

Previous: 3.2.46 getgrnamProgramming PerlNext: 3.2.48 gethostbyname
3.2.46 getgrnamBook Index3.2.48 gethostbyname