static int rpc(int argc, char *argv[]) { struct rpcent *re; int i, rv = RV_OK; setrpcent(1); if (argc == 2) { while ((re = getrpcent()) != NULL) RPCPRINT; } else { for (i = 2; i < argc; i++) { const char *err; long long id = strtonum(argv[i], 0, UINT_MAX, &err); if (!err) re = getrpcbynumber((int)id); else re = getrpcbyname(argv[i]); if (re != NULL) RPCPRINT; else { rv = RV_NOTFOUND; break; } } } endrpcent(); return rv; }
int getrpcbyname_r(const char *name, struct rpcent *result_buf, char *buffer, size_t buflen, struct rpcent **result) { int ret; __UCLIBC_MUTEX_LOCK(mylock); ret = __copy_rpcent(getrpcbyname(name), result_buf, buffer, buflen, result); __UCLIBC_MUTEX_UNLOCK(mylock); return ret; }
static int rpcent_test_getrpcbyname(struct rpcent *rpc_model, void *mdata) { char **alias; struct rpcent *rpc; if (debug) { printf("testing getrpcbyname() with the following data:\n"); dump_rpcent(rpc_model); } rpc = getrpcbyname(rpc_model->r_name); if (rpcent_test_correctness(rpc, NULL) != 0) goto errfin; if ((compare_rpcent(rpc, rpc_model, NULL) != 0) && (rpcent_check_ambiguity((struct rpcent_test_data *)mdata, rpc) !=0)) goto errfin; for (alias = rpc_model->r_aliases; *alias; ++alias) { rpc = getrpcbyname(*alias); if (rpcent_test_correctness(rpc, NULL) != 0) goto errfin; if ((compare_rpcent(rpc, rpc_model, NULL) != 0) && (rpcent_check_ambiguity( (struct rpcent_test_data *)mdata, rpc) != 0)) goto errfin; } if (debug) printf("ok\n"); return (0); errfin: if (debug) printf("not ok\n"); return (-1); }
unsigned long rpc_getprognum(const char *prog) { struct rpcent *rpc; if (isalpha(*prog)) { rpc = getrpcbyname((char *)prog); if (rpc == NULL) { return 0; } return rpc->r_number; } else { return (u_long) atoi(prog); } }
struct rpcent *rpc_getrpcent(const char *prog) { struct rpcent *ent, *ret; if (isalpha(*prog)) { ent = getrpcbyname((char *)prog); } else { ent = getrpcbynumber(atoi(prog)); } if (ent == NULL) return NULL; ret = mp_malloc(sizeof(struct rpcent)); ret->r_name = mp_strdup(ent->r_name); ret->r_number = ent->r_number; return ret; }
static void test_rpc (void) { struct rpcent *rptr; rptr = getrpcbyname ("portmap"); output_rpcent ("getrpcyname (\"portmap\")", rptr); rptr = getrpcbynumber (100000); output_rpcent ("getrpcbynumber (100000)", rptr); setrpcent (0); do { rptr = getrpcent (); output_rpcent ("getrpcent ()", rptr); } while (rptr != NULL); endrpcent (); }
int sam_initrpc( char *rpchost) { struct rpcent *rpce; char *hostname; /* Get rpcent for program number */ rpce = getrpcbyname(PROGNAME); if (!rpce) { /* Try getting the rpcent using the default program number */ rpce = getrpcbynumber(SamFS); if ((!rpce) || (strcmp(PROGNAME, rpce->r_name))) { errno = EADDRNOTAVAIL; return(-1); } } /* Get name of sam host */ if (rpchost) { hostname = rpchost; } else { if (!(hostname = getenv("SAMHOST"))) { hostname = SAMRPC_HOST; } } if (!strcmp(hostname, "localhost")) { samlocal = 1; } clnt = clnt_create(hostname, (u_long)rpce->r_number, SAMVERS, "tcp"); if (clnt == (CLIENT *)NULL) { clnt_pcreateerror(hostname); return(-1); } auth_destroy(clnt->cl_auth); clnt->cl_auth = authunix_create_default(); return(0); }
/* * rpc */ static int rpc(int argc, char *argv[]) { struct rpcent *re; unsigned long id; int i, rv; assert(argc > 1); assert(argv != NULL); #define RPCPRINT printfmtstrings(re->r_aliases, " ", " ", \ "%-16s %6d", \ re->r_name, re->r_number) setrpcent(1); rv = RV_OK; if (argc == 2) { while ((re = getrpcent()) != NULL) RPCPRINT; } else { for (i = 2; i < argc; i++) { if (parsenum(argv[i], &id)) re = getrpcbynumber((int)id); else re = getrpcbyname(argv[i]); if (re != NULL) RPCPRINT; else { rv = RV_NOTFOUND; break; } } } endrpcent(); return rv; }
main( int argc, char * argv[] ) { struct timeval intervalle = { TIMEOUT_SEC, 0 }; CLIENT * client ; int c ; struct rpcent * etc_rpc ; /* pour consulter /etc/rpc ou rpc.bynumber */ unsigned int adresse_serveur ; /* Au format NET */ struct hostent * hp ; char nom_exec[MAXPATHLEN] ; char machine_locale[256] ; char * tempo_nom_exec = NULL ; unsigned int rpc_service_num = DEFAULT_RPC_SERVICE ; unsigned int rpc_version = V4 ; unsigned int rpcproc = PROC_PLUS1 ; unsigned short port = ntohs( 2049 ) ; int val = 2 ; int rc ; char gss_service[1024] ; char host[100] ; struct COMPOUND4args compound4_args ; struct COMPOUND4res compound4_res ; /* On recupere le nom de l'executable */ if( ( tempo_nom_exec = strrchr( argv[0], '/' ) ) != NULL ) strcpy( (char *)nom_exec, tempo_nom_exec + 1 ) ; strcpy( ifname, "eth0" ) ; while( ( c = getopt( argc, argv, options ) ) != EOF ) { switch( c ) { case 'd': /* Cette option permet de recuperer un nom pour la machine distante */ if( isalpha( *optarg ) ) { strcpy( host, optarg ) ; } else { adresse_serveur = inet_addr( optarg ) ; } break; case 's': /* Un nom ou un numero de service a ete indique */ if( isalpha( (int)*optarg ) ) { /* Ca commence pas par un chiffre donc c'est un nom service */ if( ( etc_rpc = getrpcbyname( optarg ) ) == NULL ) { fprintf( stderr, "Impossible de resoudre le service %s\n", optarg ) ; } else { rpc_service_num = etc_rpc->r_number ; } } else { /* C'est un numero de service qui est indique */ rpc_service_num = atoi( optarg ) ; } break ; case 'v': /* numero de version */ rpc_version = atoi( optarg ) ; break ; case 'p': rpcproc = atoi( optarg ) ; break ; case 'I': strcpy( ifname, optarg ) ; break ; case 'h': case '?': default: /* Affichage de l'aide en ligne */ fprintf( stderr, utilisation, nom_exec ) ; exit( 0 ) ; break ; } } if( ( client = Creer_RPCClient( host, rpc_service_num, rpc_version, port , RPC_ANYSOCK ) ) == NULL ) { char erreur[100] ; strcpy( erreur, clnt_spcreateerror( "Creation RPC" ) ) ; fprintf( stderr, "Creation RPC: %s\n", erreur ) ; exit( 1 ) ; } client->cl_auth = authunix_create_default(); compound4_args.tag.utf8string_len = 0 ; /* No Tag */ compound4_args.minorversion = 0 ; compound4_args.argarray.argarray_len = 1 ; compound4_args.argarray.argarray_val = (struct nfs_argop4 * )malloc( sizeof( struct nfs_argop4 ) ) ; compound4_args.argarray.argarray_val[0].argop = NFS4_OP_PUTROOTFH ; /* This operation requires no argument */ fprintf( stderr, "requete v4\n" ) ; if( ( rc = clnt_call( client, 1, (xdrproc_t)xdr_COMPOUND4args, (caddr_t)&compound4_args, (xdrproc_t)xdr_COMPOUND4res, (caddr_t)&compound4_res, intervalle ) ) != RPC_SUCCESS ) { clnt_perror( client, "appel a NFSPROC4_COMPOUND\n" ) ; exit ( 1 ) ; } fprintf( stderr, "Requete v4 OK\n" ) ; auth_destroy( client->cl_auth ) ; clnt_destroy( client ) ; }
main( int argc, char * argv[] ) { struct timeval intervalle = { TIMEOUT_SEC, 0 }; CLIENT * client ; int c ; struct rpcent * etc_rpc ; /* pour consulter /etc/rpc ou rpc.bynumber */ unsigned int adresse_serveur ; /* Au format NET */ struct hostent * hp ; char nom_exec[MAXPATHLEN] ; char machine_locale[256] ; char * tempo_nom_exec = NULL ; unsigned int rpc_service_num = DEFAULT_RPC_SERVICE ; unsigned int rpc_version = V1 ; unsigned int rpcproc = PROC_PLUS1 ; unsigned short port = ntohs( DEFAULT_PORT ) ; int val = 2 ; int rc ; char gss_service[1024] ; char host[100] ; strcpy( ifname, "eth0" ) ; /* On recupere le nom de l'executable */ if( ( tempo_nom_exec = strrchr( argv[0], '/' ) ) != NULL ) strcpy( (char *)nom_exec, tempo_nom_exec + 1 ) ; strcpy( ifname, "eth0" ) ; while( ( c = getopt( argc, argv, options ) ) != EOF ) { switch( c ) { case 'd': /* Cette option permet de recuperer un nom pour la machine distante */ if( isalpha( *optarg ) ) { strcpy( host, optarg ) ; } else { adresse_serveur = inet_addr( optarg ) ; } break; case 's': /* Un nom ou un numero de service a ete indique */ if( isalpha( (int)*optarg ) ) { /* Ca commence pas par un chiffre donc c'est un nom service */ if( ( etc_rpc = getrpcbyname( optarg ) ) == NULL ) { fprintf( stderr, "Impossible de resoudre le service %s\n", optarg ) ; } else { rpc_service_num = etc_rpc->r_number ; } } else { /* C'est un numero de service qui est indique */ rpc_service_num = atoi( optarg ) ; } break ; case 'v': /* numero de version */ rpc_version = atoi( optarg ) ; break ; case 'p': rpcproc = atoi( optarg ) ; break ; case 'I': strcpy( ifname, optarg ) ; break ; case 'h': case '?': default: /* Affichage de l'aide en ligne */ fprintf( stderr, utilisation, nom_exec ) ; exit( 0 ) ; break ; } } if( ( client = Creer_RPCClient( host, rpc_service_num, rpc_version, port , RPC_ANYSOCK ) ) == NULL ) { char erreur[100] ; strcpy( erreur, clnt_spcreateerror( "Creation RPC" ) ) ; fprintf( stderr, "Creation RPC: %s\n", erreur ) ; exit( 1 ) ; } client->cl_auth = authunix_create_default(); val = 2 ; fprintf( stderr, "J'envoie la valeur %d\n", val ) ; if( ( rc = clnt_call( client, rpcproc, (xdrproc_t)xdr_int, (caddr_t)&val, (xdrproc_t)xdr_int, (caddr_t)&val, intervalle ) ) != RPC_SUCCESS ) { clnt_perror( client, "appel a FIXE_RET\n" ) ; exit ( 1 ) ; } fprintf( stderr, "Je recois la valeur %d\n", val ) ; auth_destroy( client->cl_auth ) ; clnt_destroy( client ) ; }