IPC(3X) IPC(3X) NAME ipccreat, ipcopen, ipclisten, ipcaccept, ipcreject, ipcexec, ipcpath , ipclogin, ipcrogin - set up connections between processes or machines SYNOPSIS #include <ipc.h> char *ipcpath(name, network, service) char *name; char *network; char *service; int ipcopen(name, param) char *name; char *param; int ipccreat(name, param) char *name; char *param; ipcinfo *ipclisten(fd) int fd; int ipcaccept(ip) ipcinfo *ip; int ipcreject(ip, no, str) ipcinfo *ip; int no; char *str; int ipcexec(name, param, cmd) char *name; char *param; char *cmd; int ipclogin(fd) int fd; int ipcrogin(fd, opt) int fd; char *opt; extern char *errstr; DESCRIPTION These routines establish communication between unrelated processes, often for networking purposes. They are loaded by the -lipc option of ld(1). IPC(3X) IPC(3X) End points in the network are identified by names of the form: element[!element]... . The name is translated element by element relative to the name space selected by the previ- ous element. The first element is always a name in the local file system. By convention, all network interfaces and services mount themselves in For example: /cs/exec refers to a local process which has mounted itself (via ipccreat ) on /cs/dk!nj/astro/voice refers to a voice synthesizer attached to Datakit; pro- cess is the Datakit interface. /cs/dk!dutoit!exec is the process that has mounted itself on in machine `dutoit'. Ipcpath, forms a network name from its arguments and returns a pointer to it. It takes three arguments: the destination name, the default network, and the default service. It assumes that name is a three part name of the form: network!host!service. If either network or service is miss- ing from name, ipcpath supplies them from the default argu- ments. It then tacks a on the front and returns a pointer to that. Thus, ipcpath("dutoit", "dk", "dcon") returns a pointer to the string `/cs/dk!dutoit!dcon'. Ipcopen places a call to a named network end point and returns a file descriptor for the resulting connection. Param, a whitespace-delimited string of values, specifies properties which the connection must have. At present four parameter values are defined: heavy light Heavy (usually computer-to-computer) or light (computer-to-terminal) traffic is expected. delim The connection must support delimiters; see stream(4). hup SIGHUP must be generated at end of file; see signal(2). Ipccreat attaches a process to a name space. It returns a file descriptor representing the attachment. Name and param mean the same as for ipcopen. Ipclisten waits for calls (from ipcopen in other processes) appearing on file descriptor fd (obtained from ipccreat). IPC(3X) IPC(3X) When a call arrives, it returns an ipcinfo structure, defined in typedef struct { int reserved[5]; char *name; that being dialed char *param; parameters used to set up call char *machine; machine id of caller char *user; user name of caller int uid, gid; uid, gid of caller } ipcinfo; The call may be accepted by ipcaccept or rejected by ipcreject. Ipcaccept returns a file descriptor for the con- nection. Ipcreject takes an integer error number and an error message string, which will be passed back to the caller as errno and errstr. A higher-level routine, ipcexec, executes the command, cmd, on a named machine. The file descriptor returned by ipcexec is the standard input, standard output, and standard error of the command. As in ipcopen, param lists properties required of the channel. Once a connection is established using ipcopen it is often necessary to authenticate yourself to the destination. This is done using ipclogin and ipcrogin. Ipclogin runs the client side of the authentication protocol described in svcmgr(8) for the v9auth action. The supplied fd is the descriptor returned by ipcopen. Until the authentication is accepted, ipclogin will prompt the user (using for a login id and password to be sent over fd. Ipcrogin runs the client side of the authentication protocol used by BSD's rlogin and rsh services. Unlike ipclogin, it will not prompt the user if the authentication fails. Ipcrogin takes a second argument that is written to fd after the authentication is accepted. EXAMPLES To connect to the voice synthesizer attached to the Datakit: #include <ipc.h> main() { int fd; fd = ipcopen(ipcpath("voice", "dk", 0), "light"); if(fd<0){ printf("can't connect: %s\n", errstr); exit(1); } ... close(fd); } IPC(3X) IPC(3X) To place a Dataphone call via Datakit; the service name is derived in an obvious way from the ACU service class; see dialout(3). fd = ipcopen(ipcpath("9-1-201-582-0000", "dk", "dial1200"), "light"); To announce as a local service and wait for incoming calls: #include <ipc.h> main() { int fd; ipcinfo *ip; fd = ipccreat("/tmp/service", 0); if(fd<0){ printf("can't announce: %s\n", errstr); exit(1); } while(ip = ipclisten(fd)){ int nfd; if(i_hate_this_user(ip->machine, ip->user)) { ipcreject(ip, EACCES, "i hate you"); continue; } nfd = ipcaccept(ip); ... close(nfd); } printf("lost the announced connection somehow\n"); exit(1); } FILES the announce point for the Datakit dialer the announce point for the internet dialer SEE ALSO dialout(3), connld(4), dkmgr(8), svcmgr(8), tcpmgr(8) D. L. Presotto, `Interprocess Communication in the Eighth Edition UNIX System', this manual, Volume 2 DIAGNOSTICS Integer return values of -1 and pointer return values of 0 denote error. Errno contains an error code (see intro(2)) and errstr points to an explanatory string. BUGS Files created by ipccreat in the local name space are not removed when the file descriptor returned by ipccreat is closed. Information in ipcinfo is no more trustworthy than its ori- gin. Information, such as user name, sent by foreign machines may be suspect. On Ethernet or dialup connections (but not on Datakit) machine names can be forged. Let's not even think about wire-swappers and wiretappers.