URI:
       tvmount.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
       ---
       tvmount.c (1414B)
       ---
            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 = 1;
           16 uchar handle[64] = {
           17         0x00
           18 };
           19 
           20 void
           21 main(int argc, char **argv)
           22 {
           23         char *p, *net, *unx;
           24         char host[INET_ADDRSTRLEN];
           25         int n, port, proto, verbose;
           26         struct sockaddr_in sa;
           27 
           28         verbose = 0;
           29         ARGBEGIN{
           30         case 'h':
           31                 p = EARGF(usage());
           32                 n = strlen(p);
           33                 if(n%2)
           34                         sysfatal("bad handle '%s'", p);
           35                 if(n > 2*sizeof handle)
           36                         sysfatal("handle too long '%s'", p);
           37                 handlelen = n/2;
           38                 if(dec16(handle, n/2, p, n) != n/2)
           39                         sysfatal("bad hex in handle '%s'", p);
           40                 break;
           41 
           42         case 'v':
           43                 verbose = 1;
           44                 break;
           45 
           46         default:
           47                 usage();
           48         }ARGEND
           49 
           50         if(argc != 2)
           51                 usage();
           52 
           53         p = p9netmkaddr(argv[0], "udp", "nfs");
           54         if(p9dialparse(strdup(p), &net, &unx, &sa, &port) < 0)
           55                 sysfatal("bad address '%s'", p);
           56 
           57         if(sa.sin_family != AF_INET)
           58                 sysfatal("only IPv4 is supported");
           59 
           60         inet_ntop(AF_INET, &(sa.sin_addr), host, INET_ADDRSTRLEN);
           61 
           62         if(verbose)
           63                 print("nfs server is net=%s addr=%s port=%d\n",
           64                         net, host, port);
           65 
           66         proto = 0;
           67         if(strcmp(net, "tcp") == 0)
           68                 proto = SOCK_STREAM;
           69         else if(strcmp(net, "udp") == 0)
           70                 proto = SOCK_DGRAM;
           71         else
           72                 sysfatal("bad proto %s: can only handle tcp and udp", net);
           73 
           74         mountnfs(proto, &sa, handle, handlelen, argv[1]);
           75         exits(0);
           76 }