Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

13.5 Internet Addresses

Internet addresses are the most popular socket address family. They are used to identify communication endpoints on an Internet: a network of computers that communicate using the TCP/IP suite of protocols. The "capital-I" Internet is the best known Internet, linking thousands of computers around the world, but the Internet family of addresses is used for thousands of smaller networks, as well.

There are two parts to an Internet address: a host and a port. The TCP/IP protocol uses the host to identify which machine information is intended for, and the port to determine exactly where to send information on that machine. An Internet address is represented in the net library as an RWInetAddr. As shown in the following picture, an RWInetAddr object contains two objects: an RWInetHost to represent the host, and an RWInetPort to represent the port.

Figure 12 -- An RWInetAddr object

13.5.1 Internet Hosts

A host can be identified either by a symbolic name, like net.roguewave.com, or by an Internet Protocol (IP) address, like 198.68.9.6. A particular host can have more than one symbolic name. A host address usually has only one IP address, although it is possible for a host to have more than one address. (Such a host is said to be multihomed.)

A host object is most often constructed by specifying either the IP address or host name as a string. For example, here are two ways to build a host object.

Once a host object is constructed, you can use the member functions of RWInetHost (see the reference manual for a complete list) to determine characteristics of the host. For example, here's a program that prints some information about your host. We'll describe it line by line.

//1The static member function RWInetHost::me() returns a host object representing the host on which the program is running.
//2Print out the primary symbolic name of the host.
//3The four-byte IP address of the host is returned by RWInetHost::address(). Usually, this address is printed a byte at a time, using dotted decimal notation. The static function RWInetHost::addressAsString converts from a long integer to a string in dotted decimal format.

13.5.2 Building Internet Addresses

You construct an Internet address object by specifying the port and then the host. Here are some examples.

//1Here we've provided both a port and a host. Automatic type conversion is used to convert the integer 3010 to an RWInetPort, and to convert the string to an RWInetHost.
//2If the host name is omitted, then the special host ANY is used. This address connects to any available IP address on the current machine.
//3The address can also be provided as a string. The format is the socket type (stream or dgram), followed by the host identifier, followed by a port identifier. The fields are separated by colons. The socket type and host can be omitted, so that both net.roguewave.com:3010 and 3010 are allowed; the default socket type is stream. If only the port number is used, the host defaults to ANY.

Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.