Ejemplo n.º 1
0
/*=============================================================================
FUNCTION:		c_rpc_qcsapi_init
DESCRIPTION:		Connect the RPC server. Try 15 times every 5 sec.
ARGUMENTS PASSED:
RETURN VALUE:		0:success, other:error
=============================================================================*/
int c_rpc_qcsapi_init()
{
	const char *host;
	CLIENT *clnt;
	int retry = 0;
	/* setup RPC based on udp protocol */
	do {
		host = client_qcsapi_find_host_addr(0, NULL);
		if (!host) {
			printf("Cannot find the host\n");
			continue;
		}

		if (!s_c_rpc_use_udp) {
			clnt = clnt_create(host, QCSAPI_PROG, QCSAPI_VERS, "tcp");
		} else {
			clnt = clnt_create(host, QCSAPI_PROG, QCSAPI_VERS, "udp");
		}
		if (clnt == NULL) {
			clnt_pcreateerror(host);
			continue;
		} else {
			client_qcsapi_set_rpcclient(clnt);
			return 0;
		}
		sleep(5);
	} while (retry++ < MAX_RETRY_TIMES);
	return -1;
}
int main(int argc, char **argv)
{
	CLIENT *clnt;
	struct qcsapi_output output;
	uint8_t dst_mac[ETH_HLEN];
	int ret;

	if (geteuid()) {
		printf("QRPC: only root can do that\n");
		exit(1);
	}

	if (argc < 3) {
		printf("QRPC: <src_ifname> <dst_mac_addr>\n");
		exit(1);
	}

	if (str_to_mac(argv[2], dst_mac) < 0) {
		printf("QRPC: Wrong destination MAC address format. "
				"Use the following format: XX:XX:XX:XX:XX:XX\n");
		exit(1);
	}

	output = qcsapi_output_stdio_adapter();

	clnt = qrpc_clnt_raw_create(QCSAPI_PROG, QCSAPI_VERS, argv[1], dst_mac, QRPC_QCSAPI_RPCD_SID);
	if (clnt == NULL) {
		clnt_pcreateerror("QRPC: ");
		exit (1);
	}

	client_qcsapi_set_rpcclient(clnt);
	argv[2] = argv[0];
	ret = qcsapi_main(&output, argc - 2, &argv[2]);
	clnt_destroy(clnt);

	if (!ret && !strcmp(argv[3], "send_file")) {
		if (qftc_start(argv[4], argv[1], dst_mac) < 0) {
			printf("send_file command failed\n");
		} else {
			printf("complete\n");
		}
	}

	return ret;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
	int ret;
	const char *host;
	int udp_retry_timeout;
	CLIENT *clnt;
	struct qcsapi_output output;

	output = qcsapi_output_stdio_adapter();

	host = client_qcsapi_find_host_addr(&argc, &argv);
	if (!host) {
		client_qcsapi_find_host_errmsg(argv[0]);
		exit(1);
	}

	udp_retry_timeout = client_qcsapi_get_udp_retry_timeout(&argc, &argv);

	clnt = clnt_create(host, QCSAPI_PROG, QCSAPI_VERS, "udp");
	if (clnt == NULL) {
		clnt = clnt_create(host, QCSAPI_PROG, QCSAPI_VERS, "tcp");
	} else {
		if (udp_retry_timeout>0) {
			struct timeval value;
			value.tv_sec = (time_t)udp_retry_timeout;
			value.tv_usec = (suseconds_t)0;
			clnt_control(clnt, CLSET_RETRY_TIMEOUT, (char *)&value);
		}
	}

	if (clnt == NULL) {
		clnt_pcreateerror(host);
		exit(1);
	}

	client_qcsapi_set_rpcclient(clnt);

	ret = qcsapi_main(&output, argc, argv);

	clnt_destroy(clnt);

	return ret;
}