SOCKETS LIBRARY(3n,L) AIX Technical Reference SOCKETS LIBRARY(3n,L) ------------------------------------------------------------------------------- sockets library PURPOSE Provides communications between processes. LIBRARY Internet Library (libc.a) DESCRIPTION This section contains a list of the socket routines provided by AIX, an overview of sockets and how to use them, and a list of related publications on networks and communications that you may find useful. SOCKET ROUTINES The following table is an list of the socket routines and a brief description of each. accept Accepts a connection on a socket. bind Binds a name to a socket. connect Initiates a connection on a socket. gethostbyaddr Gets network host address. gethostbyname Gets network host name. sethostent Opens and rewinds the host entry file. endhostent Closes the host entry file. gethostid Gets the unique identifier of the current host. sethostid Sets the unique identifier of the current host. gethostname Gets the name of the current host. sethostname Sets the name of the current host. getnetent Gets network entry. getnetbyaddr Gets network entry by address. getnetbyname Gets network entry by name. Processed November 7, 1990 SOCKETS LIBRARY(3n,L) 1 SOCKETS LIBRARY(3n,L) AIX Technical Reference SOCKETS LIBRARY(3n,L) setnetent Opens and rewinds the network entry file. endnetent Closes the network entry file. getpeername Gets the name of the connected peer. getprotoent Gets protocol entry. getprotobynumber Gets protocol entry by number. getprotobyname Gets protocol entry by name. setprotoent Opens and rewinds the protocol entry file. endprotoent Closes the protocol entry file. getservent Gets service entry. getservbyname Gets service entry by name. getservbyport Gets service entry by port number. setservent Opens and rewinds the service entry file. endservent Closes the service entry file. getsockname Gets the socket name. getsockopt Gets options on sockets. setsockopt Sets options on sockets. htonl, htons Converts values between host and Internet network byte order. ntohl, ntohs Converts values between Internet network and host byte order. inet_addr Returns a string representing an Internet address. inet_network Returns a string representing an Internet network number. inet_ntoa Converts Internet address into an ASCII string. inet_makeaddr Constructs an Internet address from a Internet network number and a local network address. inet_lnaof Returns the local network address number from an Internet address. inet_netof Returns the network number from an Internet address. Processed November 7, 1990 SOCKETS LIBRARY(3n,L) 2 SOCKETS LIBRARY(3n,L) AIX Technical Reference SOCKETS LIBRARY(3n,L) listen Listens for connections on a socket. rcmd Allows execution of commands on a remote host. recv Receives a message from a connected socket only. recvfrom Receives a message from a socket. recvmsg Receives a message from a socket. resolver A set of functions that resolves domain names. Contains the following subroutines: res_mkquery res_send res_init dn_comp dn_expand getshort putshort putlong rexec Allows command execution on a remote host. rresvport Obtains a socket with a privileged address bound to it. ruserok Provides authentication of remote requests. send Sends a message from a socket only when socket is in connected state. sendto Sends a message from a socket. sendmsg Sends a message from a socket. shutdown Shuts down part or all of a full-duplex connection. socket Creates an endpoint for communications and returns a descriptor. socketpair Creates a pair of connected sockets. OVERVIEW OF SOCKETS A socket is an object that provides communications between processes. Sockets are referenced by file descriptors and have qualities similar to those of a character special device. Read, write, and select operations can be performed on sockets by using the appropriate system calls. Processed November 7, 1990 SOCKETS LIBRARY(3n,L) 3 SOCKETS LIBRARY(3n,L) AIX Technical Reference SOCKETS LIBRARY(3n,L) A socket is created with the socket system call. (See "socket.") This system call creates a socket of a specified domain, type, and protocol. Sockets have different qualities depending on these specifications. A domain is a name space or an address space. Each domain has different rules for valid names and interpretation of names. After a socket is created, it can be given a name, according to the rules of the domain in which it was created. AIX provides support for the following socket domains: Local Provides socket communication between processes running on the same AIX system when a domain of AF_UNIX is specified. A name in this domain is a string of ASCII characters whose maximum length is machine dependent. Internet Provides socket communication between a local process and a process running on a remote host when a domain of AF_INET is specified. This domain requires that IBM AIX TCP/IP be installed on your system. A name in this domain is a DARPA Internet address, made up of a 32-bit IP address and a 16-bit port address. (See the discussion of addresses and names in AIX TCP/IP User's Guide.) In AIX, there are two types of sockets: SOCK_DGRAM Provides datagrams, which are connectionless messages of a fixed maximum length. This type of socket is generally used for short messages, such as a name server or time server, since the order and reliability of message delivery is not guaranteed. In the local domain, SOCK_DGRAM is similar to a message queue. In the Internet domain, SOCK_DGRAM is implemented on the UDP/IP protocol. SOCK_STREAM Provides sequenced, two-way byte streams with a transmission mechanism for out-of-band data. The data is transmitted on a reliable basis, in order. In the local domain, SOCK_STREAM is like a pipe. In the Internet domain, SOCK_STREAM is implemented on the TCP/IP protocol. A protocol is a standard set of rules for transferring data, such as UDP/IP and TCP/IP. A protocol is specified only if more than one protocol is supported for this particular socket type in this domain. Otherwise, this parameter is set to 0. SOCKET NAMES A socket name, which is also called a socket address, is specified by the sockaddr structure. This structure is defined in the sys/socket.h header file, and it contains the following members: Processed November 7, 1990 SOCKETS LIBRARY(3n,L) 4 SOCKETS LIBRARY(3n,L) AIX Technical Reference SOCKETS LIBRARY(3n,L) ushort sa_family; /* Defines socket address family */ char sa_data[14]; /* Contains up to 14 bytes of direct address */ The sa_family is the address family or domain, either AF_UNIX for the local domain or AF_INET for the Internet domain. The contents of sa_data depend on the protocol in use, but generally a socket name consists of a machine name part and a port or service name part. RELATED NETWORK PUBLICATIONS For general information about networking, the following publications are recommended. These publications are distributed by the Network Information Center on behalf of the Defense Communications Agency and Defense Advanced Research Projects Agency (DARPA). The mailing address is: Network Information Center SRI International Menlo Park, CA 92025 o Assigned Numbers, RFC990, J. Reynolds, J. Postel o Broadcasting Internet Datagrams, RFC919, J. Mogul o Domain Names - Concepts and Facilities, RFC882, P. Mockapetris o Domain Names - Implementation and Specification, RFC883, P. Mockapetris o File Transfer Protocol, RFC959, J. Postel o Internet Control Message Protocol, RFC792, J. Postel o Internet Name Server Protocol, IEN116, J. Postel o Internet Protocol, RFC791, J. Postel o Internet Standard Subnetting Procedure, RFC950, J. Mogul o Name/Finger, RFC742, K. Harrenstien o Official ARPA-Internet Protocols, RFC944, J. Reynolds, J. Postel o Simple Mail Transfer Protocol, RFC821, J. Postel o Standard for the Format of ARPA Internet Text Messages, RFC822. o Telnet Binary Transmission, RFC856, J. Postel, J. Reynolds o Telnet Option Specifications, RFC855, J. Postel, J. Reynolds o Telnet Protocol Specification, RFC854, J. Postel, J. Reynolds o Telnet Terminal Type Option, RFC930, M. Solomon, E. Wimmers Processed November 7, 1990 SOCKETS LIBRARY(3n,L) 5 SOCKETS LIBRARY(3n,L) AIX Technical Reference SOCKETS LIBRARY(3n,L) o The TFTP Protocol, RFC783, K. R. Sollins o Time Protocol, RFC868, J. Postel, K. Harrenstien o Transmission Control Protocol, RFC793, J. Postel o Trivial File Transfer Protocol, RFC783, K. R. Sollins o User Datagram Protocol, RFC768, J. Postel RELATED INFORMATION In this book: "accept," "bind," "connect," "gethostbyaddr, gethostbyname, sethostent, endhostent," "gethostid, sethostid," "gethostname, sethostname," "getnetent, getnetbyaddr, getnetbyname, setnetent, endnetent," "getpeername," "getprotoent, getprotobynumber, getprotobyname, setprotoent, endprotoent," "getservent, getservbyname, getservbyport, setservent, endservent," "getsockname," "getsockopt, setsockopt," "htonl, htons, ntohl, ntohs," "inet_addr, inet_network, inet_ntoa, inet_makeaddr, inet_lnaof, inet_netof," "listen," "rcmd, rresvport, ruserok," "recv, recvfrom, recvmsg," "resolver: res_mkquery, res_send, res_init, dn_comp, dn_expand, getshort, getlong, putshort, putlong," "rexec," "send, sendto, sendmsg," "shutdown," "socket," and "socketpair." Processed November 7, 1990 SOCKETS LIBRARY(3n,L) 6