6 static int call(char*, char*, DS*);
7 static int csdial(DS*);
8 static void _dial_string_parse(char*, DS*);
31 * the dialstring is of the form '[/net/]proto!dest'
34 dial(char *dest, char *local, char *dir, int *cfdp)
38 char err[ERRMAX], alterr[ERRMAX];
44 _dial_string_parse(dest, &ds);
53 errstr(err, sizeof err);
54 if(strstr(err, "refused") != 0){
58 ds.netdir = "/net.alt";
64 errstr(alterr, sizeof alterr);
65 if(strstr(alterr, "translate") || strstr(alterr, "does not exist"))
68 werrstr("%s", alterr);
76 char *p, buf[Maxstring], clone[Maxpath], err[ERRMAX], besterr[ERRMAX];
79 * open connection server
81 snprint(buf, sizeof(buf), "%s/cs", ds->netdir);
82 fd = open(buf, ORDWR);
84 /* no connection server, don't translate */
85 snprint(clone, sizeof(clone), "%s/%s/clone", ds->netdir, ds->proto);
86 return call(clone, ds->rem, ds);
90 * ask connection server to translate
92 snprint(buf, sizeof(buf), "%s!%s", ds->proto, ds->rem);
93 if(write(fd, buf, strlen(buf)) < 0){
99 * loop through each address from the connection server till
100 * we get one that works.
105 while((n = read(fd, buf, sizeof(buf) - 1)) > 0){
107 p = strchr(buf, ' ');
111 rv = call(buf, p, ds);
115 errstr(err, sizeof err);
116 if(strstr(err, "does not exist") == 0)
117 strcpy(besterr, err);
121 if(rv < 0 && *besterr)
122 werrstr("%s", besterr);
129 call(char *clone, char *dest, DS *ds)
132 char cname[Maxpath], name[Maxpath], data[Maxpath], *p;
134 /* because cs is in a different name space, replace the mount point */
136 p = strchr(clone+1, '/');
143 snprint(cname, sizeof cname, "%s/%s", ds->netdir, p);
145 cfd = open(cname, ORDWR);
149 /* get directory name */
150 n = read(cfd, name, sizeof(name)-1);
156 for(p = name; *p == ' '; p++)
158 snprint(name, sizeof(name), "%ld", strtoul(p, 0, 0));
159 p = strrchr(cname, '/');
162 snprint(ds->dir, NETPATHLEN, "%s/%s", cname, name);
163 snprint(data, sizeof(data), "%s/%s/data", cname, name);
167 snprint(name, sizeof(name), "connect %s %s", dest, ds->local);
169 snprint(name, sizeof(name), "connect %s", dest);
170 if(write(cfd, name, strlen(name)) < 0){
175 /* open data connection */
176 fd = open(data, ORDWR);
189 * parse a dial string
192 _dial_string_parse(char *str, DS *ds)
196 strncpy(ds->buf, str, Maxstring);
197 ds->buf[Maxstring-1] = 0;
199 p = strchr(ds->buf, '!');
205 if(*ds->buf != '/' && *ds->buf != '#'){
209 for(p2 = p; *p2 != '/'; p2--)
212 ds->netdir = ds->buf;