Network Interface Guide

Overview of Sockets

Sockets are the most commonly used low-level interface to network protocols. They have been an integral part of SunOS releases since 1981. A socket is an endpoint of communication to which a name can be bound. A socket has a type and one associated process. Sockets were designed to implement the client-server model for interprocess communication where:

Sockets make network protocols available, while behaving like UNIX files. Applications create sockets when they are needed. Sockets work with the close(2), read(2), write(2), ioctl(2), and fcntl(2) interfaces, and the operating system differentiates between the file descriptors for files and the file descriptors for sockets.

Socket Libraries

The socket interface routines are in a library that must be linked with the application. The library is contained in /usr/lib with the rest of the system service libraries. is used for dynamic linking.

Socket Types

Socket types define the communication properties visible to a user. The Internet family sockets provide access to the TCP/IP transport protocols. The Internet family is identified by the value AF_INET6, for sockets that can communicate over both IPv6 and IPv4. The value AF_INET is also supported for source compatibility with old applications and for "raw" access to IPv4.

Three types of sockets are supported:

  1. Stream sockets allow processes to communicate using TCP. A stream socket provides bidirectional, reliable, sequenced, and unduplicated flow of data with no record boundaries. After the connection has been established, data can be read from and written to these sockets as a byte stream. The socket type is SOCK_STREAM.

  2. Datagram sockets allow processes to use UDP to communicate. A datagram socket supports bidirectional flow of messages. A process on a datagram socket can receive messages in a different order from the sending sequence and can receive duplicate messages. Record boundaries in the data are preserved. The socket type is SOCK_DGRAM.

  3. Raw sockets provide access to ICMP. These sockets are normally datagram oriented, although their exact characteristics are dependent on the interface provided by the protocol. Raw sockets are not for most applications. They are provided to support developing new communication protocols or for access to more esoteric facilities of an existing protocol. Only superuser processes can use raw sockets. The socket type is SOCK_RAW.

See "Selecting Specific Protocols" for further information.

Interface Sets

SunOS 5.8 provides two sets of socket interfaces. The BSD socket interfaces are provided and, since SunOS 5.7 the XNS 5 (Unix98) Socket interfaces are also provided. The XNS 5 interfaces differ slightly from the BSD interfaces.

The XNS 5 Socket interfaces are documented in the man pages: accept(3XNET), bind(3XNET), connect(3XNET), endhostent(3XNET), endnetent(3XNET), endprotoent(3XNET), endservent(3XNET), gethostbyaddr(3XNET), gethostbyname(3XNET), gethostent(3XNET), gethostname(3XNET), getnetbyaddr(3XNET), getnetbyname(3XNET), getnetent(3XNET), getpeername(3XNET), getprotobyname(3XNET), getprotobynumber(3XNET), getprotoent(3XNET), getservbyname(3XNET), getservbyport(3XNET), getservent(3XNET), getsockname(3XNET), getsockopt(3XNET), htonl(3XNET), htons(3XNET), inet_addr(3XNET), inet_lnaof(3XNET), inet_makeaddr(3XNET), inet_netof(3XNET), inet_network(3XNET), inet_ntoa(3XNET), listen(3XNET), ntohl(3XNET), ntohs(3XNET), recv(3XNET), recvfrom(3XNET), recvmsg(3XNET), send(3XNET), sendmsg(3XNET), sendto(3XNET), sethostent(3XNET), setnetent(3XNET), setprotoent(3XNET), setservent(3XNET), setsockopt(3XNET), shutdown(3XNET), socket(3XNET), and socketpair(3XNET).

The traditional SunOS 5 BSD Socket behavior is documented in the corresponding 3N man pages. In addition, a number of new interfaces have been added to section 3N: freeaddrinfo(3SOCKET), freehostent(3SOCKET), getaddrinfo(3SOCKET), getipnodebyaddr(3SOCKET), getipnodebyname(3SOCKET), getnameinfo(3SOCKET), inet_ntop(3SOCKET), inet_pton(3SOCKET), See the standards(5) man page for information on building applications that use the XNS 5 (Unix98) socket interface.