URI:
       tvmount0.c - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       tvmount0.c (1547B)
       ---
            1 #include <u.h>
            2 #include <sys/socket.h>
            3 #include <netinet/in.h>
            4 #include <arpa/inet.h>
            5 #include <libc.h>
            6 #include "mountnfs.h"
            7 
            8 void
            9 usage(void)
           10 {
           11         fprint(2, "usage: vmount [-v] [-h handle] address mountpoint\n");
           12         exits("usage");
           13 }
           14 
           15 int handlelen = 20;
           16 uchar handle[64] = {
           17         /* SHA1("/") */
           18         0x42, 0x09, 0x9B, 0x4A, 0xF0, 0x21, 0xE5, 0x3F, 0xD8, 0xFD,
           19         0x4E, 0x05, 0x6C, 0x25, 0x68, 0xD7, 0xC2, 0xE3, 0xFF, 0xA8
           20 };
           21 
           22 void
           23 main(int argc, char **argv)
           24 {
           25         char *p, *net, *unx;
           26         char host[INET_ADDRSTRLEN];
           27         int n, port, proto, verbose;
           28         struct sockaddr_in sa;
           29 
           30         verbose = 0;
           31         ARGBEGIN{
           32         case 'h':
           33                 p = EARGF(usage());
           34                 n = strlen(p);
           35                 if(n%2)
           36                         sysfatal("bad handle '%s'", p);
           37                 if(n > 2*sizeof handle)
           38                         sysfatal("handle too long '%s'", p);
           39                 handlelen = n/2;
           40                 if(dec16(handle, n/2, p, n) != n/2)
           41                         sysfatal("bad hex in handle '%s'", p);
           42                 break;
           43 
           44         case 'v':
           45                 verbose = 1;
           46                 break;
           47 
           48         default:
           49                 usage();
           50         }ARGEND
           51 
           52         if(argc != 2)
           53                 usage();
           54 
           55         p = p9netmkaddr(argv[0], "udp", "nfs");
           56         if(p9dialparse(strdup(p), &net, &unx, &sa, &port) < 0)
           57                 sysfatal("bad address '%s'", p);
           58 
           59         if(sa.sin_family != AF_INET)
           60                 sysfatal("only IPv4 is supported");
           61 
           62         inet_ntop(AF_INET, &(sa.sin_addr), host, INET_ADDRSTRLEN);
           63 
           64         if(verbose)
           65                 print("nfs server is net=%s addr=%s port=%d\n",
           66                         net, host, port);
           67 
           68         proto = 0;
           69         if(strcmp(net, "tcp") == 0)
           70                 proto = SOCK_STREAM;
           71         else if(strcmp(net, "udp") == 0)
           72                 proto = SOCK_DGRAM;
           73         else
           74                 sysfatal("bad proto %s: can only handle tcp and udp", net);
           75 
           76         mountnfs(proto, &sa, handle, handlelen, argv[1]);
           77         exits(0);
           78 }