HP OpenVMS Systems Documentation |
HP TCP/IP Services for OpenVMS
|
Previous | Contents | Index |
This appendix describes the changes you must make in your application code to operate in an IPv6 networking environment, including:
Figure E-1 shows a sample sequence of events for an application that uses an AF_INET socket to send IPv4 packets.
Figure E-1 Using AF_INET Socket for IPv4 Communications
Section E.6.1.1 contains sample program code that demonstrates these steps.
You can use the AF_INET6 socket for both IPv6 and IPv4 communications. For IPv4 communications, create an AF_INET6 socket and pass it a sockaddr_in6 structure that contains an IPv4-mapped IPv6 address (for example, ::ffff:1.2.3.4 ). Figure E-2 shows the sequence of events for an application that uses an AF_INET6 socket to send IPv4 packets.
Figure E-2 Using AF_INET6 Socket to Send IPv4 Communications
AF_INET6 sockets can receive messages sent to either IPv4 or IPv6 addresses on the system. An AF_INET6 socket uses the IPv4-mapped IPv6 address format to represent IPv4 addresses. Figure E-3 shows the sequence of events for an application that uses an AF_INET6 socket to receive IPv4 packets.
Figure E-3 Using AF_INET6 Socket to Receive IPv4 Communications
For IPv6 communications, create an AF_INET6 socket and pass it a sockaddr_in6 structure that contains an IPv6 address (for example, 3ffe:1200::a00:2bff:fe2d:02b2 ). Figure E-4 shows the sequence of events for an application that uses an AF_INET6 socket to send IPv6 packets.
Figure E-4 Using AF_INET6 Socket for IPv6 Communications
Section E.6.2.1 contains sample program code that demonstrates these steps.
The following sections describe how to convert an existing AF_INET
application to an AF_INET6 application that is capable of communicating
over both IPv4 and IPv6.
E.2 Name Changes
Most of the changes required are straightforward and mechanical, though some may require a bit of code restructuring. For example, a routine that returns an int data type holding an IPv4 address may need to be modified to take as an extra parameter a pointer to an in6_addr into which it writes the IPv6 address.
Table E-1 summarizes the changes you must make to your application's code.
Search file for | Replace with | Comments |
---|---|---|
AF_INET | AF_INET6 | Replace with IPv6 address family macro. |
PF_INET | PF_INET6 | Replace with IPv6 protocol family macro. |
INADDR_ANY | in6addr_any | Replace with IPv6 global variable. |
The structure names and field names have changed for the following structures:
The following sections discuss these changes.
E.3.1 in_addr Structure
Applications that use the IPv4 in_addr structure must be changed to use the IPv6 in6_addr structure, as follows:
IPv4 Structure | IPv6 Structure |
---|---|
struct in_addr
unsigned int s_addr |
struct in6_addr
uint8_t s6_addr |
Make the following changes to your application, as needed:
Applications that use the generic socket address structure ( sockaddr ) to hold an AF_INET socket address ( sockaddr_in ) must be changed to use the AF_INET6 sockaddr_in6 structure, as follows:
AF_INET Structure | AF_INET6 Structure |
---|---|
struct sockaddr | struct sockaddr_in6 |
Make the following change to your application, as needed:
A sockaddr_in6 structure is larger than a sockaddr structure. For more information, see Section 3.2.14. |
Applications that use the BSD Version 4.4 IPv4 sockaddr_in structure must be changed to use the IPv6 sockaddr_in6 structure, as follows:
IPv4 Structure | IPv6 Structure |
---|---|
struct sockaddr_in
unsigned char sin_len sa_family_t sin_family in_port_t sin_port struct addr sin_addr |
struct sockaddr_in6
uint8_t sin6_len sa_family_t sin6_family int_port_t sin6_port struct in6_addr sin6_addr |
Make the following changes to your application, as needed:
Applications that use the hostent structure must be changed to use the addrinfo structure, as follows:
AF_INET Structure | AF_INET6 Structure |
---|---|
struct hostent | struct addrinfo |
Make the following change to your application, as needed:
See also Section E.4.2 for related changes.
E.4 Function Changes
The names and parameters have changed for the following functions:
The following sections discuss these changes.
E.4.1 gethostbyaddr() Function
Applications that use the IPv4 gethostbyaddr() function must be changed to use the IPv6 getnameinfo() function, as follows:
AF_INET Call | AF_INET6 Call |
---|---|
gethostbyaddr( xxx,4,AF_INET) | err=getnameinfo( &sa, salen, node, nodelen, service, servicelen, flags); |
Make the following change to your application, as needed:
Applications that use the gethostbyname() function must be changed to use the getaddrinfo() function, as follows:
AF_INET Call | AF_INET6 Call |
---|---|
gethostbyname( name) |
err=getaddrinfo(
nodename,
servname,
&hints,
&res);
.
. . freeaddrinfo( &ai); |
Make the following changes to your application, as needed:
Applications that use the inet_aton() function must be changed to use the inet_pton() function, as follows:
AF_INET Call | AF_INET6 Call |
---|---|
inet_aton( &string, &addr) | inet_pton (AF_INET6,&src,&dst); |
Make the following change to your application, as needed:
Applications that use the inet_ntoa() function must be changed to use the inet_ntop() function, as follows:
AF_INET Call | AF_INET6 Call |
---|---|
inet_ntoa( addr) | inet_ntop(AF_INET6,&src,&dst,size); |
Make the following change to your application, as needed:
Applications that use the inet_addr() function must be changed to use the inet_pton() function, as follows:
AF_INET Call | AF_INET6 Call |
---|---|
result=inet_addr( &string) | inet_pton (AF_INET6,&src,&dst); |
Make the following change to your application, as needed:
In addition to the name changes, you should review your code for
specific uses of IP address information and variables.
E.5.1 Comparing IP Addresses
If your application compares IP addresses or tests IP addresses for equality, the in6_addr structure changes (see in Section E.3.1) will change the comparison of int quantities to a comparison of structures. This will break the code and cause compiler errors.
Make one of the following changes to your application, as needed:
AF_INET Code | AF_INET6 Code |
---|---|
(addr1->s_addr == addr2->s_addr) | (memcmp(addr1, addr2, sizeof(struct in6_addr)) == 0) |
AF_INET Code | AF_INET6 Code |
---|---|
(addr1->s_addr == addr2->s_addr) | IN6_ARE_ADDR_EQUAL(addr1, addr2) |
If your application compares an IP address to the wildcard address, the in6_addr structure changes (see Section E.3.1) will change the comparison of int quantities to a comparison of structures. This will break the code and cause compiler errors.
Make either of the following changes to your application, as needed:
AF_INET Code | AF_INET6 Code |
---|---|
(addr->s_addr == INADDR_ANY) | IN6_IS_ADDR_UNSPECIFIED(addr) |
AF_INET Code | AF_INET6 Code |
---|---|
(addr->s_addr == INADDR_ANY) | (memcmp(addr, in6addr_any, sizeof(struct in6_addr)) == 0) |
If your application uses int data types to hold IP addresses, the in6_addr structure changes (see Section E.3.1) will change the assignment. This will break the code and cause compiler errors.
Make the following changes to your application, as needed:
AF_INET Code | AF_INET6 Code |
---|---|
struct in_addr foo;
int bar; . . . bar = foo.s_addr; |
struct in6_addr foo;
struct in6_addr bar; . . . bar = foo; |
If your application uses functions that return IP addresses as int data types, the in6_addr structure changes (see Section E.3.1) will change the destination of the return value from an int to an array of char . This will break the code and cause compiler errors.
Make the following changes to your application, as needed:
AF_INET Code | AF_INET6 Code |
---|---|
struct in_addr *addr;
addr->s_addr = foo( xxx); |
struct in6_addr *
addr;
foo( xxx, addr); |
Previous | Next | Contents | Index |