libc: allow /net/cs to specify local address for dial()
This commit is contained in:
parent
8666ec6b55
commit
1da5285c1e
1 changed files with 14 additions and 11 deletions
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
typedef struct DS DS;
|
typedef struct DS DS;
|
||||||
|
|
||||||
static int call(char*, char*, DS*);
|
static int call(char*, char*, char*, DS*);
|
||||||
static int csdial(DS*);
|
static int csdial(DS*);
|
||||||
static void _dial_string_parse(char*, DS*);
|
static void _dial_string_parse(char*, DS*);
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ static int
|
||||||
csdial(DS *ds)
|
csdial(DS *ds)
|
||||||
{
|
{
|
||||||
int n, fd, rv;
|
int n, fd, rv;
|
||||||
char *p, buf[Maxstring], clone[Maxpath], err[ERRMAX];
|
char *rem, *loc, buf[Maxstring], clone[Maxpath], err[ERRMAX];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* open connection server
|
* open connection server
|
||||||
|
@ -80,7 +80,7 @@ csdial(DS *ds)
|
||||||
if(fd < 0){
|
if(fd < 0){
|
||||||
/* no connection server, don't translate */
|
/* no connection server, don't translate */
|
||||||
snprint(clone, sizeof(clone), "%s/%s/clone", ds->netdir, ds->proto);
|
snprint(clone, sizeof(clone), "%s/%s/clone", ds->netdir, ds->proto);
|
||||||
return call(clone, ds->rem, ds);
|
return call(clone, ds->rem, ds->local, ds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -101,11 +101,14 @@ csdial(DS *ds)
|
||||||
seek(fd, 0, 0);
|
seek(fd, 0, 0);
|
||||||
while((n = read(fd, buf, sizeof(buf) - 1)) > 0){
|
while((n = read(fd, buf, sizeof(buf) - 1)) > 0){
|
||||||
buf[n] = 0;
|
buf[n] = 0;
|
||||||
p = strchr(buf, ' ');
|
rem = strchr(buf, ' ');
|
||||||
if(p == nil)
|
if(rem == nil)
|
||||||
continue;
|
continue;
|
||||||
*p++ = 0;
|
*rem++ = 0;
|
||||||
rv = call(buf, p, ds);
|
loc = strchr(rem, ' ');
|
||||||
|
if(loc != nil)
|
||||||
|
*loc++ = 0;
|
||||||
|
rv = call(buf, rem, ds->local!=nil? ds->local: loc, ds);
|
||||||
if(rv >= 0)
|
if(rv >= 0)
|
||||||
break;
|
break;
|
||||||
errstr(err, sizeof err);
|
errstr(err, sizeof err);
|
||||||
|
@ -124,7 +127,7 @@ csdial(DS *ds)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
call(char *clone, char *dest, DS *ds)
|
call(char *clone, char *remote, char *local, DS *ds)
|
||||||
{
|
{
|
||||||
int fd, cfd, n;
|
int fd, cfd, n;
|
||||||
char cname[Maxpath], name[Maxpath], data[Maxpath], *p;
|
char cname[Maxpath], name[Maxpath], data[Maxpath], *p;
|
||||||
|
@ -161,10 +164,10 @@ call(char *clone, char *dest, DS *ds)
|
||||||
snprint(data, sizeof(data), "%s/%s/data", cname, name);
|
snprint(data, sizeof(data), "%s/%s/data", cname, name);
|
||||||
|
|
||||||
/* connect */
|
/* connect */
|
||||||
if(ds->local)
|
if(local != nil)
|
||||||
snprint(name, sizeof(name), "connect %s %s", dest, ds->local);
|
snprint(name, sizeof(name), "connect %s %s", remote, local);
|
||||||
else
|
else
|
||||||
snprint(name, sizeof(name), "connect %s", dest);
|
snprint(name, sizeof(name), "connect %s", remote);
|
||||||
if(write(cfd, name, strlen(name)) < 0){
|
if(write(cfd, name, strlen(name)) < 0){
|
||||||
close(cfd);
|
close(cfd);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in a new issue