texperiment: translation from standard notations to plan 9 in netmkaddr - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 6215fd56f1c9d9392806efd1ac499f91c8ae83fb
 (DIR) parent 73a5509ae929e41ca0047254a880c8efd4aa72a1
 (HTM) Author: rsc <devnull@localhost>
       Date:   Sun, 23 Jul 2006 02:56:37 +0000
       
       experiment: translation from standard notations to plan 9 in netmkaddr
       
       Diffstat:
         M man/man3/dial.3                     |      16 ++++++++++++++++
         M src/lib9/dial.c                     |       3 +++
         M src/lib9/netmkaddr.c                |      30 +++++++++++++++++-------------
       
       3 files changed, 36 insertions(+), 13 deletions(-)
       ---
 (DIR) diff --git a/man/man3/dial.3 b/man/man3/dial.3
       t@@ -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.
        It returns a pointer to static data holding the actual address to use.
        .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
        parses a network address as described above
        into a network name, a Unix domain socket address,
 (DIR) diff --git a/src/lib9/dial.c b/src/lib9/dial.c
       t@@ -118,6 +118,9 @@ Unix:
                        free(buf);
                        return -1;
                }
       +        /* Allow regular files in addition to Unix sockets. */
       +        if((s = open(unix, ORDWR)) >= 0)
       +                return s;
                memset(&su, 0, sizeof su);
                su.sun_family = AF_UNIX;
                if(strlen(unix)+1 > sizeof su.sun_path){
 (DIR) diff --git a/src/lib9/netmkaddr.c b/src/lib9/netmkaddr.c
       t@@ -16,21 +16,25 @@ netmkaddr(char *linear, char *defnet, char *defsrv)
                 */
                cp = strchr(linear, '!');
                if(cp == 0){
       -                if(defnet==0){
       -                        if(defsrv)
       -                                snprint(addr, sizeof(addr), "net!%s!%s",
       -                                        linear, defsrv);
       -                        else
       -                                snprint(addr, sizeof(addr), "net!%s", linear);
       +                if(defnet == 0)
       +                        defnet = "net";
       +                /* allow unix sockets to omit unix! prefix */
       +                if(access(linear, 0) >= 0){
       +                        snprint(addr, sizeof(addr), "unix!%s", linear);
       +                        return addr;
                        }
       -                else {
       -                        if(defsrv)
       -                                snprint(addr, sizeof(addr), "%s!%s!%s", defnet,
       -                                        linear, defsrv);
       -                        else
       -                                snprint(addr, sizeof(addr), "%s!%s", defnet,
       -                                        linear);
       +                /* allow host:service in deference to Unix convention */
       +                if((cp = strchr(linear, ':')) != nil){
       +                        snprint(addr, sizeof(addr), "%s!%.*s!%s", 
       +                                defnet, utfnlen(linear, cp-linear),
       +                                linear, cp+1);
       +                        return addr;
                        }
       +                if(defsrv)
       +                        snprint(addr, sizeof(addr), "%s!%s!%s",
       +                                defnet, linear, defsrv);
       +                else
       +                        snprint(addr, sizeof(addr), "%s!%s", defnet, linear);
                        return addr;
                }