Blob


1 #include <u.h>
2 #include <sys/socket.h>
3 #include <netinet/in.h>
4 #include <libc.h>
5 #include "mountnfs.h"
7 void
8 usage(void)
9 {
10 fprint(2, "usage: vmount [-v] [-h handle] address mountpoint\n");
11 exits("usage");
12 }
14 int handlelen = 1;
15 uchar handle[64] = {
16 0x00
17 };
19 void
20 main(int argc, char **argv)
21 {
22 char *p, *net, *unx;
23 u32int host;
24 int n, port, proto, verbose;
25 struct sockaddr_in sa;
27 verbose = 0;
28 ARGBEGIN{
29 case 'h':
30 p = EARGF(usage());
31 n = strlen(p);
32 if(n%2)
33 sysfatal("bad handle '%s'", p);
34 if(n > 2*sizeof handle)
35 sysfatal("handle too long '%s'", p);
36 handlelen = n/2;
37 if(dec16(handle, n/2, p, n) != n/2)
38 sysfatal("bad hex in handle '%s'", p);
39 break;
41 case 'v':
42 verbose = 1;
43 break;
45 default:
46 usage();
47 }ARGEND
49 if(argc != 2)
50 usage();
52 p = p9netmkaddr(argv[0], "udp", "nfs");
53 if(p9dialparse(strdup(p), &net, &unx, &host, &port) < 0)
54 sysfatal("bad address '%s'", p);
56 if(verbose)
57 print("nfs server is net=%s addr=%d.%d.%d.%d port=%d\n",
58 net, host&0xFF, (host>>8)&0xFF, (host>>16)&0xFF, host>>24, port);
60 proto = 0;
61 if(strcmp(net, "tcp") == 0)
62 proto = SOCK_STREAM;
63 else if(strcmp(net, "udp") == 0)
64 proto = SOCK_DGRAM;
65 else
66 sysfatal("bad proto %s: can only handle tcp and udp", net);
68 memset(&sa, 0, sizeof sa);
69 memmove(&sa.sin_addr, &host, 4);
70 sa.sin_family = AF_INET;
71 sa.sin_port = htons(port);
73 mountnfs(proto, &sa, handle, handlelen, argv[1]);
74 exits(0);
75 }