3 dial, announce, listen, accept, reject, netmkaddr, getnetconninfo, freenetconninfo, dialparse \- make and break network connections
10 int dial(char *addr, char *local, char *dir, int *cfdp)
13 int announce(char *addr, char *dir)
16 int listen(char *dir, char *newdir)
19 int accept(int ctl, char *dir)
22 int reject(int ctl, char *dir, char *cause)
25 char* netmkaddr(char *addr, char *defnet, char *defservice)
28 .\" void setnetmtpt(char *to, int tolen, char *from)
31 NetConnInfo* getnetconninfo(char *dir, int fd)
34 void freenetconninfo(NetConnINfo*)
37 int dialparse(char *addr, char **net, char **unix,
40 u32int *host, int *port)
44 is a network address of the form
45 .IB network ! netaddr ! service\f1,
46 .IB network ! netaddr\f1,
57 is a free variable that stands for any network in common
58 between the source and the host
61 can be a host name, a domain name, or a network address.
62 .\" or a meta-name of the form
63 .\" .BI $ attribute\f1,
67 .\" from the value-attribute pair
68 .\" .IB attribute = value
69 .\" most closely associated with the source host in the
70 .\" network data base (see
75 argument is a path name to a
77 that has files for accessing the connection.
78 To keep the same function signatures,
79 the Unix port of these routines uses strings of the form
81 instead of line directory paths.
82 These strings should be treated as opaque data and ignored.
85 makes a call to destination
87 on a multiplexed network.
93 will try in succession all
94 networks in common between source and destination
95 until a call succeeds.
96 It returns a file descriptor open for reading and writing the
99 .\" file in the line directory.
102 .\" file in the line directory contains the address called.
103 If the network allows the local address to be set,
104 as is the case with UDP and TCP port numbers, and
106 is non-zero, the local address will be set to
113 are not supported and must be zero.
118 are the complements of
121 establishes a network
122 name to which calls can be made.
131 used in announce may be a local address or an asterisk,
132 to indicate all local addresses, e.g.
136 routine takes as its first argument the
140 When a call is received,
144 file for the line the call was received on.
147 to the path name of the new line directory.
149 accepts a call received by
153 refuses the call because of
156 returns a file descriptor for the data file opened
160 makes an address suitable for dialing or announcing.
161 It takes an address along with a default network and service to use
162 if they are not specified in the address.
163 It returns a pointer to static data holding the actual address to use.
166 also translates Unix conventions into Plan 9 syntax.
169 is the name of a local file or Unix domain socket,
179 .IB net ! host ! port \fR.
182 parses a network address as described above
183 into a network name, a Unix domain socket address,
184 an IPv4 host address, and an IPv4 port number.
187 returns a structure containing information about a
188 network connection. The structure is:
191 typedef struct NetConnInfo NetConnInfo;
194 char *dir; /* connection directory */
195 char *root; /* network root */
196 char *spec; /* binding spec */
197 char *lsys; /* local system */
198 char *lserv; /* local service */
199 char *rsys; /* remote system */
200 char *rserv; /* remote service */
201 char *laddr; /* local address */
202 char *raddr; /* remote address */
206 The information is obtained from the
211 is nil, from the connection file descriptor
214 returns either a completely specified structure, or
215 nil if either the structure can't be allocated or the
216 network directory can't be determined.
219 .IR freenetconninfo .
222 .\" copies the name of the network mount point into
227 .\" It exists to merge two pre-existing conventions for specifying
229 .\" Commands that take a network mount point as a parameter
236 .\" .IR ipconfig (8))
243 .\" the mount point is set to the default,
247 .\" points to a string starting with a slash,
248 .\" the mount point is that path.
249 .\" Otherwise, the mount point is the string pointed to by
251 .\" appended to the string
253 .\" The last form is obsolete and is should be avoided.
254 .\" It exists only to aid in conversion.
256 Make a call and return an open file descriptor to
257 use for communications:
260 int callkremvax(void)
262 return dial("kremvax", 0, 0, 0);
266 Connect to a Unix socket served by
272 return dial("unix!/tmp/ns.ken.:0/acme", 0, 0, 0);
279 loop forever receiving calls and echoing back
280 to the caller anything sent:
287 char adir[40], ldir[40];
291 acfd = announce("tcp!*!7", adir);
295 /* listen for a call */
296 lcfd = listen(adir, ldir);
299 /* fork a process to echo */
306 /* accept the call and open the data file */
307 dfd = accept(lcfd, ldir);
312 while((n = read(dfd, buf, sizeof(buf))) > 0)
323 .B \*9/src/lib9/dial.c
325 .B \*9/src/lib9/announce.c
327 .B \*9/src/lib9/_p9dialparse.c
329 .B \*9/src/lib9/getnetconn.c
335 return \-1 if they fail.
337 To avoid name conflicts with the underlying system,
344 are preprocessor macros defined as