Exemplo n.º 1
0
void quit (void)
{
    LOG("%s", __FUNCTION__);

    console_fini();
    ttf_fini();
    sdl_fini();
    config_fini();
}
Exemplo n.º 2
0
int main(int argc, char **argv) {
	int c = 0;	
	int console = 0;
	int port = 0, uport = 0, ka_time = 0, persistent = 0;
	char *addrstr = NULL, *viface = NULL, *dev = NULL;

	while((c = getopt(argc, argv, "u:p:a:n:k:i:bcvP"))!= -1) {
		switch (c) {
		case 'u':
			uport = atoi(optarg);
			break;
		case 'p':
			port = atoi(optarg);
			break;
		case 'v':
			verbose = 1;
			break;
		case 'c':
			console = 1;
			break;
		case 'a':
			addrstr = optarg;
			break;
		case 'i':
			dev = optarg;
			break;
		case 'n':
			viface = optarg;
			break;
		case 'k':
			ka_time = atoi(optarg);
			break;
		case 'b':
			background = 1;
			break;
		case 'P':
			persistent = 1;
			break;
		default:
			usage();
			exit(-1);
		}
	}
	if (!(port) || !(addrstr)) {
		printf("Error: both -a <address> and -p <port> must be specified\n");
		usage();
	}

	if (!uport)
		uport = DEFAULT_UDP_PORT;
	
	if (!ka_time)
		ka_time = DEFAULT_KEEPALIVE_TIMEOUT;	

	if (!viface)
		viface = DEFAULT_VIFACE_NAME;

	if ((!console) && (!dev)) {
		printf("Error: either -c or -i <dev> must be specified. If console mode is not used," 
				"the name of the outgoing tunnel interface must be specified\n");
		usage();
	}

	/*Initialization*/
	if (background) {
		if (log_init() < 0) {
			printf("error: log_init failed\n");
			exit(-1);
		}
	}

	memset(&c_data, 0, sizeof(struct client_data));

	/*TCP server addr*/
  	c_data.tcp_server.sin_family = AF_INET;
  	c_data.tcp_server.sin_port = htons(port);
  	if (inet_pton(AF_INET, addrstr, &c_data.tcp_server.sin_addr)<0) {
		printf("bad server ip address");
		exit(-1);
	}

	/*UDP server addr*/
	c_data.udp_server.sin_family = AF_INET;
  	c_data.udp_server.sin_port = htons(uport);
  	inet_pton(AF_INET, addrstr, &c_data.udp_server.sin_addr);

	if (client_init() < 0) {
		print_log("client_init() error", LOG_LEVEL_IMPORTANT);
		goto quit;
	}

	if (ipudp_conf_init() < 0) {
		print_log("ipudp_conf_init() error", LOG_LEVEL_IMPORTANT);
		goto quit;
	}

	if (sock_init_connect() < 0)
		goto quit;

	if ((ssl_init() < 0))
		goto quit;
	
	if (console) {
		if (console_ini() < 0) {
			console = 0;
			goto quit;
		}
	}
	/**/

	signal(SIGINT, sighand);
    signal(SIGTERM, sighand);
    signal(SIGKILL, sighand);

	if (console)
		do_select(0, ka_time);
	else {
		if (client_association(dev, viface) < 0) 
			goto quit;
		if (background) {
			if (daemonize() < 0) {
				printf("Error: couldn't demonize. Exit\n");
				goto quit;
			}
		}
		client_keepalive_cycle(persistent, ka_time);
	}

quit:
    client_fini();
	if (console)
		console_fini();

	return 0;
}