experiment: translation from standard notations to plan 9 in netmkaddr
This commit is contained in:
parent
73a5509ae9
commit
6215fd56f1
3 changed files with 36 additions and 13 deletions
|
|
@ -162,6 +162,22 @@ It takes an address along with a default network and service to use
|
||||||
if they are not specified in the address.
|
if they are not specified in the address.
|
||||||
It returns a pointer to static data holding the actual address to use.
|
It returns a pointer to static data holding the actual address to use.
|
||||||
.PP
|
.PP
|
||||||
|
.I Netmkaddr
|
||||||
|
also translates Unix conventions into Plan 9 syntax.
|
||||||
|
If
|
||||||
|
.I addr
|
||||||
|
is the name of a local file or Unix domain socket,
|
||||||
|
.I netmkaddr
|
||||||
|
will return
|
||||||
|
.IB unix ! addr \fR.
|
||||||
|
If
|
||||||
|
.I addr
|
||||||
|
is of the form
|
||||||
|
.IB host : port \fR,
|
||||||
|
.I netmkaddr
|
||||||
|
will return
|
||||||
|
.IB net ! host ! port \fR.
|
||||||
|
.PP
|
||||||
.I Dialparse
|
.I Dialparse
|
||||||
parses a network address as described above
|
parses a network address as described above
|
||||||
into a network name, a Unix domain socket address,
|
into a network name, a Unix domain socket address,
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,9 @@ Unix:
|
||||||
free(buf);
|
free(buf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
/* Allow regular files in addition to Unix sockets. */
|
||||||
|
if((s = open(unix, ORDWR)) >= 0)
|
||||||
|
return s;
|
||||||
memset(&su, 0, sizeof su);
|
memset(&su, 0, sizeof su);
|
||||||
su.sun_family = AF_UNIX;
|
su.sun_family = AF_UNIX;
|
||||||
if(strlen(unix)+1 > sizeof su.sun_path){
|
if(strlen(unix)+1 > sizeof su.sun_path){
|
||||||
|
|
|
||||||
|
|
@ -16,21 +16,25 @@ netmkaddr(char *linear, char *defnet, char *defsrv)
|
||||||
*/
|
*/
|
||||||
cp = strchr(linear, '!');
|
cp = strchr(linear, '!');
|
||||||
if(cp == 0){
|
if(cp == 0){
|
||||||
if(defnet==0){
|
if(defnet == 0)
|
||||||
if(defsrv)
|
defnet = "net";
|
||||||
snprint(addr, sizeof(addr), "net!%s!%s",
|
/* allow unix sockets to omit unix! prefix */
|
||||||
linear, defsrv);
|
if(access(linear, 0) >= 0){
|
||||||
else
|
snprint(addr, sizeof(addr), "unix!%s", linear);
|
||||||
snprint(addr, sizeof(addr), "net!%s", linear);
|
return addr;
|
||||||
}
|
}
|
||||||
else {
|
/* allow host:service in deference to Unix convention */
|
||||||
if(defsrv)
|
if((cp = strchr(linear, ':')) != nil){
|
||||||
snprint(addr, sizeof(addr), "%s!%s!%s", defnet,
|
snprint(addr, sizeof(addr), "%s!%.*s!%s",
|
||||||
linear, defsrv);
|
defnet, utfnlen(linear, cp-linear),
|
||||||
else
|
linear, cp+1);
|
||||||
snprint(addr, sizeof(addr), "%s!%s", defnet,
|
return addr;
|
||||||
linear);
|
|
||||||
}
|
}
|
||||||
|
if(defsrv)
|
||||||
|
snprint(addr, sizeof(addr), "%s!%s!%s",
|
||||||
|
defnet, linear, defsrv);
|
||||||
|
else
|
||||||
|
snprint(addr, sizeof(addr), "%s!%s", defnet, linear);
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue