TCP/IP Programming Manual
1. Change the function name from gethostbyname to getaddrinfo.
2. Provide:
• a character string for the returned node name
• a character string for the service name
• a pointer to a hints structure that contains processing options
• a pointer to an addrinfo structure or structures for the returned address information.
(See getaddrinfo (page 107) for a description of hints fields and values.)
3. Add a call to the freeaddrinfo routine to free the addrinfo structure or structures when
your application is finished using them.
Alternatively, you can use getipnodebyname. The difference between getaddrinfo and
getipnodebyname is that getaddrinfo returns both the node address and the port number
and getipnodebyaddr returns just the node address. getipnodebyname also requires another
call, freehostent, to free the hostent structure when the call is complete.
See getaddrinfo and getipnodebyname for more information about these calls.
If your application needs to determine whether an address is an IPv4 address or an IPv6 address,
and cannot determine this information from the address family, use the IN6_IS_ADDR_V4MAPPED
macro. See Address-Testing Macros (page 52) for a list of IPv6 address testing macros.
inet_ntoa Function Call
Applications that use the inet_ntoa function call must be changed to use the inet_ntop function
call, as shown in the following examples:
AF_INET6 CallAF_INET Call
inet_ntop(family, &addr, &buff, len)inet_ntoa(addr)
In your applications, change the function name from inet_ntoa to inet_ntop and provide the
family name (AF_INET or AF_INET6), the address of the input buffer containing the binary address,
a non-NULL address, and the size of the address to convert. See inet_ntop (page 138) for a
description of the library routine.
inet_addr Function Call
Applications that use the inet_addr function call must be changed to use the inet_pton function
call, as shown in the following examples:
AF_INET6 CallAF_INET Call
result=inet_pton(family, &addr, &buff)result=inet_addr(&string);
Make the following changes in your application, as needed:
Change the function name from inet_addr to inet_pton and provide the family name (AF_INET
or AF_INET6), the address of the address string containing to be converted, and the address of
the buffer into which the function stores the numeric address upon return. See inet_pton (page 139)
for a description of hints fields and values.
Making Other Application Changes
In addition to the name changes, you should review your code for specific uses of IP address
information and variables.
Porting Applications to Use AF_INET6 Sockets 57