コード例 #1
0
ファイル: local.c プロジェクト: baiyunping333/socks5_c
int main(int argc, char **argv)
{
	struct ss_server_ctx *lo_s;
	struct io_event s_event;
	struct io_event c_event;
	struct encry_key_s *key = NULL;
	size_t key_len;
	int opt;

	while ((opt = getopt(argc, argv, "l:p:s:e:h?")) != -1) {
		switch (opt) {
		case 'l':
			remote_ip = optarg;
			break;
		case 'p':
			remote_port = atoi(optarg);
			break;
		case 's':
			listen_port = atoi(optarg);
			break;
		case 'e':
			key_len = strlen(optarg);
			key = malloc(sizeof(*key) + key_len);
			key->len = key_len;
			memcpy(key->key, optarg, key_len);
			break;
		default:
			fprintf(stderr,
				"usage: %s [-l remote_ip] "
				"[-p remote_port] [-s listen_port] [-e key]\n",
				argv[0]);
			exit(1);
		}
	}
	lo_s = ss_create_server(listen_port, key);
	if (lo_s == NULL)
		DIE("ss_create_server failed!");
	memset(&s_event, 0, sizeof(s_event));
	s_event.rfileproc = ss_accept_handle;
	memset(&c_event, 0, sizeof(c_event));
	c_event.rfileproc = ss_io_handle;
	s_event.para = malloc(sizeof(c_event));
	memcpy(s_event.para, &c_event, sizeof(c_event));
	memcpy(&lo_s->io_proc, &s_event, sizeof(s_event));
	ss_loop(lo_s);
	ss_release_server(lo_s);
	return 0;
}
コード例 #2
0
ファイル: server.c プロジェクト: current1990/socks5_c
int main(int argc, char **argv)
{
	struct ss_server_ctx *ss_s;
	enum ss_encrypt_method encry_method = NO_ENCRYPT;
	struct encry_key_s *key = NULL;
	size_t key_len;
	int opt;

	while ((opt = getopt(argc, argv, "p:m:e:h?")) != -1) {
		switch (opt) {
		case 'p':
			server_port = atoi(optarg);
			break;
		case 'm':
			if (!strcmp("xor", optarg))
				encry_method = XOR_METHOD;
			else if (!strcmp("rc4", optarg))
				encry_method = RC4_METHOD;
			break;
		case 'e':
			key_len = strlen(optarg);
			key = malloc(sizeof(*key) + key_len);
			key->len = key_len;
			memcpy(key->key, optarg, key_len);
			break;
		default:
			fprintf(stderr,
				"usage: %s [-p server_port] [-m xor|rc4] "
				"[-e key]\n",
				argv[0]);
			exit(1);
		}
	}
	ss_s = ss_create_server(server_port, encry_method, key);
	if (ss_s == NULL)
		DIE("ss_create_server failed!");
	ss_server_set_handle(ss_s, AE_READABLE, ss_accept_handle, NULL, NULL);
	ss_loop(ss_s);
	ss_release_server(ss_s);
	return 0;
}