]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/ip/tftpfs.c
merge
[plan9front.git] / sys / src / cmd / ip / tftpfs.c
index 55d8f496d40df909c2c8cb0ca2939dc4238af853..fa84d2b1de9cbc239d813d6f1b487affab774631 100644 (file)
@@ -16,7 +16,7 @@ enum {
        Tftp_ERROR      = 5,
        Tftp_OACK       = 6,
 
-       TftpPort                = 69,
+       TftpPort        = 69,
 
        Segsize         = 512,
        Maxpath         = 2+2+Segsize-8,
@@ -25,19 +25,19 @@ enum {
 typedef struct Tfile Tfile;
 struct Tfile
 {
-       int             id;
+       int     id;
        uchar   addr[IPaddrlen];
-       char            path[Maxpath];
+       char    path[Maxpath];
        Channel *c;
-       Tfile           *next;
+       Tfile   *next;
        Ref;
 };
 
+char net[Maxpath];
 uchar ipaddr[IPaddrlen];
 static ulong time0;
 Tfile *files;
 
-
 static Tfile*
 tfileget(uchar *addr, char *path)
 {
@@ -53,7 +53,7 @@ tfileget(uchar *addr, char *path)
        f = emalloc9p(sizeof *f);
        memset(f, 0, sizeof(*f));
        ipmove(f->addr, addr);
-       strncpy(f->path, path, sizeof(f->path));
+       strncpy(f->path, path, Maxpath-1);
        f->ref = 1;
        f->id = id++;
        f->next = files;
@@ -148,7 +148,7 @@ static void
 download(void *aux)
 {
        int fd, cfd, last, block, seq, n, ndata;
-       char *err, adir[40];
+       char *err, adir[40], buf[256];
        uchar *data;
        Channel *c;
        Tfile *f;
@@ -171,9 +171,10 @@ download(void *aux)
        if((c = f->c) == nil)
                goto out;
 
-       threadsetname(f->path);
+       threadsetname("%s", f->path);
 
-       if((cfd = announce("udp!*!0", adir)) < 0){
+       snprint(buf, sizeof(buf), "%s/udp!*!0", net);
+       if((cfd = announce(buf, adir)) < 0){
                err = "announce: %r";
                goto out;
        }
@@ -211,7 +212,7 @@ download(void *aux)
                msg.buf[n] = 0;
                switch(nhgets(msg.buf)){
                case Tftp_ERROR:
-                       werrstr((char*)msg.buf+4);
+                       werrstr("%s", (char*)msg.buf+4);
                        err = "%r";
                        goto out;
 
@@ -264,8 +265,6 @@ out:
        if(c){
                while((r != nil) || (r = recvp(c))){
                        if(err){
-                               char buf[ERRMAX];
-
                                snprint(buf, sizeof(buf), err);
                                respond(r, buf);
                        } else {
@@ -412,7 +411,7 @@ fsstat(Req *r)
 
 Srv fs = 
 {
-.attach=               fsattach,
+.attach=       fsattach,
 .destroyfid=   fsdestroyfid,
 .walk1=                fswalk1,
 .clone=                fsclone,
@@ -424,7 +423,7 @@ Srv fs =
 void
 usage(void)
 {
-       fprint(2, "usage: tftpfs [-D] [-s srvname] [-m mtpt] [ipaddr]\n");
+       fprint(2, "usage: tftpfs [-D] [-s srvname] [-m mtpt] [-x net] [ipaddr]\n");
        threadexitsall("usage");
 }
 
@@ -435,6 +434,7 @@ threadmain(int argc, char **argv)
        char *mtpt = "/n/tftp";
 
        time0 = time(0);
+       strcpy(net, "/net");
        ipmove(ipaddr, IPnoaddr);
 
        ARGBEGIN{
@@ -448,6 +448,9 @@ threadmain(int argc, char **argv)
        case 'm':
                mtpt = EARGF(usage());
                break;
+       case 'x':
+               setnetmtpt(net, sizeof net, EARGF(usage()));
+               break;
        default:
                usage();
        }ARGEND;