예제 #1
0
파일: tcpr-chat.c 프로젝트: tl268/tcpr
int main(int argc, char **argv)
{
	int opt;

	while ((opt = getopt(argc, argv, "b:c:a:f:s:?")) != -1)
		switch (opt) {
		case 'b':
			split_address(optarg, &bind_host, &bind_port);
			break;
		case 'c':
			split_address(optarg, &connect_host, &connect_port);
			break;
		case 'a':
			split_address(optarg, &application_host,
						&application_port);
			break;
		case 'f':
			split_address(optarg, &filter_host, &filter_port);
			break;
		case 's':
			state_file = optarg;
			break;
		default:
			fprintf(stderr, "Usage: %s [OPTIONS]\n", argv[0]);
			fprintf(stderr, "  -b HOST:[PORT]  "
				"Bind to the specified address.\n");
			fprintf(stderr, "  -c HOST:[PORT]  "
				"Connect to the specified address.\n");
			fprintf(stderr, "  -a HOST:[PORT]  "
				"Receive updates at the specified address.\n");
			fprintf(stderr, "  -f HOST:[PORT]  "
				"Send updates to the specified address.\n");
			fprintf(stderr, "  -s FILE         "
				"Keep persistent state in FILE.\n");
			fprintf(stderr, "  -?              "
				"Print this help message and exit.\n");
			exit(EXIT_FAILURE);
		}

	if (!connect_port && connect_host)
		connect_port = "8888";
	if (!bind_port && (bind_host || !connect_port))
		bind_port = "8888";

	if (filter_host || filter_port) {
		filtering = 1;
		if (!filter_port)
			filter_port = application_port
					? application_port : "7777";
		if (!application_port)
			application_port = filter_port;
		if (!application_host)
			application_host = bind_host;
		if (!state_file)
			state_file = "tcpr-application.dat";
		setup_state();
		setup_update_connection();
	}

	if (recovering)
		recover_connection();
	else
		setup_connection();

	finish();
	return EXIT_SUCCESS;
}
예제 #2
0
파일: tcpr-chat.c 프로젝트: psp26/tcpr
int main(int argc, char **argv)
{
	int opt;

	while ((opt = getopt(argc, argv, "b:c:a:f:s:p?")) != -1)
		switch (opt) {
		case 'b':
			split_address(optarg, &bind_host, &bind_port);
			break;
		case 'c':
			split_address(optarg, &connect_host, &connect_port);
			break;
		case 'a':
			application_path = optarg;
			break;
		case 'f':
			filter_path = optarg;
			break;
		case 's':
			state_file = optarg;
			break;
		case 'p':
			filtering = 0;
			break;
		default:
			fprintf(stderr, "Usage: %s [OPTIONS]\n", argv[0]);
			fprintf(stderr, "  -b HOST:[PORT]  "
				"Bind to HOST at PORT.\n");
			fprintf(stderr, "  -c HOST:[PORT]  "
				"Connect to HOST at PORT.\n");
			fprintf(stderr, "  -a PATH         "
				"Receive updates at the UNIX socket PATH.\n");
			fprintf(stderr, "  -f PATH         "
				"Send updates to the UNIX socket PATH.\n");
			fprintf(stderr, "  -s FILE         "
				"Keep persistent state in FILE.\n");
			fprintf(stderr, "  -p              "
				"Act as the peer; i.e. ignore TCPR.\n");
			fprintf(stderr, "  -?              "
				"Print this help message and exit.\n");
			exit(EXIT_FAILURE);
		}

	if (!connect_port && connect_host)
		connect_port = "8888";
	if (!bind_port && (bind_host || !connect_port))
		bind_port = "8888";

	if (filtering) {
		setup_state();
		setup_update_connection();
	}

	if (recovering)
		recover_connection();
	else
		setup_connection();

	finish();
	return EXIT_SUCCESS;
}