This section describes the address formats used in the internet domain.
internet addresses (IP) are 32-bit values that represent a network interface. Every internet address within an administered internet (AF_INET) communication domain must be unique. A host can have as many internet addresses as it has network interfaces. For more information about internet address formats, see Internetworking with TCP/IP Volume I: Principles, Protocols, and Architectures , and Volume II: Implementation and Internals , Douglas E. Comer, Prentice Hall, 1991.
Each internet host is assigned at least one unique internet address. This address is used by IP and other higher-level protocols. When a host is a gateway, it has more than one IP address. Gateway hosts connect two or more physical networks and have one IP address per connected physical network.
Addresses within an internet consist of a network number and a local address. All physical host IP addresses share the same network number and are logically part of the same network even if that network is connected with various physical media.
Hosts on disjoint physical networks might also have the same network number, but are not part of the same internet network. Hosts that are part of the same internet network can exchange packets directly without going through intermediate routers. An internet network can be subdivided logically using a subnet mask. All host interfaces to the same physical network are given the same subnetwork number. An internet domain can provide standards for assigning addresses to networks, broadcasts, and subnetworks.
Dotted-Decimal Notation: A commonly used notation for internet host addresses is the dotted-decimal format, which divides the 32-bit address into four 8-bit fields. The value of each field is specified as a decimal number, and the fields are separated by periods (for example, 10.2.0.52).
Address examples in this document use dotted-decimal notation in the following forms:
where:
nnn
Note: Additional details about internet network address format class A, B, C, and D addresses, subnetwork address format, and broadcast address formats can be found in the TCP/IP Guide
Addressing within an Internet Domain: A socket address in an internet communication domain is composed of five fields in the following sockaddr_in structure: length, address family, port, internet address, and a .* reserved field. The sockaddr_in structure should be cleared before use. The structure is located in the <NETINET\IN.H> header file:
struct in_addr { u_long s_addr; };
struct sockaddr_in { u_char sin_len; /* sizeof (struct sockaddr_in) = 16 */ u_char sin_family; /* AFINET */ u_short sin_port; /* port id */ struct in_addr sin_addr; /* address */ char sin_zero[8]; /* not used */ };
The sin_len field is set to 16 as the size of the sockaddr_in structure.
The sin_family field is set to AF_INET.
The sin_port field is set to the port number in network-byte order. If you are specifying your workstation address in sin_addr and you set sin_port to 0 using the bind() call, the system assigns an available port. If you specify a different workstation address in sin_addr, you must specify the port. For more information on ports, see Ports.
The sin_addr field is set to the internet address represented in network-byte order. When specified as a parameter to bind(), sin_addr is usually set to the constant INADDR_ANY, as defined in <NETINET\IN.H>. This binds the socket to any and all local internet addresses. By using INADDR_ANY, an application can bind a socket without specifying the local internet address. The constant INADDR_ANY also allows an application running on a host with multiple interfaces (called a multihomed host) to receive UDP datagrams and TCP connection requests arriving at any interface on a single socket. (The application is not required to have one socket per interface, with each interface bound to a specific internet address).
To specify your workstation address, you can leave sin_addr unspecified. If you are specifying a different workstation address, you must specify a valid internet address for that workstation.
The sin_zero field is not used, and it should be set to 0 by the application before passing the address structure to any sockets call.