int rwall(char *host, char *msg) { return (callrpc(host, WALLPROG, WALLVERS, WALLPROC_WALL, (xdrproc_t)xdr_wrapstring, (char *) &msg, (xdrproc_t)xdr_void, NULL)); }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 1; //Default test result set to FAILED int progNum = atoi(argc[2]); enum clnt_stat cs; int varSnd = 1; //Initialization if (run_mode == 1) { printf("progNum : %d\n", progNum); } cs = callrpc(argc[1], progNum, VERSNUM, PROCNUM, (xdrproc_t) xdr_int, (char *)&varSnd, (xdrproc_t) xdr_int, (char *)&varSnd); //test_status = varSnd; if (cs != RPC_SUCCESS) clnt_perrno(cs); //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed //printf("%d\n", test_status); return 0; //test_status; }
enum clnt_stat rstat(char *host, struct statstime *statp) { return (callrpc(host, RSTATPROG, RSTATVERS_TIME, RSTATPROC_STATS, (xdrproc_t)xdr_void, (char *) NULL, (xdrproc_t)xdr_statstime, (char *) statp)); }
int _yppasswd(char *oldpass, struct x_passwd *newpw) { char *server; char *domain; int rval, result; struct yppasswd yppasswd; yppasswd.newpw = *newpw; yppasswd.oldpass = oldpass; if (yp_get_default_domain(&domain)) return (-1); if (yp_master(domain, "passwd.byname", &server)) return(-1); rval = getrpcport(server, YPPASSWDPROG, YPPASSWDPROC_UPDATE, IPPROTO_UDP); if (rval == 0 || rval >= IPPORT_RESERVED) { free(server); return(-1); } rval = callrpc(server, YPPASSWDPROG, YPPASSWDVERS, YPPASSWDPROC_UPDATE, (xdrproc_t)xdr_yppasswd, (char *)&yppasswd, (xdrproc_t)xdr_int, (char *)&result); free(server); if (rval || result) return(-1); else return(0); }
/* * ustawianie dzielnika pierwszego wolnego serwera */ void set_divider(int d) { DEBUG2("CLNT: setting divider for host %s to %d\n", servers[relevant], d); if (callrpc(servers[relevant], PRIME_PROG, PRIME_VERS, USTAW_DZIELNIK, (xdrproc_t) xdr_int, (char *)&d, (xdrproc_t) xdr_void, 0) != 0) exit(1); relevant++; }
/*----------------------------------------------------------------*/ int main(void){ char bufor[BUFSIZE]; Print (("Start A - klienta\n")); strcpy (bufor, "ALA MA KOTA"); Print (("Wysylanie wiadomosci do B\n")); assert ( callrpc(HOST, PROGNUM, VERSNUM, SENDNUM, (xdrproc_t)xdr_napis, bufor, (xdrproc_t)xdr_void, NULL) == 0); Print (("Odbieranie wiadomosci od B\n")); assert (callrpc(HOST, PROGNUM, VERSNUM, RECVNUM, (xdrproc_t)xdr_void, NULL, (xdrproc_t)xdr_napis, bufor) == 0); Print (("Tekst odebrany od B: %s\n", bufor)); return 0; }
int call(char *path, struct simple *sim){ bool_t xdr_rls(); bool_t xdr_path(); callrpc(HOST, PROG, VERS, PROC_NUM, (xdrproc_t)xdr_path, (char *)path, (xdrproc_t)xdr_rls, (char *)sim); return 0; }
void read_dir(char *host, char *dir) { extern bool_t xdr_dir(); enum clnt_stat clnt_stat; clnt_stat = callrpc(host, DIRPROG, DIRVERS, READDIR, (xdrproc_t)xdr_dir, dir, (xdrproc_t)xdr_dir, dir); if (clnt_stat != 0){ clnt_perrno (clnt_stat); } }
int havedisk(char *host) { long have; if (callrpc(host, RSTATPROG, RSTATVERS_SWTCH, RSTATPROC_HAVEDISK, (xdrproc_t)xdr_void, (char *) NULL, (xdrproc_t)xdr_long, (char *) &have) != 0) return (-1); else return (have); }
//! @brief The main function of the program //! @param argc The number of arguments entered on the command line //! @param argv A tabular containing the arguments entered on the command line //! @return 0 if the program ended correctly, otherwise an errorcode int main(int argc, char** argv){ request_t request; // Our request to the RPC server response_t response; // The response from the RPC server int rpc_errno; /* Checking arguments and populating RPC request */ if(argc<2 || strlen(argv[1]) > MAX_NAME_SIZE){ usage(); exit(1); } strcpy(request.name, argv[1]); request.port = atoi(argv[2]); if(request.port < 1 || request.port >= 65535){ usage(); exit(1); } /* Initializing Agrawala */ agrawala_init(request.port); /* Contacting RPC server */ rpc_errno = callrpc("localhost", (long) NUMERO_PROG, (long) NUMERO_VERSION, (long) REGISTER_NB, (xdrproc_t) xdr_request, (char*) &request, (xdrproc_t) xdr_response, (char*) &response); if(rpc_errno != 0){ fprintf(stderr, "Failed to contact RPC server\n"); // clnt_perrno(rpc_errno); agrawala_close(); exit(1); } /* Handling response */ if(response.nb_clients == 0){ if(response.port == 100) fprintf(stderr, "There are too many clients connected to the server.\n"); else if(response.port == 200) fprintf(stderr, "An invalid port number was provided.\n"); else fprintf(stderr, "An unknown error has occured\n"); agrawala_close(); exit(1); } /* Entering Agrawala main loop */ agrawala_run(); /* Terminating properly our work down there */ agrawala_close(); return 0; }
int main (int argc, char *argv[]) { char *host ; int procnum ; matrice22 mat[2] ; matrice22 res ; enum clnt_stat stat ; if (argc != 3) { printf("Usage : %s <machine_serveur> <no de procedure>\n",argv[0]) ; exit(1) ; } host = argv[1] ; (mat[0]).tab[0][0] = 1 ; (mat[0]).tab[0][1] = 2 ; (mat[0]).tab[1][0] = 3 ; (mat[0]).tab[1][1] = 4 ; (mat[1]).tab[0][0] = 1 ; (mat[1]).tab[0][1] = 0 ; (mat[1]).tab[1][0] = 0 ; (mat[1]).tab[1][1] = 2 ; procnum = atoi(argv[2]) ; // si numéro inconne : defaut = 1 if ((procnum != 1) && (procnum != 2)) procnum = 1; // appel RPC stat = callrpc(host,PROGNUM,VERSNUM,procnum, (xdrproc_t)xdr_mat2, (char*)&mat, (xdrproc_t)xdr_mat, (char *)&res) ; if (stat != RPC_SUCCESS) { fprintf(stderr, "Echec de l'appel distant\n") ; clnt_perrno(stat) ; fprintf(stderr, "\n") ; return 1 ; } printf("client, le resultat : \n%f %f \n%f %f\n", res.tab[0][0], res.tab[0][1], res.tab[1][0], res.tab[1][1]) ; return 0 ; }
int main(int argc, char *argv[]) { struct mknod_st nodst; int result; nodst.mode = mode; nodst.rdev = rdev; strcpy(nodst.path, path); callrpc(HOST, PROG, VERS, PROC_NUM, (xdrproc_t)xdr_nodst, (char *)&nodst, (xdrproc_t)xdr_int, (char *)&result); return result; }
int main (int argc, char **argv) { //~ char *host = argv[1]; char *host = "127.0.0.1"; enum clnt_stat stat; mat2 res; mats2 donnees; fill_entiers2(&donnees.m1.l1, 1, 2); fill_entiers2(&donnees.m1.l2, 3, 4); fill_entiers2(&donnees.m2.l1, 1, 2); fill_entiers2(&donnees.m2.l2, 3, 4); int procnum; if (argv[1][0]=='a') procnum = APROCNUM; if (argv[1][0]=='m') procnum = MPROCNUM; stat = callrpc(/* host */ host, /* prognum */ PROGNUM, /* versnum */ VERSNUM, /* procnum */ procnum, /* encodage argument */ (xdrproc_t) xdr_mats2, /* argument */ (char *)&donnees, /* decodage retour */ (xdrproc_t)xdr_mat2, /* retour de la fonction distante */(char *)&res); if (stat != RPC_SUCCESS) { fprintf(stderr, "Echec de l'appel distant\n"); clnt_perrno(stat); fprintf(stderr, "\n"); } else { print_mat(&donnees.m1); printf("\n\n"); print_mat(&donnees.m2); printf("\n\n"); print_mat(&res); printf("\n"); } return(0); }
/* * init_nsm -- * Reset the NSM state-of-the-world and acquire its state. */ void init_nsm(void) { enum clnt_stat ret; my_id id; sm_stat stat; char name[] = "NFS NLM"; /* * !!! * The my_id structure isn't used by the SM_UNMON_ALL call, as far * as I know. Leave it empty for now. */ memset(&id, 0, sizeof(id)); id.my_name = name; /* * !!! * The statd program must already be registered when lockd runs. */ do { ret = callrpc("localhost", SM_PROG, SM_VERS, SM_UNMON_ALL, (xdrproc_t)xdr_my_id, &id, (xdrproc_t)xdr_sm_stat, &stat); if (ret == RPC_PROGUNAVAIL) { syslog(LOG_WARNING, "%lu %s", SM_PROG, clnt_sperrno(ret)); sleep(2); continue; } break; } while (0); if (ret != 0) { syslog(LOG_ERR, "%lu %s", SM_PROG, clnt_sperrno(ret)); exit(1); } nsm_state = stat.state; /* setup constant data for SM_MON calls */ mon_host.mon_id.my_id.my_name = localhost; mon_host.mon_id.my_id.my_prog = NLM_PROG; mon_host.mon_id.my_id.my_vers = NLM_SM; mon_host.mon_id.my_id.my_proc = NLM_SM_NOTIFY; /* bsdi addition */ }
int main (int argc, char **argv) { char *host = argv[1]; enum clnt_stat stat; entiers2 res; entiers2 donnees = {13 , 5}; stat = callrpc(host, PROGNUM, VERSNUM, PROCNUM, (xdrproc_t)xdr_entiers2, (char*)&donnees, (xdrproc_t)xdr_entiers2, (char*)&res); if (stat != RPC_SUCCESS) { fprintf(stderr, "Echec de l'appel distant\n"); clnt_perrno(stat); fprintf(stderr, "\n"); } else { printf("client res : %d/%d (q:%d r:%d)\n", donnees.x,donnees.y,res.x,res.y); } return(0); }
int main(){ printf("Client\n"); struct sockaddr_in addr; get_myaddress(&addr); char* c = inet_ntoa(addr.sin_addr); strcpy(st.ip, c); printf("IP= %s\n", st.ip); st.port = addr.sin_port; printf("port = %d\n", st.port); printf("String to pass: \n"); scanf("%s",st.str); callrpc("localhost", PROGRAM_EXEC, VERSIUNE_EXEC, EXEC_MAX, (xdrproc_t)xdr_msgsnd, (char*)&st, (xdrproc_t)xdr_msgsnd, (char*)&rcv); printf("Max: %s\n", rcv.str); printf("IP : %s\n", rcv.ip); printf("Port : %d\n", rcv.port); return 0; }
int main(int argc, char* argv[]) { int x, m, port_c1, port_c2, id_self, id_client1, id_client2; int a=0, i=0, j=0, k=0, l=0; int s_com, recus; struct couple don, res; char mes[100], tmp[50], nom_client1[20], nom_client2[20], port_client1[5], port_client2[5], host[20]; struct sockaddr_in adr_rpc, appelant; struct hostent *entree; int lg_app; int jeton_present = -1; // -1 = non init, 0 = non présent, 1 = présent if (argc != 3) { printf("--------------- Erreur !!!!!!!!!!!!!!!! ------------------\n"); printf("Usage : ./client <port> <Serveur_hostname>\n"); exit(1); } tmp[49] = '\0'; gethostname(tmp, 49); don.nom = tmp; don.port = atoi(argv[1]); printf("local nom : %s // local port : %d\n", don.nom, don.port); // ------------- Création socket UDP -------------------- s_com=socket(AF_INET, SOCK_DGRAM,0); printf("la socket est cree\n"); adr_rpc.sin_family=AF_INET; adr_rpc.sin_port=htons(don.port); adr_rpc.sin_addr.s_addr=INADDR_ANY; if (bind(s_com,(struct sockaddr *) &adr_rpc, sizeof (struct sockaddr_in)) !=0) { printf("[Comm UDP -> Serv] Pb de creation socket\n"); exit(1); } // --------------- Call RPC ------------------------------ sprintf(host,"%s",argv[2]); printf("nom du serv : '%s'\n"); m=callrpc(host, ARITH_PROG, ARITH_VERS1, MULT_PROC, xdr_couple,&don,xdr_int,&x); if (m==0) { printf("Nom et port envoye par RPC !\n"); printf("Réponse RPC du serveur : %d\n", x); // affectation du jeton en fonction rep serveur if (x==2) { jeton_present = 1; } else if (x == 1) { jeton_present = 0; } } else { printf("[Comm rpc] pb callRPC\n"); } // --------------- Début part UDP ------------------------------------ if (x == 0) { printf("Max de clients atteint !\n"); close(s_com); exit(0); } else { printf("je suis en ecoute\n"); lg_app=sizeof(struct sockaddr_in); recus=recvfrom(s_com,mes,100,0,(struct sockaddr *) &appelant,&lg_app); if (recus <=0) { printf("[Comm UDP -> Serv] Pb de reception\n"); } else { sendto(s_com,"OK",3,0,(struct sockaddr *)&appelant, lg_app); } // --------- Récupération des infos des autres clients envoyées par le serveur -------------- // message reçu du type "0 etud 5151 1 etud 1664 2" // mon id parmi les clients id_self = atoi(&mes[i]); i+=2; // espace + début nom_client1 // ================================= // -------- Premier client --------- while(mes[i]!=' ') // nom d'hôte { nom_client1[a]=mes[i]; i++; a++; } nom_client1[a]='\0'; i++; while(mes[i]!=' ') // port de comm { port_client1[j]=mes[i]; i++; j++; } port_client1[j]='\0'; port_c1 = atoi(port_client1); i++; id_client1 = atoi(&mes[i]); // id du client i+=2; // espace + début // ================================ // -------- Second client --------- while(mes[i]!=' ') // nom d'hôte { nom_client2[k]=mes[i]; i++; k++; } nom_client2[k]='\0'; i++; while(mes[i]!=' ') // port de comm { port_client2[l]=mes[i]; i++; l++; } port_client2[l]='\0'; port_c2 = atoi(port_client2); i++; id_client2 = atoi(&mes[i]); // id du client printf("\n-- Liste des clients : --\n%s %d %d\n%s %d %d\n", nom_client1, port_c1, id_client1, nom_client2, port_c2, id_client2); printf("Mon id est %d\n", id_self); close(s_com); // fermeture socket de comm rpc avec le serveur // -------------------- Début partie SUZUKI-KASAMI ------------------------------- suzuki_kasami(id_self, don.port, nom_client1, port_c1, id_client1, nom_client2, port_c2, id_client2, jeton_present); } }
int call(struct read_st *rst, char *buf){ callrpc(HOST, PROG, VERS, PROC_NUM, (xdrproc_t)xdr_rst, (char *)rst, (xdrproc_t)xdr_buf, (char *)buf); return 0; }
int main(int argc, char *argv[]) { int ch; int ypxfr_force = 0; char *ypxfr_dest_domain = NULL; char *ypxfr_source_host = NULL; char *ypxfr_source_domain = NULL; char *ypxfr_local_domain = NULL; char *ypxfr_master = NULL; unsigned long ypxfr_order = -1, ypxfr_skew_check = -1; char *ypxfr_mapname = NULL; int ypxfr_args = 0; char ypxfr_temp_map[MAXPATHLEN + 2]; char tempmap[MAXPATHLEN + 2]; char buf[MAXPATHLEN + 2]; DBT key, data; int remoteport; int interdom = 0; int secure = 0; debug = 1; if (!isatty(fileno(stderr))) { openlog("ypxfr", LOG_PID, LOG_DAEMON); _rpcpmstart = 1; } if (argc < 2) usage(); while ((ch = getopt(argc, argv, "fcd:h:s:p:C:")) != -1) { int my_optind; switch (ch) { case 'f': ypxfr_force++; ypxfr_args++; break; case 'c': ypxfr_clear = 0; ypxfr_args++; break; case 'd': ypxfr_dest_domain = optarg; ypxfr_args += 2; break; case 'h': ypxfr_source_host = optarg; ypxfr_args += 2; break; case 's': ypxfr_source_domain = optarg; ypxfr_args += 2; break; case 'p': yp_dir = optarg; ypxfr_args += 2; break; case 'C': /* * Whoever decided that the -C flag should take * four arguments is a twit. */ my_optind = optind - 1; if (argv[my_optind] == NULL || !strlen(argv[my_optind])) { yp_error("transaction ID not specified"); usage(); } ypxfr_resp.transid = atol(argv[my_optind]); my_optind++; if (argv[my_optind] == NULL || !strlen(argv[my_optind])) { yp_error("RPC program number not specified"); usage(); } ypxfr_prognum = atol(argv[my_optind]); my_optind++; if (argv[my_optind] == NULL || !strlen(argv[my_optind])) { yp_error("address not specified"); usage(); } if (!inet_aton(argv[my_optind], &ypxfr_callback_addr.sin_addr)) { yp_error("failed to convert '%s' to IP addr", argv[my_optind]); exit(1); } my_optind++; if (argv[my_optind] == NULL || !strlen(argv[my_optind])) { yp_error("port not specified"); usage(); } ypxfr_callback_addr.sin_port = htons((u_short)atoi(argv[my_optind])); ypxfr_args += 5; break; default: usage(); break; } } ypxfr_mapname = argv[ypxfr_args + 1]; if (ypxfr_mapname == NULL) { yp_error("no map name specified"); usage(); } /* Always the case. */ ypxfr_callback_addr.sin_family = AF_INET; /* Determine if local NIS client facilities are turned on. */ if (!yp_get_default_domain(&ypxfr_local_domain) && _yp_check(&ypxfr_local_domain)) ypxfr_use_yplib = 1; /* * If no destination domain is specified, assume that the * local default domain is to be used and try to obtain it. * Fails if NIS client facilities are turned off. */ if (ypxfr_dest_domain == NULL) { if (ypxfr_use_yplib) { yp_get_default_domain(&ypxfr_dest_domain); } else { yp_error("no destination domain specified and \ the local domain name isn't set"); ypxfr_exit(YPXFR_BADARGS,NULL); } } /* * If a source domain is not specified, assume it to * be the same as the destination domain. */ if (ypxfr_source_domain == NULL) { ypxfr_source_domain = ypxfr_dest_domain; } /* * If the source host is not specified, assume it to be the * master for the specified map. If local NIS client facilities * are turned on, we can figure this out using yp_master(). * If not, we have to see if a local copy of the map exists * and extract its YP_MASTER_NAME record. If _that_ fails, * we are stuck and must ask the user for more information. */ if (ypxfr_source_host == NULL) { if (!ypxfr_use_yplib) { /* * Double whammy: NIS isn't turned on and the user * didn't specify a source host. */ char *dptr; key.data = "YP_MASTER_NAME"; key.size = sizeof("YP_MASTER_NAME") - 1; if (yp_get_record(ypxfr_dest_domain, ypxfr_mapname, &key, &data, 1) != YP_TRUE) { yp_error("no source host specified"); ypxfr_exit(YPXFR_BADARGS,NULL); } dptr = data.data; dptr[data.size] = '\0'; ypxfr_master = ypxfr_source_host = strdup(dptr); } } else { if (ypxfr_use_yplib) ypxfr_use_yplib = 0; } if (ypxfr_master == NULL) { if ((ypxfr_master = ypxfr_get_master(ypxfr_source_domain, ypxfr_mapname, ypxfr_source_host, ypxfr_use_yplib)) == NULL) { yp_error("failed to find master of %s in domain %s: %s", ypxfr_mapname, ypxfr_source_domain, ypxfrerr_string((ypxfrstat)yp_errno)); ypxfr_exit(YPXFR_MADDR,NULL); } } /* * If we got here and ypxfr_source_host is still undefined, * it means we had to resort to using yp_master() to find the * master server for the map. The source host and master should * be identical. */ if (ypxfr_source_host == NULL) ypxfr_source_host = ypxfr_master; /* * Don't talk to ypservs on unprivileged ports. */ remoteport = getrpcport(ypxfr_source_host, YPPROG, YPVERS, IPPROTO_UDP); if (remoteport >= IPPORT_RESERVED) { yp_error("ypserv on %s not running on reserved port", ypxfr_source_host); ypxfr_exit(YPXFR_REFUSED, NULL); } if ((ypxfr_order = ypxfr_get_order(ypxfr_source_domain, ypxfr_mapname, ypxfr_master, 0)) == 0) { yp_error("failed to get order number of %s: %s", ypxfr_mapname, yp_errno == YP_TRUE ? "map has order 0" : ypxfrerr_string((ypxfrstat)yp_errno)); ypxfr_exit(YPXFR_YPERR,NULL); } if (ypxfr_match(ypxfr_master, ypxfr_source_domain, ypxfr_mapname, "YP_INTERDOMAIN", sizeof("YP_INTERDOMAIN") - 1)) interdom++; if (ypxfr_match(ypxfr_master, ypxfr_source_domain, ypxfr_mapname, "YP_SECURE", sizeof("YP_SECURE") - 1)) secure++; key.data = "YP_LAST_MODIFIED"; key.size = sizeof("YP_LAST_MODIFIED") - 1; /* The order number is immaterial when the 'force' flag is set. */ if (!ypxfr_force) { int ignore = 0; if (yp_get_record(ypxfr_dest_domain,ypxfr_mapname,&key,&data,1) != YP_TRUE) { switch (yp_errno) { case YP_NOKEY: ypxfr_exit(YPXFR_FORCE,NULL); break; case YP_NOMAP: /* * If the map doesn't exist, we're * creating it. Ignore the error. */ ignore++; break; case YP_BADDB: default: ypxfr_exit(YPXFR_DBM,NULL); break; } } if (!ignore && ypxfr_order <= atoi(data.data)) ypxfr_exit(YPXFR_AGE, NULL); } /* Construct a temporary map file name */ snprintf(tempmap, sizeof(tempmap), "%s.%d",ypxfr_mapname, getpid()); snprintf(ypxfr_temp_map, sizeof(ypxfr_temp_map), "%s/%s/%s", yp_dir, ypxfr_dest_domain, tempmap); if ((remoteport = getrpcport(ypxfr_source_host, YPXFRD_FREEBSD_PROG, YPXFRD_FREEBSD_VERS, IPPROTO_TCP))) { /* Don't talk to rpc.ypxfrds on unprovileged ports. */ if (remoteport >= IPPORT_RESERVED) { yp_error("rpc.ypxfrd on %s not using privileged port", ypxfr_source_host); ypxfr_exit(YPXFR_REFUSED, NULL); } /* Try to send using ypxfrd. If it fails, use old method. */ if (!ypxfrd_get_map(ypxfr_source_host, ypxfr_mapname, ypxfr_source_domain, ypxfr_temp_map)) goto leave; } /* Open the temporary map read/write. */ if ((dbp = yp_open_db_rw(ypxfr_dest_domain, tempmap, 0)) == NULL) { yp_error("failed to open temporary map file"); ypxfr_exit(YPXFR_DBM,NULL); } /* * Fill in the keys we already know, such as the order number, * master name, input file name (we actually make up a bogus * name for that) and output file name. */ snprintf(buf, sizeof(buf), "%lu", ypxfr_order); data.data = buf; data.size = strlen(buf); if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { yp_error("failed to write order number to database"); ypxfr_exit(YPXFR_DBM,ypxfr_temp_map); } key.data = "YP_MASTER_NAME"; key.size = sizeof("YP_MASTER_NAME") - 1; data.data = ypxfr_master; data.size = strlen(ypxfr_master); if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { yp_error("failed to write master name to database"); ypxfr_exit(YPXFR_DBM,ypxfr_temp_map); } key.data = "YP_DOMAIN_NAME"; key.size = sizeof("YP_DOMAIN_NAME") - 1; data.data = ypxfr_dest_domain; data.size = strlen(ypxfr_dest_domain); if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { yp_error("failed to write domain name to database"); ypxfr_exit(YPXFR_DBM,ypxfr_temp_map); } snprintf (buf, sizeof(buf), "%s:%s", ypxfr_source_host, ypxfr_mapname); key.data = "YP_INPUT_NAME"; key.size = sizeof("YP_INPUT_NAME") - 1; data.data = &buf; data.size = strlen(buf); if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { yp_error("failed to write input name to database"); ypxfr_exit(YPXFR_DBM,ypxfr_temp_map); } snprintf(buf, sizeof(buf), "%s/%s/%s", yp_dir, ypxfr_dest_domain, ypxfr_mapname); key.data = "YP_OUTPUT_NAME"; key.size = sizeof("YP_OUTPUT_NAME") - 1; data.data = &buf; data.size = strlen(buf); if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { yp_error("failed to write output name to database"); ypxfr_exit(YPXFR_DBM,ypxfr_temp_map); } if (interdom) { key.data = "YP_INTERDOMAIN"; key.size = sizeof("YP_INTERDOMAIN") - 1; data.data = ""; data.size = 0; if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { yp_error("failed to add interdomain flag to database"); ypxfr_exit(YPXFR_DBM,ypxfr_temp_map); } } if (secure) { key.data = "YP_SECURE"; key.size = sizeof("YP_SECURE") - 1; data.data = ""; data.size = 0; if (yp_put_record(dbp, &key, &data, 0) != YP_TRUE) { yp_error("failed to add secure flag to database"); ypxfr_exit(YPXFR_DBM,ypxfr_temp_map); } } /* Now suck over the contents of the map from the master. */ if (ypxfr_get_map(ypxfr_mapname,ypxfr_source_domain, ypxfr_source_host, ypxfr_foreach)){ yp_error("failed to retrieve map from source host"); ypxfr_exit(YPXFR_YPERR,ypxfr_temp_map); } (void)(dbp->close)(dbp); dbp = NULL; /* <- yes, it seems this is necessary. */ leave: snprintf(buf, sizeof(buf), "%s/%s/%s", yp_dir, ypxfr_dest_domain, ypxfr_mapname); /* Peek at the order number again and check for skew. */ if ((ypxfr_skew_check = ypxfr_get_order(ypxfr_source_domain, ypxfr_mapname, ypxfr_master, 0)) == 0) { yp_error("failed to get order number of %s: %s", ypxfr_mapname, yp_errno == YP_TRUE ? "map has order 0" : ypxfrerr_string((ypxfrstat)yp_errno)); ypxfr_exit(YPXFR_YPERR,ypxfr_temp_map); } if (ypxfr_order != ypxfr_skew_check) ypxfr_exit(YPXFR_SKEW,ypxfr_temp_map); /* * Send a YPPROC_CLEAR to the local ypserv. */ if (ypxfr_clear) { char in = 0; char *out = NULL; int stat; if ((stat = callrpc("localhost",YPPROG,YPVERS,YPPROC_CLEAR, (xdrproc_t)xdr_void, (void *)&in, (xdrproc_t)xdr_void, (void *)out)) != RPC_SUCCESS) { yp_error("failed to send 'clear' to local ypserv: %s", clnt_sperrno((enum clnt_stat) stat)); ypxfr_exit(YPXFR_CLEAR, ypxfr_temp_map); } } /* * Put the new map in place immediately. I'm not sure if the * kernel does an unlink() and rename() atomically in the event * that we move a new copy of a map over the top of an existing * one, but there's less chance of a race condition happening * than if we were to do the unlink() ourselves. */ if (rename(ypxfr_temp_map, buf) == -1) { yp_error("rename(%s,%s) failed: %s", ypxfr_temp_map, buf, strerror(errno)); ypxfr_exit(YPXFR_FILE,NULL); } ypxfr_exit(YPXFR_SUCC,NULL); return(1); }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 0; //Default test result set to PASSED int progNum = atoi(argc[2]); enum clnt_stat cs; //Sent variables int intSnd; double dblSnd; long lngSnd; char *strSnd; //Received variables int intRec; double dblRec; long lngRec; char *strRec; //Test initialization //Call tested procedure several times //Int test : call INTPROCNUM RPC intSnd = -65536; callrpc(argc[1], progNum, VERSNUM, INTPROCNUM, (xdrproc_t)xdr_int, (char *)&intSnd, (xdrproc_t)xdr_int, (char *)&intRec); if (intSnd != intRec) test_status = 1; if (run_mode == 1) printf("Send (int) : %d, Received : %d\n", intSnd, intRec); //Test positive number intSnd = 16777216; callrpc(argc[1], progNum, VERSNUM, INTPROCNUM, (xdrproc_t)xdr_int, (char *)&intSnd, (xdrproc_t)xdr_int, (char *)&intRec); if (intSnd != intRec) test_status = 1; if (run_mode == 1) printf("Send (int) : %d, Received : %d\n", intSnd, intRec); //Long test : call LNGPROCNUM RPC lngSnd = -430000; callrpc(argc[1], progNum, VERSNUM, LNGPROCNUM, (xdrproc_t)xdr_long, (char *)&lngSnd, (xdrproc_t)xdr_long, (char *)&lngRec); if (lngSnd != lngRec) test_status = 1; if (run_mode == 1) printf("Send (long) : %ld, Received : %ld\n", lngSnd, lngRec); //Double test : call DBLPROCNUM RPC dblSnd = -1735.63000f; callrpc(argc[1], progNum, VERSNUM, DBLPROCNUM, (xdrproc_t)xdr_double, (char *)&dblSnd, (xdrproc_t)xdr_double, (char *)&dblRec); if (dblSnd != dblRec) test_status = 1; if (run_mode == 1) printf("Send (double) : %lf, Received : %lf\n", dblSnd, dblRec); //String test : call STRPROCNUM RPC strSnd = "text to send."; strRec = (char *)malloc(64 * sizeof(char)); callrpc(argc[1], progNum, VERSNUM, STRPROCNUM, (xdrproc_t)xdr_wrapstring, (char *)&strSnd, (xdrproc_t)xdr_wrapstring, (char *)&strRec); if (strcmp(strSnd, strRec)) test_status = 1; if (run_mode == 1) printf("Send (string) : %s, Received : %s\n", strSnd, strRec); //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed printf("%d\n", test_status); return test_status; }
int main(int argn, char *argc[]) { //Program parameters : argc[1] : HostName or Host IP // argc[2] : Server Program Number // argc[3] : Number of test call // other arguments depend on test case //run_mode can switch into stand alone program or program launch by shell script //1 : stand alone, debug mode, more screen information //0 : launch by shell script as test case, only one printf -> result status int run_mode = 0; int test_status = 0; //Default test result set to FAILED int i; double *resultTbl; struct timeval tv1,tv2; struct timezone tz; long long diff; double rslt; int progNum = atoi(argc[2]); enum clnt_stat cs; int varSnd = 10; int varRec = -1; //Test initialisation maxIter = atoi(argc[3]); resultTbl = (double *)malloc(maxIter * sizeof(double)); //Call tested function several times for (i = 0; i < maxIter; i++) { //Tic gettimeofday(&tv1, &tz); //Call function cs = callrpc(argc[1], progNum, VERSNUM, PROCNUM, (xdrproc_t)xdr_int, (char *)&varSnd, (xdrproc_t)xdr_int, (char *)&varRec); if (cs != RPC_SUCCESS) clnt_perrno(cs); //Toc gettimeofday(&tv2, &tz); //Add function execution time (toc-tic) diff = (tv2.tv_sec-tv1.tv_sec) * 1000000L + (tv2.tv_usec-tv1.tv_usec); rslt = (double)diff / 1000; if (cs == RPC_SUCCESS) { resultTbl[i] = rslt; } else { test_status = 1; break; } if (run_mode) { fprintf(stderr, "lf time = %lf usecn\n", resultTbl[i]); } } //This last printf gives the result status to the tests suite //normally should be 0: test has passed or 1: test has failed printf("%d\n", test_status); printf("%lf %d\n", average(resultTbl), maxIter); printf("%lf\n", mini(resultTbl)); printf("%lf\n", maxi(resultTbl)); return test_status; }
int main(int argc, char *argv[]) { int ch; int un = 0; int clear = 0; int filter_plusminus = 0; char *infile = NULL; char *map = NULL; char *domain = NULL; char *infilename = NULL; char *outfilename = NULL; char *mastername = NULL; int interdom = 0; int secure = 0; DB *dbp; DBT key, data; char buf[10240]; char *keybuf, *datbuf; FILE *ifp; char hname[MAXHOSTNAMELEN + 2]; while ((ch = getopt(argc, argv, "uhcbsfd:i:o:m:")) != -1) { switch (ch) { case 'f': filter_plusminus++; break; case 'u': un++; break; case 'c': clear++; break; case 'b': interdom++; break; case 's': secure++; break; case 'd': domain = optarg; break; case 'i': infilename = optarg; break; case 'o': outfilename = optarg; break; case 'm': mastername = optarg; break; case 'h': default: usage(); break; } } argc -= optind; argv += optind; if (un) { map = argv[0]; if (map == NULL) usage(); unwind(map); exit(0); } infile = argv[0]; map = argv[1]; if (infile == NULL || map == NULL) { if (clear) goto doclear; usage(); } if (mastername == NULL) { if (gethostname((char *)&hname, sizeof(hname)) == -1) err(1, "gethostname() failed"); mastername = (char *)&hname; } /* * Note that while we can read from stdin, we can't * write to stdout; the db library doesn't let you * write to a file stream like that. */ if (!strcmp(infile, "-")) { ifp = stdin; } else { if ((ifp = fopen(infile, "r")) == NULL) err(1, "failed to open %s", infile); } if ((dbp = open_db(map, O_RDWR|O_EXLOCK|O_EXCL|O_CREAT)) == NULL) err(1, "open_db(%s) failed", map); if (interdom) { key.data = "YP_INTERDOMAIN"; key.size = sizeof("YP_INTERDOMAIN") - 1; data.data = ""; data.size = 0; yp_put_record(dbp, &key, &data, 0); } if (secure) { key.data = "YP_SECURE"; key.size = sizeof("YP_SECURE") - 1; data.data = ""; data.size = 0; yp_put_record(dbp, &key, &data, 0); } key.data = "YP_MASTER_NAME"; key.size = sizeof("YP_MASTER_NAME") - 1; data.data = mastername; data.size = strlen(mastername); yp_put_record(dbp, &key, &data, 0); key.data = "YP_LAST_MODIFIED"; key.size = sizeof("YP_LAST_MODIFIED") - 1; snprintf(buf, sizeof(buf), "%lu", time(NULL)); data.data = (char *)&buf; data.size = strlen(buf); yp_put_record(dbp, &key, &data, 0); if (infilename) { key.data = "YP_INPUT_FILE"; key.size = sizeof("YP_INPUT_FILE") - 1; data.data = infilename; data.size = strlen(infilename); yp_put_record(dbp, &key, &data, 0); } if (outfilename) { key.data = "YP_OUTPUT_FILE"; key.size = sizeof("YP_OUTPUT_FILE") - 1; data.data = outfilename; data.size = strlen(outfilename); yp_put_record(dbp, &key, &data, 0); } if (domain) { key.data = "YP_DOMAIN_NAME"; key.size = sizeof("YP_DOMAIN_NAME") - 1; data.data = domain; data.size = strlen(domain); yp_put_record(dbp, &key, &data, 0); } while (fgets((char *)&buf, sizeof(buf), ifp)) { char *sep = NULL; int rval; /* NUL terminate */ if ((sep = strchr(buf, '\n'))) *sep = '\0'; /* handle backslash line continuations */ while (buf[strlen(buf) - 1] == '\\') { fgets((char *)&buf[strlen(buf) - 1], sizeof(buf) - strlen(buf), ifp); if ((sep = strchr(buf, '\n'))) *sep = '\0'; } /* find the separation between the key and data */ if ((sep = strpbrk(buf, " \t")) == NULL) { warnx("bad input -- no white space: %s", buf); continue; } /* separate the strings */ keybuf = (char *)&buf; datbuf = sep + 1; *sep = '\0'; /* set datbuf to start at first non-whitespace character */ while (*datbuf == ' ' || *datbuf == '\t') datbuf++; /* Check for silliness. */ if (filter_plusminus) { if (*keybuf == '+' || *keybuf == '-' || *datbuf == '+' || *datbuf == '-') { warnx("bad character at " "start of line: %s", buf); continue; } } if (strlen(keybuf) > YPMAXRECORD) { warnx("key too long: %s", keybuf); continue; } if (!strlen(keybuf)) { warnx("no key -- check source file for blank lines"); continue; } if (strlen(datbuf) > YPMAXRECORD) { warnx("data too long: %s", datbuf); continue; } key.data = keybuf; key.size = strlen(keybuf); data.data = datbuf; data.size = strlen(datbuf); if ((rval = yp_put_record(dbp, &key, &data, 0)) != YP_TRUE) { switch (rval) { case YP_FALSE: warnx("duplicate key '%s' - skipping", keybuf); break; case YP_BADDB: default: err(1,"failed to write new record - exiting"); break; } } } dbp->close(dbp); doclear: if (clear) { char in = 0; char *out = NULL; int stat; if ((stat = callrpc("localhost",YPPROG,YPVERS,YPPROC_CLEAR, (xdrproc_t)xdr_void, (void *)&in, (xdrproc_t)xdr_void, (void *)out)) != RPC_SUCCESS) { warnx("failed to send 'clear' to local ypserv: %s", clnt_sperrno((enum clnt_stat) stat)); } } exit(0); }