Make UEFI boot-platform build again
[haiku.git] / src / bin / network / mount_nfs / mount_nfs.cpp
blob95df92e721848add6ba1c798656052a396de8bd7
1 #include <string.h>
2 #include <netdb.h>
3 #include <sys/stat.h>
4 #include <errno.h>
5 #include <stdio.h>
6 #include <Application.h>
7 #include <Roster.h>
8 #include <unistd.h>
9 #include <signal.h>
10 #include <sys/socket.h>
11 #include <arpa/inet.h>
12 #ifdef __HAIKU__
13 #include <fs_volume.h>
14 int mount(const char *filesystem, const char *where, const char *device, ulong flags, void *parameters, size_t len)
16 (void) len;
17 return fs_mount_volume(where, device, filesystem, flags, (const char *)parameters);
19 #endif
21 #define BUFSZ 1024
23 struct mount_nfs_params
25 unsigned int serverIP;
26 char *server;
27 char *_export;
28 uid_t uid;
29 gid_t gid;
30 char *hostname;
33 void usage (const char *exename);
35 void usage (const char *exename)
37 printf ("usage: %s server:export mountpoint uid gid\n",exename);
40 int main (int argc, char **argv)
42 char buf[BUFSZ];
43 signal(SIGINT, SIG_IGN);
44 signal(SIGHUP, SIG_IGN);
46 //BApplication theApp ("application/x-vnd.barecode-mount_nfs");
48 if (argc!=5)
50 usage(argv[0]);
51 return 1;
54 struct stat st;
55 if (stat(argv[2],&st)<B_NO_ERROR)
57 printf ("mountpoint does not exist\n");
58 return 1;
61 char *colon=strchr(argv[1],':');
63 if (colon==NULL)
65 usage(argv[0]);
66 return 1;
69 int serverLength=colon-argv[1];
70 char *server=new char[serverLength+1];
71 memcpy (server,argv[1],serverLength);
72 server[serverLength]=0;
74 hostent *ent;
76 ent=gethostbyname (server);
78 if (ent==NULL)
80 printf ("could not get server ip\n");
81 delete[] server;
82 return 1;
85 unsigned int serverIP=ntohl(*((unsigned int *)ent->h_addr));
87 mount_nfs_params params;
89 params.serverIP=serverIP;
90 params.server=server;
91 params._export=colon+1;
93 sscanf (argv[3],"%d",&params.uid);
94 sscanf (argv[4],"%d",&params.gid);
96 char hostname[256];
97 gethostname (hostname,256);
99 params.hostname=hostname;
101 sprintf(buf, "nfs:%s:%s,uid=%u,gid=%u,hostname=%s",
102 inet_ntoa(*((struct in_addr *)ent->h_addr)),
103 params._export,
104 params.uid,
105 params.gid,
106 params.hostname);
108 int result=mount ("nfs",argv[2],NULL,0,buf,strlen(buf));
109 //int result=mount ("nfs",argv[2],NULL,0,&params,sizeof(params));
111 delete[] server;
113 if (result<B_NO_ERROR)
115 printf ("mount failed (%s)\n",strerror(result));
116 return 1;
119 return 0;