+char *
+getnfsargs(spec)
+ char *spec;
+{
+ register CLIENT *clp;
+ struct hostent *hp;
+ struct sockaddr_in saddr;
+ struct timeval pertry, try;
+ enum clnt_stat clnt_stat;
+ int so = RPC_ANYSOCK;
+ char *hostp, *delimp;
+ u_short tport;
+ struct nfhret nfhret;
+ char nam[MNAMELEN + 1];
+
+ strncpy(nam, spec, MNAMELEN);
+ nam[MNAMELEN] = '\0';
+ if ((delimp = index(spec, '@')) != NULL) {
+ hostp = delimp + 1;
+ } else if ((delimp = index(spec, ':')) != NULL) {
+ hostp = spec;
+ spec = delimp + 1;
+ } else {
+ fprintf(stderr,
+ "No <host>:<dirpath> or <dirpath>@<host> spec\n");
+ return (0);
+ }
+ *delimp = '\0';
+ if ((hp = gethostbyname(hostp)) == NULL) {
+ fprintf(stderr, "Can't get net id for host\n");
+ return (0);
+ }
+ bcopy(hp->h_addr, (caddr_t)&saddr.sin_addr, hp->h_length);
+ nfhret.stat = EACCES; /* Mark not yet successful */
+ while (retrycnt > 0) {
+ saddr.sin_family = AF_INET;
+ saddr.sin_port = htons(PMAPPORT);
+ if ((tport = pmap_getport(&saddr, RPCPROG_NFS,
+ NFS_VER2, IPPROTO_UDP)) == 0) {
+ if ((opflags & ISBGRND) == 0)
+ clnt_pcreateerror("NFS Portmap");
+ } else {
+ saddr.sin_port = 0;
+ pertry.tv_sec = 10;
+ pertry.tv_usec = 0;
+ if ((clp = clntudp_create(&saddr, RPCPROG_MNT,
+ RPCMNT_VER1, pertry, &so)) == NULL) {
+ if ((opflags & ISBGRND) == 0)
+ clnt_pcreateerror("Cannot MNT PRC");
+ } else {
+ clp->cl_auth = authunix_create_default();
+ try.tv_sec = 10;
+ try.tv_usec = 0;
+ clnt_stat = clnt_call(clp, RPCMNT_MOUNT,
+ xdr_dir, spec, xdr_fh, &nfhret, try);
+ if (clnt_stat != RPC_SUCCESS) {
+ if ((opflags & ISBGRND) == 0)
+ clnt_perror(clp, "Bad MNT RPC");
+ } else {
+ auth_destroy(clp->cl_auth);
+ clnt_destroy(clp);
+ retrycnt = 0;
+ }
+ }
+ }
+ if (--retrycnt > 0) {
+ if (opflags & BGRND) {
+ opflags &= ~BGRND;
+ if (fork())
+ return (0);
+ else
+ opflags |= ISBGRND;
+ }
+ sleep(10);
+ }
+ }
+ if (nfhret.stat) {
+ if (opflags & ISBGRND)
+ exit(1);
+ fprintf(stderr, "Can't access %s, errno=%d\n", spec,
+ nfhret.stat);
+ return (0);
+ }
+ saddr.sin_port = htons(tport);
+ nfsargs.addr = &saddr;
+ nfsargs.fh = &nfhret.nfh;
+ nfsargs.hostname = nam;
+ return ((caddr_t)&nfsargs);
+}
+