[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Communications Programming Concepts


Socket Communication Domains

Sockets that share common communication properties, such as naming conventions and protocol address formats, are grouped into communication domains. A communication domain is sometimes referred to as name or address space.

The communication domain includes the following:

Communication domains also consist of two categories, socket types and descriptors. Socket types include stream, datagram, sequenced packet, raw, and connection-oriented datagram.

Address Formats

An address format indicates what set of rules was used in creating network addresses of a particular format. For example, in the Internet communication domain, a host address is a 32-bit value that is encoded using one of four rules based on the type of network on which the host resides.

Each communication domain has different rules for valid socket names and interpretation of names. After a socket is created, it can be given a name according to the rules of the communication domain in which it was created. For example, in the UNIX communication domain, sockets are named with operating system path names. A socket can be named /dev/foo. Sockets normally exchange data only with sockets in the same communication domain.

Address Families

The socket subroutine takes an address family as a parameter. Specifying an address family indicates to the system how to interpret supplied addresses. The /usr/include/sys/socket.h and /usr/include/sys/socketvar.h files define the address families.

A socket subroutine that takes an address family (AF) as a parameter can use AF_UNIX (UNIX), AF_INET (Internet), AF_NS (Xerox Network Systems), or AF_NDD (Network Device Drivers of the operating sytem) protocol. These address families are part of the following communication domains:

UNIX Provides socket communication between processes running on the same operating system when an address family of AF_UNIX is specified. A socket name in the UNIX domain is a string of ASCII characters whose maximum length depends on the machine in use.
Internet Provides socket communication between a local process and a process running on a remote host when an address family of AF_INET is specified. The Internet domain requires that Transmission Control Protocol/Internet Protocol (TCP/IP) be installed on your system. A socket name in the Internet domain is an Internet address, made up of a 32-bit IP address and a 16-bit port address.
XNS Provides connection-oriented, reliable, full-duplex service to an application. A socket name in the XNS domain is made up of a four-byte network number, a six-byte host number, and a two-byte port number.
NDD Provides socket communication between a local process and a process running on a remote host when an address family of AF_NDD is specified. The NDD domain enables applications to run directly on top of physical networks. This is in contrast to the Internet domain, in which applications run on top of transport protocols such as TCP, or User Datagram Protocol (UDP). A socket name in the NDD domain consists of operating system NDD name and a second part that is protocol dependent.

Communication domains are described by a domain data structure that is loadable. Communication protocols within a domain are described by a structure that is defined within the system for each protocol implementation configured. When a request is made to create a socket, the system uses the name of the communication domain to search linearly the list of configured domains. If the domain is found, the domain's table of supported protocols is consulted for a protocol appropriate for the type of socket being created or for a specific protocol request. (A wildcard entry may exist for a raw domain.) Should multiple protocol entries satisfy the request, the first is selected.

UNIX Domain Properties

Characteristics of the UNIX domain are:

Types of sockets In the UNIX domain, the SOCK_STREAM socket type provides pipe-like facilities, while the SOCK_DGRAM and SOCK_SEQPACKET socket types usually provide reliable message-style communications.
Naming Socket names are strings and appear in the file system name space through portals.

Passing File Descriptors

In the Unix system it is possible to pass an open file between processes in a couple of ways:

  1. From a parent to a child by opening it in the parent and then either fork or exec another process. This has obvious shortcomings.
  2. Between any processes using a Unix domain socket, as described below. This is a more general technique.

Passing a file descriptor from one process to another means taking an open file in the sending process and generating another pointer to the file table entry in the receiving process. To pass a file descriptor from any arbitrary process to another, it is necessary for the processes to be connected with a Unix domain socket (a socket whose family type is AF_UNIX). Thereafter, one can pass a descriptor from the sending process by using the sendmsg() system call to the receiving process, which must perform the recvmsg() system call. These two system calls are the only ones supporting the concept of "access rights" which is how descriptors are passed.

Basically "access rights" imply that the owning process has acquired the rights to the corresponding system resource by opening it. This right is then passed by this process (the sending process) to a receiving process using the aforesaid system calls. Typically, file descriptors are passed through the access rights mechanism.

The msghdr structure in sys/socket.h contains the following field:

caddr_t msg_accrights access rights sent/received

The file descriptor is passed through this field of the message header, which is used as a parameter in the corresponding sendmsg() system call.

Internet Domain Properties

Characteristics of the Internet domain are:

Socket types and protocols The SOCK_STREAM socket type is supported by the Internet TCP protocol; the SOCK_DGRAM socket type, by the UDP protocol. Each is layered atop the transport-level IP. The Internet Control Message Protocol (ICMP) is implemented atop or beside IP and is accessible through a raw socket.
Naming Sockets in the Internet domain have names composed of a 32-bit Internet address and a 16-bit port number. Options can be used to provide IP source routing or security options. The 32-bit address is composed of network and host parts; the network part is variable in size and is frequency encoded. The host part can be interpreted optionally as a subnet field plus the host on a subnet; this is enabled by setting a network address mask.
Raw access The Internet domain allows a program with root-user authority access to the raw facilities of IP. These interfaces are modeled as SOCK_RAW sockets. Each raw socket is associated with one IP protocol number and receives all traffic for that protocol. This allows administrative and debugging functions to occur and enables user-level implementations of special-purpose protocols such as inter-gateway routing protocols.

XNS Domain Properties

A characteristic of the Xerox Network System (XNS) domain is the SOCK_SEQPACKET socket type, which provides reliable message-style communications.

The Operating System Network Device Driver (NDD) Domain Properties

Characteristics of the operating system NDD domain are:

Socket types and protocols The SOCK_DGRAM socket type is supported by the connectionless datagram protocols. These include Ethernet, token ring, Fiber Distributed Data Interface (FDDI), and FCS protocols. This socket type allows applications to send and receive datagrams directly over these media types. The SOCK_CONN_DGRAM socket type is supported by connection-oriented datagram protocols. Currently, Asynchronous Transfer Mode (ATM) is the only protocol defined for this socket type. This socket type has the property of connection-oriented, unreliable, message delivery service.
Naming Sockets in the NDD domain have names composed of the operating system NDD name and a second part that is protocol dependent. For example, for ATM, this part contains a 20-byte destination address and subaddress.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]