11.1 Introduction
All the examples so far in this text have used
numeric addresses for the hosts (e.g., 206.6.226.33) and numeric
port numbers to identify the servers (e.g., port 13 for the
standard daytime server and port 9877 for our echo server). We
should, however, use names instead of numbers for numerous reasons:
Names are easier to remember; the numeric address can change but
the name can remain the same; and with the move to IPv6, numeric
addresses become much longer, making it much more error-prone to
enter an address by hand. This chapter describes the functions that
convert between names and numeric values: gethostbyname
and gethostbyaddr to convert between hostnames and IPv4
addresses, and getservbyname and getservbyport to
convert between service names and port numbers. It also describes
two protocol-independent functions: getaddrinfo and
getnameinfo, which convert between hostnames and IP
addresses and between service
names and port numbers.
|