Beispiel #1
0
static int swan_ts_test_client_main(int argc, char *argv[])
{
	int i;
	u16 addr;

	for (i = 1; i < argc; i++)
	{
		addr = text2value_unsigned(argv[i], NULL, 10);

		swan_ts_test_client(NULL, addr);
	}

	return 0;
}
Beispiel #2
0
pid_t process_find_by_cmdline(const char *proc_path, const char *cmdline)
{
	DIR *dir_proc;
	pid_t pid;
	struct dirent *en;
	char pathname[64], *p_name;

	if (proc_path == NULL) {
		proc_path = "/proc";
	}

	dir_proc = opendir(proc_path);
	if (dir_proc == NULL) {
		pr_err_info("Open directroy %s failed", proc_path);
		return -EFAULT;
	}

	pid = -1;
	p_name = text_path_cat(pathname, sizeof(pathname), proc_path, NULL);

	while ((en = readdir(dir_proc))) {
		char buff[1024];
		ssize_t readlen;

		if (text_is_number(en->d_name) == 0) {
			continue;
		}

		sprintf(p_name, "%s/cmdline", en->d_name);

		readlen = file_read(pathname, buff, sizeof(buff));
		if (readlen < 0) {
			continue;
		}

		buff[readlen] = 0;

		if (text_lhcmp(cmdline, buff) == 0) {
			pid = text2value_unsigned(en->d_name, NULL, 10);
			break;
		}
	}

	closedir(dir_proc);

	return pid;
}
Beispiel #3
0
static int test_discovery_service_main(int argc, char *argv[])
{
	int ret;
	struct udp_discovery_service service;

	assert(argc > 1);

	if (argc > 2) {
		service.port = text2value_unsigned(argv[2], NULL, 10);
	} else {
		service.port = 8888;
	}

	ret = udp_discovery_service_start(&service, argv[1]);
	if (ret < 0) {
		pr_red_info("udp_discovery_service_start: %d", ret);
		return ret;
	}

	cavan_thread_join(&service.thread);

	return 0;
}
Beispiel #4
0
static int swan_ts_write_data_main(int argc, char *argv[])
{
	int i;
	int ret;
	char *buff;
	u16 count;

	assert(argc > 1);

	count = argc - 1;

	buff = malloc(count);

	for (i = 0; i < count; i++)
	{
		buff[i] = text2value_unsigned(argv[i + 1], NULL, 10);
	}

	println("count = %d", count);
	println("The data is:");
	print_mem((u8 *) buff, count);

	ret = swan_ts_write_data(NULL, buff, count);
	if (ret < 0)
	{
		pr_red_info("Failed");
	}
	else
	{
		pr_green_info("OK");
	}

	free(buff);

	return ret;
}
Beispiel #5
0
int ftp_client_read_response(struct network_client *client, char *response, size_t size)
{
	int state;
	ssize_t rwlen;
	char buff[2048], *p = buff, *p_end = p + sizeof(buff);

	while (p < p_end)
	{
		char *q;

		rwlen = network_client_timed_recv(client, p, p_end - p, 5000);
		if (rwlen <= 0)
		{
			return -EFAULT;
		}

		for (q = p, p += rwlen; q < p; q++)
		{
			int step = 0;

			while (q < p && IS_NUMBER(*q))
			{
				q++;
			}

			if (q < p && *q != '-')
			{
				step++;
			}

			while (q < p)
			{
				if (*q == '\n')
				{
					step++;
					break;
				}

				q++;
			}

			if (step == 2)
			{
				goto label_read_complete;
			}
		}
	}

label_read_complete:
	*p = 0;
#if FTP_DEBUG
	print_ntext(buff, p - buff);
#endif
	state = text2value_unsigned(buff, (const char **) &p, 10);

	if (response && size > 0)
	{
		text_ncopy(response, p + 1, size);
	}

	return state;
}