Beispiel #1
0
void
substring_1(char *host, char * str)
{
	CLIENT *clnt;
	double  *result_1;
	//char * sub_1_arg;

#ifndef	DEBUG
	clnt = clnt_create (host, SUBSTRING, SUB, "tcp");
	if (clnt == NULL) {
		clnt_pcreateerror (host);
		exit (1);
	}
#endif	/* DEBUG */

	
	
	result_1 = sub_1(&str, clnt);
	if (result_1 == (double *) NULL) {
		clnt_perror (clnt, "call failed");
	}
	
	printf("number of occurences: %e",*result_1);
	
	
	
#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
int ControladorCliente::obtenerNumeroCliente() {
	CLIENT *clnt;
	retorno  *result_1;
	char *obteneridcliente_1_arg;

	clnt = clnt_create ("LOCALHOST", NUMERADORCLIENTE, NUMERADORCLIENTE1, "udp");
	if (clnt == NULL) {
		clnt_pcreateerror ("LOCALHOST");
		exit (1);
	}

	result_1 = obteneridcliente_1((void*)&obteneridcliente_1_arg, clnt);
	if (result_1 == (retorno *) NULL) {
		clnt_perror (clnt, "call failed");
	}

	clnt_destroy (clnt);

	this->numCliente = (*result_1).retorno_u.numero;
        
        sprintf(mensajePantalla, "Cliente #%ld:",this->numCliente);
        Logger::setProcessInformation(mensajePantalla);
        
        return this->numCliente;
}
Beispiel #3
0
void
echo_task_1(char *host,task_struct * task)
{
	CLIENT *clnt;
	
	
	char * *result_4;
	task_struct  readtask_1_arg;
	readtask_1_arg.type=task->type;
	readtask_1_arg.desc=task->desc;

#ifndef	DEBUG
	clnt = clnt_create (host, ECHO_TASK, ONE, "udp");
	if (clnt == NULL) {
		clnt_pcreateerror (host);
		exit (1);
	}
#endif	/* DEBUG */

	
	result_4 = readtask_1(&readtask_1_arg, clnt);
	if (result_4 == (char **) NULL) {
		clnt_perror (clnt, "call failed");
	}
#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
void main (int argc, char *argv[])
{
    CLIENT *clnt;
    char **msg;

        if (argc < 2) {
                printf ("usage: %s server_host\n", argv[0]);
                exit (1);
        }

    /* Create client RPC handle */
    clnt = clnt_create (argv[1], PRINTMSGPROG, PRINTMSGVERS, "tcp");
    if (clnt == NULL) {
        clnt_pcreateerror (argv[1]);
        exit (1);
    }

    /* Call Server procedure */
    msg = printmsg_1(NULL, clnt);
    if (msg == (char **) NULL) {
        clnt_perror (clnt, "call failed");
    }

    printf("Message from Server:%s\n", *msg);
    clnt_destroy (clnt);
}
void
fib_thread_1(char *host, int c_thread)
{
	CLIENT *clnt;
	int  *result_1;
	int  fib_1_arg = c_thread;

#ifndef	DEBUG
	clnt = clnt_create (host, fib_thread, fib_ver_1, "udp");
	if (clnt == NULL) {
		clnt_pcreateerror (host);
		exit (1);
	}
#endif	/* DEBUG */
	printf("Chosen thread: %d\n", fib_1_arg);
	result_1 = fib_1(&fib_1_arg, clnt);
	if (result_1 == (int *) NULL) {
		clnt_perror (clnt, "call failed");
	}else{
		if(*result_1 == 1){
			printf("You won!!  :) \n");
		}else {
			printf("You lost!! :( \n");
		}
	}

#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
void
idl_1(char *host)
{
	CLIENT *clnt;
	void  *result_1;
	data  notifier_reception_1_arg;

#ifndef	DEBUG
	clnt = clnt_create (host, IDL, VERSION_UN, "udp");
	if (clnt == NULL) {
		clnt_pcreateerror (host);
		exit (1);
	}
#endif	/* DEBUG */
	notifier_reception_1_arg.pid1 = 1;
	notifier_reception_1_arg.pid2 = 2;
	notifier_reception_1_arg.valeur = 3;
	result_1 = notifier_reception_1(&notifier_reception_1_arg, clnt);
	if (result_1 == (void *) NULL) {
		clnt_perror (clnt, "call failed");
	}
#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
Beispiel #7
0
static void pppol2tp_rpc_client_delete(void)
{
	if (pppol2tp_client != NULL) {
		clnt_destroy(pppol2tp_client);
		pppol2tp_client = NULL;
	}
}
Beispiel #8
0
void
addition_1(char *host)
{
	CLIENT *clnt;
	int  *result_1;
	numbers  add_1_arg;

#ifndef	DEBUG
	clnt = clnt_create (host, ADDITION, ADDITION_1, "udp");
	if (clnt == NULL) {
		clnt_pcreateerror (host);
		exit (1);
	}
#endif	/* DEBUG */
	scanf("%d",&add_1_arg.size);
	int i;
	for(i=0;i<add_1_arg.size;i++)
	{
		scanf("%d",&add_1_arg.nums[i]);
	}
	result_1 = add_1(&add_1_arg, clnt);
	if (result_1 == (int *) NULL) {
		clnt_perror (clnt, "call failed");
	}
	printf("%d\n",*result_1);
#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
main(int argc, char *argv[]) {
  CLIENT *c1;
  char *server;
  char **sresult;


  if (argc !=2){
    printf("=============================================================\n");
    printf("Solaris 9 PortBind XDR-DECODE taddr2uaddr() Remote DoS\n");
    printf("-------------------------------------------------------------\n");
    printf("Federico L. Bossi Bonin <*****@*****.**>\n");
    printf("=============================================================\n\n");
    printf("usage: %s <IP>\n",argv[0]);
    exit(1);
  }

  server = argv[1];

if ((c1 = clnt_create(server,100000, 4, "tcp")) == NULL){
       clnt_pcreateerror(server);
    exit(1);
  }

  xdr xdrmessage; 
  xdrmessage.long_arg = 0;
  xdrmessage.string_arg="";

  if ((sresult = str_4(&xdrmessage, c1)) == NULL){ 
   clnt_perror(c1, server);
   exit(1);
  }

  clnt_destroy(c1);
  exit(0);
}
Beispiel #10
0
int
key_gendes (des_block *key)
{
  struct sockaddr_in sin;
  CLIENT *client;
  int socket;
  enum clnt_stat stat;

  sin.sin_family = AF_INET;
  sin.sin_port = 0;
  sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
  __bzero (sin.sin_zero, sizeof (sin.sin_zero));
  socket = RPC_ANYSOCK;
  client = clntudp_bufcreate (&sin, (u_long) KEY_PROG, (u_long) KEY_VERS,
			      trytimeout, &socket, RPCSMALLMSGSIZE,
			      RPCSMALLMSGSIZE);
  if (client == NULL)
    return -1;

  stat = clnt_call (client, KEY_GEN, (xdrproc_t) xdr_void, NULL,
		    (xdrproc_t) xdr_des_block, (caddr_t) key,
		    tottimeout);
  clnt_destroy (client);
  __close (socket);
  if (stat != RPC_SUCCESS)
    return -1;

  return 0;
}
void
dateprog3_1(char *host,int day, int month, int year)
{
	CLIENT *clnt;
	int  *result_1;
	date  findday_1_arg;
        findday_1_arg.day = day;
        findday_1_arg.month = month;
        findday_1_arg.year = year;	
	clnt = clnt_create(host, DATEPROG3, SIMP_VERSION, "udp");
	if (clnt == NULL) {
		clnt_pcreateerror(host);
		exit(1);
	}
	result_1 = findday_1(&findday_1_arg, clnt);
	if (result_1 == NULL) {
		clnt_perror(clnt, "call failed:");
	}
	switch(*result_1)
	{
		case 0: printf("Sunday\n"); break;
		case 1: printf("Monday\n"); break;
		case 2: printf("Tuesday\n"); break;
		case 3: printf("Wednesday\n"); break;
		case 4: printf("Thursday\n"); break;
		case 5: printf("Friday\n"); break;
		case 6: printf("Saturday\n"); break;
		default: printf("Error in getting day\n");
	}
	clnt_destroy( clnt );
}
int
main (int argc, char *argv[])
{
	char *host;
	char *path;


	if (argc < 2) {
		printf ("usage: %s server_host\n", argv[0]);
		exit (1);
	}
	host = argv[1];
	path= argv[2];

	CLIENT *clnt;
	char  *result_1;
	
	clnt = clnt_create (host, DEL_PROG, DEL_VERS, "tcp");
	if (clnt == NULL) {
		clnt_pcreateerror (host);
		exit (1);
	}

	result_1 = del_1(&path, clnt);
	if (result_1 == (char *) NULL) {
		clnt_perror (clnt, "call failed");
	}

	clnt_destroy (clnt);
exit (0);
}
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]);
	char *proto = "tcp";
	CLIENT *clnt = NULL;

	//First of all, create a client
	clnt = clnt_create(argc[1], progNum, VERSNUM, proto);

	//Then call destroy macro
	clnt_destroy(clnt);

	//If we are here, macro call was successful
	test_status = 0;

	//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;
}
Beispiel #14
0
int main (int argc, char **argv)
{
	char *host;
	CLIENT *sv;
	int *res;
	if (argc!=2){
		printf("Uso: %s <host>\n", argv[0]);
	}
	else
	{
		host = argv[1];
		sv = clnt_create(host, CALCULAR, UNO, "tcp");
		if (sv != NULL)
		{
			res = sumar_1(5,2,sv);
			if (res != NULL){
				printf("5+2 = %d\n", *res);
			}
			else {
				clnt_perror(sv, "error en RPC");
			}
			clnt_destroy(sv);
		}
		else{
			clnt_pcreateerror(host);
		}
	}
	return (0);
}
Beispiel #15
0
static void up7_cleanup(void)
{
    if (clnt) {
        clnt_destroy(clnt);
        clnt = NULL;
    }
}
void devolverCliente(char *host, int numero)
{
	CLIENT *clnt;

	void  *result_2;
	int  devolveridcliente_1_arg;

	devolveridcliente_1_arg = numero;
	
#ifndef	DEBUG
	clnt = clnt_create (host, NUMERADORCLIENTE, NUMERADORCLIENTE1, "udp");
	if (clnt == NULL) {
		clnt_pcreateerror (host);
		exit (1);
	}
#endif	/* DEBUG */

	result_2 = devolveridcliente_1(&devolveridcliente_1_arg, clnt);
	if (result_2 == (void *) NULL) {
		clnt_perror (clnt, "call failed");
	}

#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
Beispiel #17
0
void
date_prog_1(char *host)
{
	CLIENT *clnt;
	long  *result_1;
	char *bin_date_1_arg = NULL;
	char * *result_2;
	long  str_date_1_arg = NULL;

#ifndef	DEBUG
	clnt = clnt_create (host, DATE_PROG, DATE_VERS, "udp");
	if (clnt == NULL) {
		clnt_pcreateerror (host);
		exit (1);
	}
#endif	/* DEBUG */

	result_1 = bin_date_1((void*)&bin_date_1_arg, clnt);
	if (result_1 == (long *) NULL) {
		clnt_perror (clnt, "call failed");
	}
	else{
		printf("time = %ld\n",*result_1);
	}
	result_2 = str_date_1(&str_date_1_arg, clnt);
	if (result_2 == (char **) NULL) {
		clnt_perror (clnt, "call failed");
	}
	else{
		printf("time = %s\n", *result_2);
	}
#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
Beispiel #18
0
int main(int argc, char **argv)
{
  char *server; /* 遠隔サーバ */
  CLIENT *client; /* クライアント情報 */
  char **result; /* 遠隔呼び出しの結果 */
  /* サーバ名をコマンドラインから取る */
  if (argc != 2) {
    fprintf(stderr, "usage: rdate hostname\n");
    exit(1);
  }
  server = argv[1];
  /* UDP 型のクライアントを作る */
  client = clnt_create(server, DATE_PROG, DATE_VERS, "udp");
  if (client == NULL) {
    clnt_pcreateerror(server); /* 接続失敗 */
    exit(2);
      }
  /* strdate を呼ぶ */
  result = strdate_1(NULL, client);
  if (result == NULL) {
    clnt_perror(client, server); /* 呼び出し失敗 */
    exit(2);
  }
  printf("Time on host %s = %s\n", server, *result);
  clnt_destroy(client); /* クライアント情報を破棄 */
  exit(0);
}
Beispiel #19
0
void
serverprog_1(char *host)
{
	CLIENT *clnt;
	int  *result_1;
	char  get_1_arg;
	int  *result_2;
	char  put_1_arg;

#ifndef	DEBUG
	clnt = clnt_create (host, SERVERPROG, SERVERPROTO, "udp");
	if (clnt == NULL) {
		clnt_pcreateerror (host);
		exit (1);
	}
#endif	/* DEBUG */

	result_1 = get_1(&get_1_arg, clnt);
	if (result_1 == (int *) NULL) {
		clnt_perror (clnt, "call failed");
	}
	result_2 = put_1(&put_1_arg, clnt);
	if (result_2 == (int *) NULL) {
		clnt_perror (clnt, "call failed");
	}
#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
void *my_thread_process(void *arg)
{
	int i;
	CLIENT *clnt = NULL;
	int sndVar = 0;
	int recVar = -1;
	struct timeval total_timeout;

	if (run_mode == 1) {
		fprintf(stderr, "Thread %ld\n", (long)arg);
	}
	//Initialisation
	total_timeout.tv_sec = 1;
	total_timeout.tv_usec = 1;
	/**/
	    //First of all, create client using top level API
	    clnt = clnt_create(hostname, progNum, VERSNUM, nettype);

	if (clnt == NULL) {
		printf("5\n");
		exit(5);
	}

	for (i = 0; i < callNb; i++) {
		clnt_call((CLIENT *) clnt, PROCNUM, (xdrproc_t) xdr_int, (char *)&sndVar,	// xdr_in
			  (xdrproc_t) xdr_int, (char *)&recVar,	// xdr_out
			  total_timeout);
	/**/}

	clnt_destroy(clnt);

	pthread_exit(0);
}
Beispiel #21
0
static void
onehost(char *host)
{
	utmpidlearr up;
	CLIENT *rusers_clnt;
	struct sockaddr_in addr;
	struct hostent *hp;
	struct timeval tv;

	hp = gethostbyname(host);
	if (hp == NULL)
		errx(1, "unknown host \"%s\"", host);

	rusers_clnt = clnt_create(host, RUSERSPROG, RUSERSVERS_IDLE, "udp");
	if (rusers_clnt == NULL)
		errx(1, "%s", clnt_spcreateerror(""));

	bzero((char *)&up, sizeof(up));
	tv.tv_sec = 15;	/* XXX ?? */
	tv.tv_usec = 0;
	if (clnt_call(rusers_clnt, RUSERSPROC_NAMES, (xdrproc_t)xdr_void, NULL,
	    (xdrproc_t)xdr_utmpidlearr, &up, tv) != RPC_SUCCESS)
		errx(1, "%s", clnt_sperror(rusers_clnt, ""));
	memcpy(&addr.sin_addr.s_addr, hp->h_addr, sizeof(addr.sin_addr.s_addr));
	rusers_reply((caddr_t)&up, &addr);
	clnt_destroy(rusers_clnt);
}
Beispiel #22
0
void
square_calc_1(char *host)
{
	CLIENT *clnt;
	int  *result_1;
	args  square_1_arg;

#ifndef	DEBUG
	clnt = clnt_create (host, SQUARE_CALC, SQUARE_CALC_1, "udp");
	if (clnt == NULL) {
		clnt_pcreateerror (host);
		exit (1);
	}
#endif	/* DEBUG */
	int num;
	printf("Enter the number :");
	scanf("%d", &num);

	square_1_arg.num = num;

	result_1 = square_1(&square_1_arg, clnt);
	if (result_1 == (int *) NULL) {
		clnt_perror (clnt, "call failed");
	}

	printf("Res : %d\n", *result_1);
#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
Beispiel #23
0
/*
 * Like yp_bind except can query a specific host
 */
static int
bind_host(char *dom, struct sockaddr_in *lsin)
{
	struct hostent *hent = NULL;
	struct ypbind_resp ypbr;
	struct timeval tv;
	CLIENT *client;
	int sock, r;
	struct in_addr ss_addr;

	sock = RPC_ANYSOCK;
	tv.tv_sec = 15;
	tv.tv_usec = 0;
	client = clntudp_create(lsin, YPBINDPROG, YPBINDVERS, tv, &sock);
	if (client == NULL) {
		warnx("can't clntudp_create: %s", yperr_string(YPERR_YPBIND));
		return (YPERR_YPBIND);
	}

	tv.tv_sec = 5;
	tv.tv_usec = 0;
	r = clnt_call(client, YPBINDPROC_DOMAIN,
		(xdrproc_t)xdr_domainname, &dom,
		(xdrproc_t)xdr_ypbind_resp, &ypbr, tv);
	if (r != RPC_SUCCESS) {
		warnx("can't clnt_call: %s", yperr_string(YPERR_YPBIND));
		clnt_destroy(client);
		return (YPERR_YPBIND);
	} else {
		if (ypbr.ypbind_status != YPBIND_SUCC_VAL) {
			warnx("can't yp_bind: reason: %s",
				ypbinderr_string(ypbr.ypbind_respbody.ypbind_error));
			clnt_destroy(client);
			return (r);
		}
	}
	clnt_destroy(client);

	ss_addr = ypbr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr;
	/*printf("%08x\n", ss_addr);*/
	hent = gethostbyaddr((char *)&ss_addr, sizeof(ss_addr), AF_INET);
	if (hent)
		printf("%s\n", hent->h_name);
	else
		printf("%s\n", inet_ntoa(ss_addr));
	return (0);
}
Beispiel #24
0
int
main(int argc, char *argv[])
{
	CLIENT			*rpc_clnt;
	/* */
	int			int_arg;
	int			*int_res;
	repeatargs		rpt_arg;
	String			*char_res;
	powargs			pow_arg;
	sillypowres		*pow_res;

	if (argc != 2) {
		fprintf(stderr, "usage: %s rpc-server\n", argv[0]);
		exit(1);
	}
	if ((rpc_clnt = clnt_create(argv[1], TEST_PROG1, TEST_VERS2, "tcp")) == NULL) {
		perror(argv[1]);
		exit(2);
	}

	fprintf(stderr, "Calling FNULL() ... ");
	if (fnull_2(&int_arg /* ignored */, rpc_clnt) == NULL) {
		perror("fnull_2");
		exit(3);
	}
	fprintf(stderr, "done\n");

	int_arg = 21;
	fprintf(stderr, "Calling DOUBLE(%d) = ", int_arg);
	if ((int_res = double_2(&int_arg, rpc_clnt)) == NULL) {
		perror("double_2");
		exit(4);
	}
	fprintf(stderr, "%d\n", *int_res);

	rpt_arg.num = 4;
	rpt_arg.str = "Hi!";
	fprintf(stderr, "Calling REPEAT(%d, %s) = ", rpt_arg.num, rpt_arg.str);
	if ((char_res = repeat_2(&rpt_arg, rpc_clnt)) == NULL) {
		perror("repeat_2");
		exit(5);
	}
	fprintf(stderr, "%s\n", *char_res);

	pow_arg.x = 2.0;
	pow_arg.y = 4.0;
	fprintf(stderr, "Calling POW(%f, %f) = ", pow_arg.x, pow_arg.y);
	if ((pow_res = pow_2(&pow_arg, rpc_clnt)) == NULL ||
	    pow_res->res != STATUS_OK) {
		perror("pow_2");
		exit(6);
	}
	fprintf(stderr, "%f (%s)\n", pow_res->sillypowres_u.powok.result,
		pow_res->sillypowres_u.powok.message);

	clnt_destroy(rpc_clnt);
	exit(0);
}
Beispiel #25
0
main(int argc, char *argv[]) {

if (argc < 2) {
printf("usage:%s <hostname>\n",argv[0]);
exit(1);
}

if (argc >2) { len=atoi(argv[2]);  }
if (len > 1024) { len=1024; }

unsigned long PROGRAM=100000;
unsigned long VERSION=2;

struct hostent *hp;
struct sockaddr_in server_addr;
int sock = RPC_ANYSOCK;
register CLIENT *client;
enum clnt_stat clnt_stat;
struct timeval timeout;
timeout.tv_sec = 40;
timeout.tv_usec = 0;


if ((hp = gethostbyname(argv[1])) == NULL) {
printf("Can't resolve %s\n",argv[1]);
exit(0);
}

gethostname(myhost,255);
bcopy(hp->h_addr, (caddr_t)&server_addr.sin_addr,hp->h_length);
server_addr.sin_family = AF_INET;
server_addr.sin_port =  0;

if ((client = clnttcp_create(&server_addr,PROGRAM,VERSION,&sock,1024,1024)) == NULL) {
clnt_pcreateerror("clnttcp_create");
exit(0);
}

client->cl_auth = authunix_create(myhost, 0, 0, 0, NULL);

char *data = (char *) malloc(1024);
memset(data,0x0,strlen(data));

char *response = (char *) malloc(1024);
memset(response,0x0,strlen(response));

for (i = 0 ; i < len ; i++) {
memcpy(data+strlen(data),"1",1);
clnt_call(client,1,(xdrproc_t) xdr_wrapstring ,(char *) &data,(xdrproc_t) xdr_wrapstring,(char *)  response,timeout);
}

clnt_call(client,4,(xdrproc_t) xdr_wrapstring ,(char *) &data,(xdrproc_t) xdr_wrapstring,(char *)  response,timeout);

clnt_destroy(client);
close(sock);
free(data);
free(response);
exit(0);
}
Beispiel #26
0
int
callaurpc(char *host, int prognum, int versnum, int procnum,
		xdrproc_t inproc, char *in, xdrproc_t outproc, char *out)
{
	static enum clnt_stat clnt_stat;
	struct timeval tottimeout;

	static CLIENT *cl = NULL;
	static int oldprognum, oldversnum;
	static char oldhost[MAXHOSTNAMELEN+1];

	/*
	 * Cache the client handle in case there are lots
	 * of entries in the /etc/mnttab for the same
	 * server. If the server returns an error, don't
	 * make further calls.
	 */
	if (cl == NULL || oldprognum != prognum || oldversnum != versnum ||
		strcmp(oldhost, host) != 0) {
		if (cl) {
			clnt_destroy(cl);
			cl = NULL;
		}
		cl = clnt_create(host, prognum, versnum, "udp");
		if (cl == NULL)
			return ((int)RPC_TIMEDOUT);
		if ((cl->cl_auth = authunix_create_default()) == NULL) {
			clnt_destroy(cl);
			return (RPC_CANTSEND);
		}
		oldprognum = prognum;
		oldversnum = versnum;
		(void) strcpy(oldhost, host);
		clnt_stat = RPC_SUCCESS;
	}

	if (clnt_stat != RPC_SUCCESS)
		return ((int)clnt_stat);	/* don't bother retrying */

	tottimeout.tv_sec  = 5;
	tottimeout.tv_usec = 0;
	clnt_stat = clnt_call(cl, procnum, inproc, in,
	    outproc, out, tottimeout);

	return ((int)clnt_stat);
}
Beispiel #27
0
void rpc_disconnect(void)
{
    int i;

    for (i = 0; i < skye_options.servercount; i++){
        clnt_destroy (rpc_clients[i]);
    }
}
void rpc_timeout_alarm_handler(int signo) {
    if (signo == SIGALRM) {
        if (client) {
            clnt_destroy(client);
        }
        critical("RPC timed out after %d seconds\n", mp_timeout);
    }
}
Beispiel #29
0
void *
sm_notify_1_svc(stat_chge *arg, struct svc_req *req)
{
  struct timeval timeout = { 20, 0 };	/* 20 secs timeout		*/
  CLIENT *cli;
  static char dummy; 
  sm_status tx_arg;		/* arg sent to callback procedure	*/
  MonList *lp;
  HostInfo *hp;
  pid_t pid;

  if (debug) syslog(LOG_DEBUG, "notify from host %s, new state %d",
    arg->mon_name, arg->state);

  hp = find_host(arg->mon_name, FALSE);
  if (!hp)
  {
    /* Never heard of this host - why is it notifying us?		*/
    syslog(LOG_ERR, "Unsolicited notification from host %s", arg->mon_name);
    return (&dummy);
  }
  lp = hp->monList;
  if (!lp) return (&dummy);	/* We know this host, but have no	*/
				/* outstanding requests.		*/
  pid = fork();
  if (pid == -1)
  {
    syslog(LOG_ERR, "Unable to fork notify process - %s", strerror(errno));
    return (NULL);
  }
  if (pid) return (&dummy);	/* Parent returns			*/

  while (lp)
  {
    tx_arg.mon_name = arg->mon_name;
    tx_arg.state = arg->state;
    memcpy(tx_arg.priv, lp->notifyData, sizeof(tx_arg.priv));
    cli = clnt_create(lp->notifyHost, lp->notifyProg, lp->notifyVers, "udp");
    if (!cli)
    {
      syslog(LOG_ERR, "Failed to contact host %s%s", lp->notifyHost,
        clnt_spcreateerror(""));
    }
    else
    {
      if (clnt_call(cli, lp->notifyProc, (xdrproc_t)xdr_sm_status, &tx_arg,
	  (xdrproc_t)xdr_void, &dummy, timeout) != RPC_SUCCESS)
      {
        syslog(LOG_ERR, "Failed to call rpc.statd client at host %s",
	  lp->notifyHost);
      }
      clnt_destroy(cli);
    }
    lp = lp->next;
  }

  exit (0);	/* Child quits	*/
}
void *my_thread_process(void *arg)
{
	int i;
	CLIENT *client = NULL;
	struct netconfig *nconf = NULL;
	struct netbuf svcaddr;
	char addrbuf[ADDRBUFSIZE];
	int var_snd = 0;
	int var_rec = -1;
	struct timeval tv;

	if (run_mode == 1) {
		fprintf(stderr, "Thread %d\n", atoi(arg));
	}

	tv.tv_sec = 0;
	tv.tv_usec = 100;

	nconf = getnetconfigent("udp");
	if (nconf == (struct netconfig *)NULL) {
		fprintf(stderr, "err nconf\n");
		printf("5\n");
		exit(1);
	}

	svcaddr.len = 0;
	svcaddr.maxlen = ADDRBUFSIZE;
	svcaddr.buf = addrbuf;

	if (svcaddr.buf == NULL) {
		printf("5\n");
		exit(5);
	}

	if (!rpcb_getaddr(progNum, VERSNUM, nconf, &svcaddr, hostname)) {
		fprintf(stderr, "rpcb_getaddr failed!!\n");
		printf("5\n");
		exit(5);
	}

	client = clnt_tli_create(RPC_ANYFD, nconf, &svcaddr,
				 progNum, VERSNUM, 0, 0);

	if (client == NULL) {
		printf("5\n");
		exit(5);
	}

	for (i = 0; i < callNb; i++) {
		clnt_call(client, PROCNUM,
			  (xdrproc_t) xdr_int, (char *)&var_snd,
			  (xdrproc_t) xdr_int, (char *)&var_rec, tv);
	}

	clnt_destroy(client);

	pthread_exit(0);
}