Using IPv6 Addresses
IPv6 addresses represent the next generation of IP addresses. Like internet (IPv4) addresses before them, these addresses identify communication endpoints on an internet. IPv6 differs from IPv4 in the number of addressable endpoints that it can support, as well as a number of additional features that are outside of the scope of the Essential Networking Module User's Guide.
An IPv6 address is composed of three parts:
• Host, which identifies the computer
• Scope, which identifies a network interface on the host computer
• Port, which identifies where to send information to that host
An IPv6 address is represented in the Networking package as an
RWInet6Addr. As shown in
Figure 11, an
RWInet6Addr object contains two objects, an
RWInet6Host to represent the host, and an
RWInetPort to represent the port.
Constructing a Host
A host is identified by either a symbolic name, like net.roguewave.com, or by an IPv6 hex address, like fe80::2b0:d0ff:fe92:873c. A particular host can have more than one symbolic name. A host address usually has only one IPv6 address, although it is possible for a host to have more than one address.
You can construct a host object by specifying either the IP address or host name as a string, as shown in the following examples.
RWInet6Host host1("net.roguewave.com");
RWInet6Host host2("fe80::2b0:d0ff:fe92:873c");
Once a host object is constructed, you can use the member functions of
RWInet6Host to determine characteristics of the host.
Example 11 prints information about a host.
Example 11 – Printing information about a host.
#include <rw/rstream.h>
#include <rw/network/RWInet6Host.h>
int main()
{
RWWinSockInfo winsock;
RWInet6Host host = RWInet6Host::me(); // 1
cout << host.getName() << endl; // 2
cout << RWInet6Host::addressAsString(host.getAddress()) // 3
<< endl;
return 0;
}
Building IPv6 Addresses
Example 12 shows how to build an IPv6 address object by specifying the port and then the host.
Example 12 – Building IPv6 addresses
RWInet6Addr addr1( 3010, "net.roguewave.com" ); // 1
RWInet6Addr addr2( 3010 ); // 2
RWInet6Addr addr3( "stream:net.roguewave.com:3010" ); // 3
RWInet6Addr addr4( "stream:[fe80::2b0:d0ff:fe92:873c]:3010" ); // 4
RWInet6Addr addr5( "stream:net.roguewave.com%4:3010" ); // 5
NOTE >> IPv6 addresses are not supported on all platforms. To verify that IPv6 addresses are supported by Rogue Wave on your platform, check if the RWNET_HAS_INET6_SOCKETS macro is defined.