INET(4) BSD Programmer's Manual INET(4)NAMEinet - Internet protocol family
SYNOPSIS
#include <sys/types.h>
#include <netinet/in.h>
DESCRIPTION
The Internet protocol family is a collection of protocols layered atop
the Internet Protocol (IP) transport layer, and utilizing the Internet
address format. The Internet family provides protocol support for the
SOCK_STREAM, SOCK_DGRAM, and SOCK_RAW socket types; the SOCK_RAW inter-
face provides access to the IP protocol.
ADDRESSING
Internet addresses are four byte quantities, stored in network standard
format (on some machines, such as the VAX and i386 family of processors
these are word and byte reversed).
Sockets bound to the Internet protocol family utilize the following ad-
dressing structure,
struct sockaddr_in {
u_char sin_len;
u_char sin_family;
u_short sin_port;
struct in_addr sin_addr;
char sin_zero[8];
};
Sockets may be created with the local address INADDR_ANY to effect
``wildcard'' matching on incoming messages. The address in a connect(2)
or sendto(2) call may be given as INADDR_ANY to mean ``this host''. The
distinguished address INADDR_BROADCAST is allowed as a shorthand for the
broadcast address on the primary network if the first network configured
supports broadcast.
The 32-bit Internet address contains both network and host parts. The
distinction between the network and host parts is defined by the
``network mask'' (or mask length; the number of contiguous one bits in
the network mask). The network mask is specified when adding a route to
the forwarding table and when configuring the addressing of an interface.
At the command level (route(8)and ifconfig 8) a default network mask is
provided when not explicitly provided. This default is currently the
``natural'' netmask specified by the class of the address. Class A net-
works range from 1.0.0.0 to 127.0.0.0 and have a network mask of
255.0.0.0 (a length of 8 bits). Class B networks range from 128.0.0.0 to
191.255.255.0 and have a network mask of 255.255.0.0 (a length of 16
bits). Class C networks range from 192.0.0 to 223.255.255 and have a
network mask of 255.255.255.0.
Networks with masks that are more specific (have a longer mask) than the
``natural'' network mask are called ``subnets''. Typically an organiza-
tion will be assigned a range of addresses denoted by a network number
and mask. These will then be ``subnetted'' into smaller pieces (with
longer network masks) for different logical networks within the organiza-
tion.
Networks with masks that are more general (have a short network mask) are
called ``supernets''. Due to the limited availability of Internet address
space, organizations are frequently assigned a ``supernet'' consisting of
a block of Class C networks instead of a Class B network.
PROTOCOLS
The Internet protocol family is comprised of the IP transport protocol,
Internet Control Message Protocol (ICMP), Transmission Control Protocol
(TCP), and User Datagram Protocol (UDP). TCP is used to support the
SOCK_STREAM abstraction while UDP is used to support the SOCK_DGRAM ab-
straction. A raw interface to IP is available by creating an Internet
socket of type SOCK_RAW. The ICMP message protocol is accessible from a
raw socket.
INTERFACES
A program may discover interface addresses by use of the sysctl(3) or
getifaddrs(3) functions. Interfaces are configured by using the
SIOCAIFADDR and SIOCDIFADDR ioctl(2) calls with the in_aliasreq and ifreq
structures respectively.
SEE ALSOioctl(2), socket(2), byteorder(3), getifaddrs(3), sysctl(3),
netintro(4), route(4), tcp(4), udp(4), ip(4), icmp(4), ifconfig(8),
netstat(8), route(8).
"An Introductory 4.3 BSD Interprocess Communication Tutorial", PS1, 7.
"An Advanced 4.3 BSD Interprocess Communication Tutorial", PS1, 8.
CAVEAT
The Internet protocol support is subject to change as the Internet
protocols develop. Users should not depend on details of the current
implementation, but rather the services exported.
HISTORY
The inet protocol interface appeared in 4.2BSD.
4.2 Berkeley Distribution June 5, 1993 2