summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2020-08-20 06:42:18 -0400
committerAndrew Cady <d@jerkface.net>2020-08-20 16:29:56 -0400
commit5d1bce667f97244718bbeaff42bade637782c6ba (patch)
treea5d5d2915127bf173a03c5ac34b5bdce930a89f4
parentde62d93767d02a6c4768936670b668eca5f3fafe (diff)
whitespace fixes
-rw-r--r--client.c74
-rw-r--r--main.c124
-rw-r--r--util.c12
3 files changed, 105 insertions, 105 deletions
diff --git a/client.c b/client.c
index 3073e5d..1e02286 100644
--- a/client.c
+++ b/client.c
@@ -310,12 +310,12 @@ int do_client_loop(uint8_t *tox_id_str)
310 310
311 while(1) 311 while(1)
312 { 312 {
313 /* Let tox do its stuff */ 313 /* Let tox do its stuff */
314 tox_iterate(tox, NULL); 314 tox_iterate(tox, NULL);
315 315
316 switch(state) 316 switch(state)
317 { 317 {
318 /* 318 /*
319 * Send friend request 319 * Send friend request
320 */ 320 */
321 case CLIENT_STATE_INITIAL: 321 case CLIENT_STATE_INITIAL:
@@ -501,7 +501,7 @@ int do_client_loop(uint8_t *tox_id_str)
501 tv.tv_sec = 0; 501 tv.tv_sec = 0;
502 tv.tv_usec = 20000; 502 tv.tv_usec = 20000;
503 fds = client_master_fdset; 503 fds = client_master_fdset;
504 504
505 /* Handle accepting new connections */ 505 /* Handle accepting new connections */
506 if(!client_pipe_mode && 506 if(!client_pipe_mode &&
507 client_tunnel.sockfd <= 0) /* Don't accept if we're already waiting to establish a tunnel */ 507 client_tunnel.sockfd <= 0) /* Don't accept if we're already waiting to establish a tunnel */
@@ -628,39 +628,39 @@ int do_client_loop(uint8_t *tox_id_str)
628 } 628 }
629 } 629 }
630 break; 630 break;
631 case CLIENT_STATE_CONNECTION_LOST: 631 case CLIENT_STATE_CONNECTION_LOST:
632 { 632 {
633 TOX_CONNECTION friend_connection_status; 633 TOX_CONNECTION friend_connection_status;
634 friend_connection_status = tox_friend_get_connection_status(tox, friendnumber, &friend_query_error); 634 friend_connection_status = tox_friend_get_connection_status(tox, friendnumber, &friend_query_error);
635 if(friend_query_error != TOX_ERR_FRIEND_QUERY_OK) 635 if(friend_query_error != TOX_ERR_FRIEND_QUERY_OK)
636 { 636 {
637 log_printf(L_DEBUG, "tox_friend_get_connection_status: error %u\n", friend_query_error); 637 log_printf(L_DEBUG, "tox_friend_get_connection_status: error %u\n", friend_query_error);
638 } 638 }
639 else 639 else
640 { 640 {
641 if(friend_connection_status == TOX_CONNECTION_NONE) 641 if(friend_connection_status == TOX_CONNECTION_NONE)
642 { 642 {
643 /* https://github.com/TokTok/c-toxcore/blob/acb6b2d8543c8f2ea0c2e60dc046767cf5cc0de8/toxcore/tox.h#L1267 */ 643 /* https://github.com/TokTok/c-toxcore/blob/acb6b2d8543c8f2ea0c2e60dc046767cf5cc0de8/toxcore/tox.h#L1267 */
644 TOX_ERR_FRIEND_DELETE tox_delete_error; 644 TOX_ERR_FRIEND_DELETE tox_delete_error;
645 645
646 log_printf(L_WARNING, "Lost connection to server, closing all tunnels and re-adding friend\n"); 646 log_printf(L_WARNING, "Lost connection to server, closing all tunnels and re-adding friend\n");
647 client_close_all_connections(); 647 client_close_all_connections();
648 tox_friend_delete(tox, friendnumber, &tox_delete_error); 648 tox_friend_delete(tox, friendnumber, &tox_delete_error);
649 if(tox_delete_error) 649 if(tox_delete_error)
650 { 650 {
651 log_printf(L_ERROR, "Error when deleting server from friend list: %d\n", tox_delete_error); 651 log_printf(L_ERROR, "Error when deleting server from friend list: %d\n", tox_delete_error);
652 } 652 }
653 state = CLIENT_STATE_INITIAL; 653 state = CLIENT_STATE_INITIAL;
654 } 654 }
655 else 655 else
656 { 656 {
657 state = CLIENT_STATE_FORWARDING; 657 state = CLIENT_STATE_FORWARDING;
658 } 658 }
659 } 659 }
660 } 660 }
661 break; 661 break;
662 case 0xffffffff: 662 case 0xffffffff:
663 log_printf(L_ERROR, "You forgot a break statement\n"); 663 log_printf(L_ERROR, "You forgot a break statement\n");
664 case CLIENT_STATE_SHUTDOWN: 664 case CLIENT_STATE_SHUTDOWN:
665 exit(0); 665 exit(0);
666 break; 666 break;
diff --git a/main.c b/main.c
index f9153c7..d3bd3a8 100644
--- a/main.c
+++ b/main.c
@@ -161,7 +161,7 @@ void tunnel_delete(tunnel *t)
161 free(t); 161 free(t);
162} 162}
163 163
164int tunnel_in_delete_queue(tunnel *t) 164int tunnel_in_delete_queue(tunnel *t)
165{ 165{
166 tunnel_list *element; 166 tunnel_list *element;
167 167
@@ -232,7 +232,7 @@ void set_tox_username(Tox *tox)
232/* Get sockaddr, IPv4 or IPv6 */ 232/* Get sockaddr, IPv4 or IPv6 */
233void *get_in_addr(struct sockaddr *sa) 233void *get_in_addr(struct sockaddr *sa)
234{ 234{
235 if (sa->sa_family == AF_INET) 235 if (sa->sa_family == AF_INET)
236 { 236 {
237 return &(((struct sockaddr_in*)sa)->sin_addr); 237 return &(((struct sockaddr_in*)sa)->sin_addr);
238 } 238 }
@@ -254,7 +254,7 @@ int get_client_socket(char *hostname, int port)
254 hints.ai_family = AF_INET; 254 hints.ai_family = AF_INET;
255 hints.ai_socktype = SOCK_STREAM; 255 hints.ai_socktype = SOCK_STREAM;
256 256
257 if ((rv = getaddrinfo(hostname, port_str, &hints, &servinfo)) != 0) 257 if ((rv = getaddrinfo(hostname, port_str, &hints, &servinfo)) != 0)
258 { 258 {
259 /* Add a special case for "localhost" when name resolution is broken */ 259 /* Add a special case for "localhost" when name resolution is broken */
260 if(!strncmp("localhost", hostname, 256)) 260 if(!strncmp("localhost", hostname, 256))
@@ -273,7 +273,7 @@ int get_client_socket(char *hostname, int port)
273 } 273 }
274 274
275 // loop through all the results and connect to the first we can 275 // loop through all the results and connect to the first we can
276 for(p = servinfo; p != NULL; p = p->ai_next) 276 for(p = servinfo; p != NULL; p = p->ai_next)
277 { 277 {
278 if (p->ai_family != AF_INET && p->ai_family != AF_INET6) 278 if (p->ai_family != AF_INET && p->ai_family != AF_INET6)
279 continue; 279 continue;
@@ -311,8 +311,8 @@ int get_client_socket(char *hostname, int port)
311 311
312/* Proto - our protocol handling */ 312/* Proto - our protocol handling */
313 313
314/* 314/*
315 * send_frame: (almost) zero-copy. Overwrites first PROTOCOL_BUFFER_OFFSET bytes of data 315 * send_frame: (almost) zero-copy. Overwrites first PROTOCOL_BUFFER_OFFSET bytes of data
316 * so actual data should start at position PROTOCOL_BUFFER_OFFSET 316 * so actual data should start at position PROTOCOL_BUFFER_OFFSET
317 */ 317 */
318int send_frame(protocol_frame *frame, uint8_t *data) 318int send_frame(protocol_frame *frame, uint8_t *data)
@@ -414,7 +414,7 @@ int handle_ping_frame(protocol_frame *rcvd_frame)
414 frame->friendnumber = rcvd_frame->friendnumber; 414 frame->friendnumber = rcvd_frame->friendnumber;
415 frame->packet_type = PACKET_TYPE_PONG; 415 frame->packet_type = PACKET_TYPE_PONG;
416 frame->data_length = rcvd_frame->data_length; 416 frame->data_length = rcvd_frame->data_length;
417 417
418 send_frame(frame, data); 418 send_frame(frame, data);
419 419
420 return 0; 420 return 0;
@@ -433,7 +433,7 @@ int handle_request_tunnel_frame(protocol_frame *rcvd_frame)
433 log_printf(L_WARNING, "Got tunnel request frame from friend #%d when in client mode\n", rcvd_frame->friendnumber); 433 log_printf(L_WARNING, "Got tunnel request frame from friend #%d when in client mode\n", rcvd_frame->friendnumber);
434 return -1; 434 return -1;
435 } 435 }
436 436
437 port = rcvd_frame->connid; 437 port = rcvd_frame->connid;
438 hostname = calloc(1, rcvd_frame->data_length + 1); 438 hostname = calloc(1, rcvd_frame->data_length + 1);
439 if(!hostname) 439 if(!hostname)
@@ -446,14 +446,14 @@ int handle_request_tunnel_frame(protocol_frame *rcvd_frame)
446 hostname[rcvd_frame->data_length] = '\0'; 446 hostname[rcvd_frame->data_length] = '\0';
447 447
448 log_printf(L_INFO, "Got a request to forward data from %s:%d\n", hostname, port); 448 log_printf(L_INFO, "Got a request to forward data from %s:%d\n", hostname, port);
449 449
450 // check rules 450 // check rules
451 if (rules_policy == VALIDATE && nrules > 0 ) { 451 if (rules_policy == VALIDATE && nrules > 0 ) {
452 452
453 rule temp_rule, *found = NULL; 453 rule temp_rule, *found = NULL;
454 temp_rule.host = hostname; 454 temp_rule.host = hostname;
455 temp_rule.port = port; 455 temp_rule.port = port;
456 456
457 LL_SEARCH(rules, found, &temp_rule, rule_cmp); 457 LL_SEARCH(rules, found, &temp_rule, rule_cmp);
458 if(!found) 458 if(!found)
459 { 459 {
@@ -532,7 +532,7 @@ int handle_client_tcp_frame(protocol_frame *rcvd_frame)
532 int sent_bytes; 532 int sent_bytes;
533 533
534 sent_bytes = send( 534 sent_bytes = send(
535 tun->sockfd, 535 tun->sockfd,
536 rcvd_frame->data + offset, 536 rcvd_frame->data + offset,
537 rcvd_frame->data_length - offset, 537 rcvd_frame->data_length - offset,
538 MSG_NOSIGNAL 538 MSG_NOSIGNAL
@@ -569,7 +569,7 @@ int handle_client_tcp_fin_frame(protocol_frame *rcvd_frame)
569 log_printf(L_WARNING, "Friend #%d tried to close tunnel which belongs to #%d\n", rcvd_frame->friendnumber, tun->friendnumber); 569 log_printf(L_WARNING, "Friend #%d tried to close tunnel which belongs to #%d\n", rcvd_frame->friendnumber, tun->friendnumber);
570 return -1; 570 return -1;
571 } 571 }
572 572
573 log_printf(L_DEBUG2, "Deleting tunnel #%d (%p) in handle_client_tcp_fin_frame(), socket %d", rcvd_frame->connid, tun, tun->sockfd); 573 log_printf(L_DEBUG2, "Deleting tunnel #%d (%p) in handle_client_tcp_fin_frame(), socket %d", rcvd_frame->connid, tun, tun->sockfd);
574 tunnel_queue_delete(tun); 574 tunnel_queue_delete(tun);
575 575
@@ -614,7 +614,7 @@ int handle_frame(protocol_frame *frame)
614 } 614 }
615 break; 615 break;
616 default: 616 default:
617 log_printf(L_DEBUG, "Got unknown packet type 0x%x from friend %d\n", 617 log_printf(L_DEBUG, "Got unknown packet type 0x%x from friend %d\n",
618 frame->packet_type, 618 frame->packet_type,
619 frame->friendnumber 619 frame->friendnumber
620 ); 620 );
@@ -623,7 +623,7 @@ int handle_frame(protocol_frame *frame)
623 return 0; 623 return 0;
624} 624}
625 625
626/* 626/*
627 * This is a callback which gets a packet from Tox core. 627 * This is a callback which gets a packet from Tox core.
628 * It checks for basic inconsistiencies and allocates the 628 * It checks for basic inconsistiencies and allocates the
629 * protocol_frame structure. 629 * protocol_frame structure.
@@ -800,12 +800,12 @@ void load_rules()
800 int valid_rules = 0; 800 int valid_rules = 0;
801 801
802 file = fopen(rules_file, "r"); 802 file = fopen(rules_file, "r");
803 803
804 if (file == NULL) { 804 if (file == NULL) {
805 log_printf(L_WARNING, "Could not open rules file (%s)\n", rules_file); 805 log_printf(L_WARNING, "Could not open rules file (%s)\n", rules_file);
806 return; 806 return;
807 } 807 }
808 808
809 while (fgets(line, sizeof(line), file)) { 809 while (fgets(line, sizeof(line), file)) {
810 /* allow comments & white lines */ 810 /* allow comments & white lines */
811 if (line[0]=='#'||line[0]=='\n') { 811 if (line[0]=='#'||line[0]=='\n') {
@@ -834,10 +834,10 @@ void load_rules()
834 } 834 }
835 } 835 }
836 fclose(file); 836 fclose(file);
837 837
838 /* save valid rules in global variable */ 838 /* save valid rules in global variable */
839 nrules = valid_rules; 839 nrules = valid_rules;
840 840
841 log_printf(L_INFO, "Loaded %d rules\n", nrules); 841 log_printf(L_INFO, "Loaded %d rules\n", nrules);
842 if (nrules==0 && rules_policy != NONE){ 842 if (nrules==0 && rules_policy != NONE){
843 log_printf(L_WARNING, "No rules loaded! NO CONNECTIONS WILL BE ALLOWED!\n"); 843 log_printf(L_WARNING, "No rules loaded! NO CONNECTIONS WILL BE ALLOWED!\n");
@@ -884,7 +884,7 @@ void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *m
884 return; 884 return;
885 } 885 }
886 } 886 }
887 887
888 memset(tox_printable_id, '\0', sizeof(tox_printable_id)); 888 memset(tox_printable_id, '\0', sizeof(tox_printable_id));
889 id_to_string(tox_printable_id, public_key); 889 id_to_string(tox_printable_id, public_key);
890 890
@@ -927,7 +927,7 @@ void cleanup()
927 tox_kill(tox); 927 tox_kill(tox);
928 if(client_socket) 928 if(client_socket)
929 { 929 {
930 close(client_socket); 930 close(client_socket);
931 } 931 }
932 log_close(); 932 log_close();
933} 933}
@@ -1009,8 +1009,8 @@ int do_server_loop()
1009 log_printf(L_DEBUG, "Current tunnel: %p", tun); 1009 log_printf(L_DEBUG, "Current tunnel: %p", tun);
1010 if(FD_ISSET(tun->sockfd, &fds)) 1010 if(FD_ISSET(tun->sockfd, &fds))
1011 { 1011 {
1012 int nbytes = recv(tun->sockfd, 1012 int nbytes = recv(tun->sockfd,
1013 tox_packet_buf+PROTOCOL_BUFFER_OFFSET, 1013 tox_packet_buf+PROTOCOL_BUFFER_OFFSET,
1014 READ_BUFFER_SIZE, 0); 1014 READ_BUFFER_SIZE, 0);
1015 1015
1016 /* Check if connection closed */ 1016 /* Check if connection closed */
@@ -1039,7 +1039,7 @@ int do_server_loop()
1039 sent_data = 1; 1039 sent_data = 1;
1040 1040
1041 tunnel_queue_delete(tun); 1041 tunnel_queue_delete(tun);
1042 1042
1043 continue; 1043 continue;
1044 } 1044 }
1045 else 1045 else
@@ -1070,7 +1070,7 @@ int do_server_loop()
1070 gettimeofday(&tv_end, NULL); 1070 gettimeofday(&tv_end, NULL);
1071 ms_start = 1000 * tv_start.tv_sec + tv_start.tv_usec/1000; 1071 ms_start = 1000 * tv_start.tv_sec + tv_start.tv_usec/1000;
1072 ms_end = 1000 * tv_end.tv_sec + tv_end.tv_usec/1000; 1072 ms_end = 1000 * tv_end.tv_sec + tv_end.tv_usec/1000;
1073 1073
1074 if(!sent_data && (ms_end - ms_start < tox_do_interval_ms)) 1074 if(!sent_data && (ms_end - ms_start < tox_do_interval_ms))
1075 { 1075 {
1076 /*log_printf(L_DEBUG, "Sleeping for %d ms extra to prevent high CPU usage\n", (tox_do_interval_ms - (ms_end - ms_start)));*/ 1076 /*log_printf(L_DEBUG, "Sleeping for %d ms extra to prevent high CPU usage\n", (tox_do_interval_ms - (ms_end - ms_start)));*/
@@ -1089,7 +1089,7 @@ static void child_handler(int signum)
1089 } 1089 }
1090} 1090}
1091 1091
1092/* 1092/*
1093 * Daemonize the process if -D is set 1093 * Daemonize the process if -D is set
1094 * Optionally drop privileges and create a lock file 1094 * Optionally drop privileges and create a lock file
1095 */ 1095 */
@@ -1099,17 +1099,17 @@ void do_daemonize()
1099 FILE *pidf = NULL; 1099 FILE *pidf = NULL;
1100 1100
1101 /* already a daemon */ 1101 /* already a daemon */
1102 if (getppid() == 1) 1102 if (getppid() == 1)
1103 { 1103 {
1104 return; 1104 return;
1105 } 1105 }
1106 1106
1107 /* Drop user if there is one, and we were run as root */ 1107 /* Drop user if there is one, and we were run as root */
1108 if (daemon_username && (getuid() == 0 || geteuid() == 0)) 1108 if (daemon_username && (getuid() == 0 || geteuid() == 0))
1109 { 1109 {
1110 struct passwd *pw = getpwnam(daemon_username); 1110 struct passwd *pw = getpwnam(daemon_username);
1111 1111
1112 if(pw) 1112 if(pw)
1113 { 1113 {
1114 log_printf(L_DEBUG, "Setuid to user %s", daemon_username); 1114 log_printf(L_DEBUG, "Setuid to user %s", daemon_username);
1115 setuid(pw->pw_uid); 1115 setuid(pw->pw_uid);
@@ -1139,14 +1139,14 @@ void do_daemonize()
1139 1139
1140 /* Fork off the parent process */ 1140 /* Fork off the parent process */
1141 pid = fork(); 1141 pid = fork();
1142 if (pid < 0) 1142 if (pid < 0)
1143 { 1143 {
1144 log_printf(L_ERROR, "Unable to fork daemon, code=%d (%s)", 1144 log_printf(L_ERROR, "Unable to fork daemon, code=%d (%s)",
1145 errno, strerror(errno)); 1145 errno, strerror(errno));
1146 exit(1); 1146 exit(1);
1147 } 1147 }
1148 /* If we got a good PID, then we can exit the parent process. */ 1148 /* If we got a good PID, then we can exit the parent process. */
1149 if (pid > 0) 1149 if (pid > 0)
1150 { 1150 {
1151 /* Wait for confirmation from the child via SIGTERM or SIGCHLD, or 1151 /* Wait for confirmation from the child via SIGTERM or SIGCHLD, or
1152 for two seconds to elapse (SIGALRM). pause() should not return. */ 1152 for two seconds to elapse (SIGALRM). pause() should not return. */
@@ -1175,7 +1175,7 @@ void do_daemonize()
1175 1175
1176 /* Create a new SID for the child process */ 1176 /* Create a new SID for the child process */
1177 sid = setsid(); 1177 sid = setsid();
1178 if (sid < 0) 1178 if (sid < 0)
1179 { 1179 {
1180 log_printf(L_ERROR, "unable to create a new session, code %d (%s)", 1180 log_printf(L_ERROR, "unable to create a new session, code %d (%s)",
1181 errno, strerror(errno)); 1181 errno, strerror(errno));
@@ -1184,7 +1184,7 @@ void do_daemonize()
1184 1184
1185 /* Change the current working directory. This prevents the current 1185 /* Change the current working directory. This prevents the current
1186 directory from being locked; hence not being able to remove it. */ 1186 directory from being locked; hence not being able to remove it. */
1187 if ((chdir("/")) < 0) 1187 if ((chdir("/")) < 0)
1188 { 1188 {
1189 log_printf(L_ERROR, "Unable to change directory to %s, code %d (%s)", 1189 log_printf(L_ERROR, "Unable to change directory to %s, code %d (%s)",
1190 "/", errno, strerror(errno) ); 1190 "/", errno, strerror(errno) );
@@ -1197,10 +1197,10 @@ void do_daemonize()
1197 freopen( "/dev/null", "w", stderr); 1197 freopen( "/dev/null", "w", stderr);
1198 1198
1199 /* Create the pid file as the new user */ 1199 /* Create the pid file as the new user */
1200 if (pidfile && pidfile[0]) 1200 if (pidfile && pidfile[0])
1201 { 1201 {
1202 pidf = fopen(pidfile, "w"); 1202 pidf = fopen(pidfile, "w");
1203 if (!pidf) 1203 if (!pidf)
1204 { 1204 {
1205 log_printf(L_ERROR, "Unable to create PID file %s, code=%d (%s)", 1205 log_printf(L_ERROR, "Unable to create PID file %s, code=%d (%s)",
1206 pidfile, errno, strerror(errno)); 1206 pidfile, errno, strerror(errno));
@@ -1212,7 +1212,7 @@ void do_daemonize()
1212 1212
1213 1213
1214 /* Tell the parent process that we are A-okay */ 1214 /* Tell the parent process that we are A-okay */
1215 kill( parent, SIGUSR1 ); 1215 kill( parent, SIGUSR1 );
1216} 1216}
1217 1217
1218void help() 1218void help()
@@ -1239,8 +1239,8 @@ void help()
1239 fprintf(stderr, " mode\n"); 1239 fprintf(stderr, " mode\n");
1240 fprintf(stderr, " -s <secret> - shared secret used for connection authentication (max\n"); 1240 fprintf(stderr, " -s <secret> - shared secret used for connection authentication (max\n");
1241 fprintf(stderr, " %u characters)\n", TOX_MAX_FRIEND_REQUEST_LENGTH-1); 1241 fprintf(stderr, " %u characters)\n", TOX_MAX_FRIEND_REQUEST_LENGTH-1);
1242 fprintf(stderr, " -t <port> - set TCP relay port (0 disables TCP relaying)\n"); 1242 fprintf(stderr, " -t <port> - set TCP relay port (0 disables TCP relaying)\n");
1243 fprintf(stderr, " -u <port>:<port> - set Tox UDP port range\n"); 1243 fprintf(stderr, " -u <port>:<port> - set Tox UDP port range\n");
1244 fprintf(stderr, " -d - debug mode (use twice to display toxcore log too)\n"); 1244 fprintf(stderr, " -d - debug mode (use twice to display toxcore log too)\n");
1245 fprintf(stderr, " -q - quiet mode\n"); 1245 fprintf(stderr, " -q - quiet mode\n");
1246 fprintf(stderr, " -S - send output to syslog instead of stderr\n"); 1246 fprintf(stderr, " -S - send output to syslog instead of stderr\n");
@@ -1260,11 +1260,11 @@ int main(int argc, char *argv[])
1260 size_t save_size = 0; 1260 size_t save_size = 0;
1261 uint8_t *save_data = NULL; 1261 uint8_t *save_data = NULL;
1262 allowed_toxid *allowed_toxid_obj = NULL; 1262 allowed_toxid *allowed_toxid_obj = NULL;
1263 1263
1264 srand(time(NULL)); 1264 srand(time(NULL));
1265 tcp_relay_port = 1024 + (rand() % 64511); 1265 tcp_relay_port = 1024 + (rand() % 64511);
1266 udp_start_port = 1024 + (rand() % 64500); 1266 udp_start_port = 1024 + (rand() % 64500);
1267 udp_end_port = udp_start_port + 10; 1267 udp_end_port = udp_start_port + 10;
1268 1268
1269 log_init(); 1269 log_init();
1270 1270
@@ -1334,7 +1334,7 @@ int main(int argc, char *argv[])
1334 if(optarg[strlen(optarg) - 1] != '/') 1334 if(optarg[strlen(optarg) - 1] != '/')
1335 { 1335 {
1336 int optarg_len = strlen(optarg); 1336 int optarg_len = strlen(optarg);
1337 1337
1338 config_path[optarg_len] = '/'; 1338 config_path[optarg_len] = '/';
1339 config_path[optarg_len + 1] = '\0'; 1339 config_path[optarg_len + 1] = '\0';
1340 } 1340 }
@@ -1356,7 +1356,7 @@ int main(int argc, char *argv[])
1356 { 1356 {
1357 log_tox_trace = 1; 1357 log_tox_trace = 1;
1358 } 1358 }
1359 if(min_log_level != L_DEBUG && min_log_level != L_DEBUG2) 1359 if(min_log_level != L_DEBUG && min_log_level != L_DEBUG2)
1360 { 1360 {
1361 min_log_level = L_DEBUG; 1361 min_log_level = L_DEBUG;
1362 } 1362 }
@@ -1442,7 +1442,7 @@ int main(int argc, char *argv[])
1442 { 1442 {
1443 log_printf(L_INFO, "Server in ToxID whitelisting mode - only clients listed with -i can connect"); 1443 log_printf(L_INFO, "Server in ToxID whitelisting mode - only clients listed with -i can connect");
1444 } 1444 }
1445 1445
1446 if((!client_mode) && (rules_policy != NONE)) 1446 if((!client_mode) && (rules_policy != NONE))
1447 { 1447 {
1448 load_rules(); 1448 load_rules();
@@ -1470,22 +1470,22 @@ int main(int argc, char *argv[])
1470 1470
1471 /* Bootstrap tox */ 1471 /* Bootstrap tox */
1472 tox_options_default(&tox_options); 1472 tox_options_default(&tox_options);
1473 if(min_log_level >= L_DEBUG2) 1473 if(min_log_level >= L_DEBUG2)
1474 { 1474 {
1475 tox_options.log_callback = on_tox_log; 1475 tox_options.log_callback = on_tox_log;
1476 } 1476 }
1477 tox_options.udp_enabled = 1; 1477 tox_options.udp_enabled = 1;
1478 tox_options.local_discovery_enabled = 1; 1478 tox_options.local_discovery_enabled = 1;
1479 tox_options.tcp_port = tcp_relay_port; 1479 tox_options.tcp_port = tcp_relay_port;
1480 tox_options.start_port = udp_start_port; 1480 tox_options.start_port = udp_start_port;
1481 tox_options.end_port = udp_end_port; 1481 tox_options.end_port = udp_end_port;
1482 tox_options.hole_punching_enabled = 1; 1482 tox_options.hole_punching_enabled = 1;
1483 1483
1484 log_printf(L_INFO, "Using %d for TCP relay port and %d-%d for UDP", 1484 log_printf(L_INFO, "Using %d for TCP relay port and %d-%d for UDP",
1485 tox_options.tcp_port, 1485 tox_options.tcp_port,
1486 tox_options.start_port, 1486 tox_options.start_port,
1487 tox_options.end_port 1487 tox_options.end_port
1488 ); 1488 );
1489 1489
1490 if((!client_mode) || load_saved_toxid_in_client_mode) 1490 if((!client_mode) || load_saved_toxid_in_client_mode)
1491 { 1491 {
diff --git a/util.c b/util.c
index 3e6a99c..01fbe65 100644
--- a/util.c
+++ b/util.c
@@ -92,12 +92,12 @@ int parse_local_port_forward(char *string, int *local_port, char **hostname, int
92 92
93 /* First replace all @ with :, ':' is forbidden in some environments */ 93 /* First replace all @ with :, ':' is forbidden in some environments */
94 char *p = string; 94 char *p = string;
95 while(*p) 95 while(*p)
96 { 96 {
97 if(*p == '@') *p = ':'; 97 if(*p == '@') *p = ':';
98 p++; 98 p++;
99 } 99 }
100 100
101 lport = strtok(string, ":"); 101 lport = strtok(string, ":");
102 host = strtok(NULL, ":"); 102 host = strtok(NULL, ":");
103 rport = strtok(NULL, ":"); 103 rport = strtok(NULL, ":");
@@ -123,12 +123,12 @@ int parse_pipe_port_forward(char *string, char **hostname, int *remote_port)
123 123
124 /* First replace all @ with :, ':' is forbidden in some environments */ 124 /* First replace all @ with :, ':' is forbidden in some environments */
125 char *p = string; 125 char *p = string;
126 while(*p) 126 while(*p)
127 { 127 {
128 if(*p == '@') *p = ':'; 128 if(*p == '@') *p = ':';
129 p++; 129 p++;
130 } 130 }
131 131
132 host = strtok(string, ":"); 132 host = strtok(string, ":");
133 rport = strtok(NULL, ":"); 133 rport = strtok(NULL, ":");
134 134