HP OpenVMS Systems Documentation |
HP TCP/IP Services for OpenVMS
|
Previous | Contents | Index |
Returns the number of bytes required for an IPv6 routing header.
#include <ip6.h>size_t inet6_rth_space ( int type, int segments );
type
Specifies the type of routing header. The valid value is IPV6_RTHDR_TYPE_0 for IPv6 routing header type 0.
segments
Specifies the number of segments or addresses that are to be included in the routing header. The valid value is from 0 to 127, inclusive.
The inet6_rth_space() function determines the amount of space, in bytes, required for a routing header. Although the function returns the amount of space required, it does not allocate buffer space. This enables the application to allocate a larger buffer.
If the application uses ancillary data, it must pass the returned length to CMSG_LEN() to determine the amount of memory required for the ancillary data object, including the cmsghdr structure.
Note
If an application wants to send other ancillary data objects, it must specify them to sendmsg() as a single msg_control buffer.
x Upon successful completion, the inet6_rth_space() function returns the length, in bytes, of the routing header and the specified number of segments. 0 (zero) Failure, if the type is not supported or the number of segments is invalid for the type of routing header
Converts a numeric address to a text string suitable for presentation.
#include <inet.h>const char *inet_ntop ( int af, const void *src, char *dst, size_t size );
af
Specifies the address family. Valid values are AF_INET for an IPv4 address and AF_INET6 for an IPv6 address.
src
Points to a buffer that contains the numeric Internet address.
dst
Points to a buffer that is to contain the text string.
size
Specifies the size of the buffer pointed to by the dst parameter. For IPv4 addresses, the minimum buffer size is 16 octets; for IPv6 addresses, the minimum buffer size is 46 octets. The <in.h> header file defines the INET_ADDRSTRLEN and INET6_ADDRSTRLEN constants, respectively, for these values.
The inet_ntop() function converts a numeric Internet address value to a text string.
Pointer to the buffer containing the text string. Success Pointer to the buffer containing NULL. Failure
Converts an address in its standard text presentation form its numeric binary form, in network byte order.
#include <inet.h>int inet_pton ( int af, const char *src, void *dst );
af
Specifies the address family. Valid values are AF_INET for an IPv4 address and AF_INET6 for an IPv6 address.
src
Points to the address text string to be converted.
dst
Points to a buffer that is to contain the numeric address.
The inet_pton() function converts a text string to a numeric value in Internet network byte order.
- If the af parameter is AF_INET, the function accepts a string in the standard IPv4 dotted-decimal format:
ddd.ddd.ddd.ddd
In this format, ddd is a one- to three-digit decimal number between 0 and 255.- If the af parameter is AF_INET6, the function accepts a string in the following format:
x:x:x:x:x:x:x:x
In this format, x is the hexadecimal value of a 16-bit piece of the address.
IPv6 addresses can contain long strings of zero (0) bits. To make it easier to write these addresses, you can use double-colon characters (::) one time in an address to represent 1 or more 16-bit groups of zeros.- For mixed IPv4 and IPv6 environments, the following format is also accepted:
x:x:x:x:x:x:ddd.ddd.ddd.ddd
In this format, x is the hexadecimal value of a 16-bit piece of the address, and ddd is a one- to three-digit decimal value between 0 and 255 that represents the IPv4 address. See RFC 2373 for more information about IPv6 addressing formats.The calling application is responsible for ensuring that the buffer referred to by the dst parameter is large enough to hold the numeric address. AF_INET addresses require 4 bytes and AF_INET6 addresses require 16 bytes.
1 Success 0 (zero) If the input string is neither a valid IPv4 dotted-decimal string nor a valid IPv6 address string, the function returns a 0. -1 Failure. errno is set to the following value.
EAFNOSUPPORT The address family specified in the af parameter is unknown.
This chapter describes the changes you must make in your application code to operate in an IPv6 networking environment.
You can also use this information as guidelines for creating new IPv6-ready applications.
See RFC 3493, Basic Socket Interface Extensions for IPv6, for
complete information on the changes to the BSD socket applications
programming interface (API). See RFC 3542, Advanced Sockets API for
IPv6 for complete information on how to use raw sockets and header
information in IPv6 applications.
8.1 Using AF_INET6 Sockets
At present, applications use AF_INET sockets for IPv4 communications. Figure 8-1 shows a sample sequence of events for an application that uses an AF_INET socket to send IPv4 packets.
Figure 8-1 Using AF_INET Socket for IPv4 Communications
Section 8.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 8-2 shows the sequence of events for an application that uses an AF_INET6 socket to send IPv4 packets.
Figure 8-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 8-3 shows the sequence of events for an application that uses an AF_INET6 socket to receive IPv4 packets.
Figure 8-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 8-4 shows the sequence of events for an application that uses an AF_INET6 socket to send IPv6 packets.
Figure 8-4 Using AF_INET6 Socket for IPv6 Communications
Section 8.6.2.1 contains sample program code that demonstrates these steps.
The following sections show how to convert an existing AF_INET
application to an AF_INET6 application that is capable of communicating
over both IPv4 and IPv6.
8.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 8-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.
8.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. |
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 8.4.2 for related changes.
8.4 Function Changes
The names and parameters have changed for the following functions:
The following sections discuss these changes.
8.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 gethostbynam()e function must be changed to use the getaddrinfo() function, as folllows:
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_ntoa() function must be changed to use the getnameinfo() function, as follows:
AF_INET Call | AF_INET6 Call |
---|---|
inet_ntoa( addr) | err=getnameinfo( &sa, salen, node, nodelen, service, servicelen, NI_NUMERICHOST); |
Make the following change to your application, as needed:
Previous | Next | Contents | Index |