File main.c changed (mode: 100644) (index ff57619..659efa7) |
... |
... |
void cleanup() |
931 |
931 |
tox_kill(tox); |
tox_kill(tox); |
932 |
932 |
if(client_socket) |
if(client_socket) |
933 |
933 |
{ |
{ |
934 |
|
close(client_socket); |
|
|
934 |
|
close(client_socket); |
935 |
935 |
} |
} |
936 |
936 |
log_close(); |
log_close(); |
937 |
937 |
} |
} |
|
... |
... |
void help() |
1245 |
1245 |
fprintf(stdout, " mode\n"); |
fprintf(stdout, " mode\n"); |
1246 |
1246 |
fprintf(stdout, " -s <secret> - shared secret used for connection authentication (max\n"); |
fprintf(stdout, " -s <secret> - shared secret used for connection authentication (max\n"); |
1247 |
1247 |
fprintf(stdout, " %u characters)\n", TOX_MAX_FRIEND_REQUEST_LENGTH-1); |
fprintf(stdout, " %u characters)\n", TOX_MAX_FRIEND_REQUEST_LENGTH-1); |
1248 |
|
fprintf(stdout, " -t <port> - set TCP relay port (0 disables TCP relaying)\n"); |
|
1249 |
|
fprintf(stdout, " -u <port>:<port> - set Tox UDP port range\n"); |
|
|
1248 |
|
fprintf(stdout, " -t <port> - set TCP relay port (0 disables TCP relaying)\n"); |
|
1249 |
|
fprintf(stdout, " -u <port>:<port> - set Tox UDP port range\n"); |
1250 |
1250 |
fprintf(stdout, " -d - debug mode (use twice to display toxcore log too)\n"); |
fprintf(stdout, " -d - debug mode (use twice to display toxcore log too)\n"); |
1251 |
1251 |
fprintf(stdout, " -q - quiet mode\n"); |
fprintf(stdout, " -q - quiet mode\n"); |
1252 |
1252 |
fprintf(stdout, " -S - send output to syslog instead of stdout\n"); |
fprintf(stdout, " -S - send output to syslog instead of stdout\n"); |
|
... |
... |
int main(int argc, char *argv[]) |
1267 |
1267 |
size_t save_size = 0; |
size_t save_size = 0; |
1268 |
1268 |
uint8_t *save_data = NULL; |
uint8_t *save_data = NULL; |
1269 |
1269 |
allowed_toxid *allowed_toxid_obj = NULL; |
allowed_toxid *allowed_toxid_obj = NULL; |
1270 |
|
|
|
1271 |
|
srand(time(NULL)); |
|
1272 |
|
tcp_relay_port = 1024 + (rand() % 64511); |
|
1273 |
|
udp_start_port = 1024 + (rand() % 64500); |
|
1274 |
|
udp_end_port = udp_start_port + 10; |
|
|
1270 |
|
|
|
1271 |
|
srand(time(NULL)); |
|
1272 |
|
tcp_relay_port = 1024 + (rand() % 64511); |
|
1273 |
|
udp_start_port = 1024 + (rand() % 64500); |
|
1274 |
|
udp_end_port = udp_start_port + 10; |
1275 |
1275 |
|
|
1276 |
1276 |
log_init(); |
log_init(); |
1277 |
1277 |
|
|
|
... |
... |
int main(int argc, char *argv[]) |
1360 |
1360 |
strncpy(shared_secret, optarg, TOX_MAX_FRIEND_REQUEST_LENGTH-1); |
strncpy(shared_secret, optarg, TOX_MAX_FRIEND_REQUEST_LENGTH-1); |
1361 |
1361 |
break; |
break; |
1362 |
1362 |
case 'd': |
case 'd': |
1363 |
|
if(min_log_level == L_DEBUG2) |
|
1364 |
|
{ |
|
1365 |
|
log_tox_trace = 1; |
|
1366 |
|
} |
|
1367 |
|
if(min_log_level != L_DEBUG && min_log_level != L_DEBUG2) |
|
1368 |
|
{ |
|
1369 |
|
min_log_level = L_DEBUG; |
|
1370 |
|
} |
|
1371 |
|
else |
|
1372 |
|
{ |
|
1373 |
|
min_log_level = L_DEBUG2; |
|
1374 |
|
} |
|
|
1363 |
|
if(min_log_level == L_DEBUG2) |
|
1364 |
|
{ |
|
1365 |
|
log_tox_trace = 1; |
|
1366 |
|
} |
|
1367 |
|
if(min_log_level != L_DEBUG && min_log_level != L_DEBUG2) |
|
1368 |
|
{ |
|
1369 |
|
min_log_level = L_DEBUG; |
|
1370 |
|
} |
|
1371 |
|
else |
|
1372 |
|
{ |
|
1373 |
|
min_log_level = L_DEBUG2; |
|
1374 |
|
} |
1375 |
1375 |
|
|
1376 |
1376 |
break; |
break; |
1377 |
1377 |
case 'q': |
case 'q': |
|
... |
... |
int main(int argc, char *argv[]) |
1390 |
1390 |
case 'U': |
case 'U': |
1391 |
1391 |
daemon_username = optarg; |
daemon_username = optarg; |
1392 |
1392 |
break; |
break; |
1393 |
|
case 't': |
|
1394 |
|
errno = 0; |
|
1395 |
|
tcp_relay_port = strtol(optarg, NULL, 10); |
|
1396 |
|
if(errno != 0 || tcp_relay_port < 0 || tcp_relay_port > 65535) |
|
1397 |
|
{ |
|
1398 |
|
tcp_relay_port = 1024 + (rand() % 64511); |
|
1399 |
|
log_printf(L_WARNING, "Ignored -t %s: TCP port number needs to be a number between 0 and 65535."); |
|
1400 |
|
} |
|
1401 |
|
break; |
|
1402 |
|
case 'u': |
|
1403 |
|
{ /* TODO make a function in util.h */ |
|
1404 |
|
char *sport; |
|
1405 |
|
char *eport; |
|
1406 |
|
|
|
1407 |
|
sport = strtok(optarg, ":"); |
|
1408 |
|
eport = strtok(NULL, ":"); |
|
1409 |
|
if(!sport || !eport) |
|
1410 |
|
{ |
|
1411 |
|
log_printf(L_WARNING, "Ignored -u %s: wrong format"); |
|
1412 |
|
} |
|
1413 |
|
else |
|
1414 |
|
{ |
|
1415 |
|
errno = 0; |
|
1416 |
|
udp_start_port = strtol(sport, NULL, 10); |
|
1417 |
|
udp_end_port = strtol(eport, NULL, 10); |
|
1418 |
|
if(errno != 0 || udp_start_port < 1 || udp_start_port > 65535 || \ |
|
1419 |
|
udp_end_port < 1 || udp_end_port > 65535) |
|
1420 |
|
{ |
|
1421 |
|
log_printf(L_WARNING, "Ignored -u %s: ports need to be integers between 1 and 65535"); |
|
1422 |
|
udp_start_port = 1024 + (rand() % 64500); |
|
1423 |
|
udp_end_port = udp_start_port + 10; |
|
1424 |
|
} |
|
1425 |
|
|
|
1426 |
|
} |
|
1427 |
|
} |
|
1428 |
|
break; |
|
|
1393 |
|
case 't': |
|
1394 |
|
errno = 0; |
|
1395 |
|
tcp_relay_port = strtol(optarg, NULL, 10); |
|
1396 |
|
if(errno != 0 || tcp_relay_port < 0 || tcp_relay_port > 65535) |
|
1397 |
|
{ |
|
1398 |
|
tcp_relay_port = 1024 + (rand() % 64511); |
|
1399 |
|
log_printf(L_WARNING, "Ignored -t %s: TCP port number needs to be a number between 0 and 65535."); |
|
1400 |
|
} |
|
1401 |
|
break; |
|
1402 |
|
case 'u': |
|
1403 |
|
{ /* TODO make a function in util.h */ |
|
1404 |
|
char *sport; |
|
1405 |
|
char *eport; |
|
1406 |
|
|
|
1407 |
|
sport = strtok(optarg, ":"); |
|
1408 |
|
eport = strtok(NULL, ":"); |
|
1409 |
|
if(!sport || !eport) |
|
1410 |
|
{ |
|
1411 |
|
log_printf(L_WARNING, "Ignored -u %s: wrong format"); |
|
1412 |
|
} |
|
1413 |
|
else |
|
1414 |
|
{ |
|
1415 |
|
errno = 0; |
|
1416 |
|
udp_start_port = strtol(sport, NULL, 10); |
|
1417 |
|
udp_end_port = strtol(eport, NULL, 10); |
|
1418 |
|
if(errno != 0 || udp_start_port < 1 || udp_start_port > 65535 || \ |
|
1419 |
|
udp_end_port < 1 || udp_end_port > 65535) |
|
1420 |
|
{ |
|
1421 |
|
log_printf(L_WARNING, "Ignored -u %s: ports need to be integers between 1 and 65535"); |
|
1422 |
|
udp_start_port = 1024 + (rand() % 64500); |
|
1423 |
|
udp_end_port = udp_start_port + 10; |
|
1424 |
|
} |
|
1425 |
|
|
|
1426 |
|
} |
|
1427 |
|
} |
|
1428 |
|
break; |
1429 |
1429 |
case 'b': |
case 'b': |
1430 |
1430 |
strncpy(boot_json, optarg, sizeof(boot_json) - 1); |
strncpy(boot_json, optarg, sizeof(boot_json) - 1); |
1431 |
1431 |
break; |
break; |
|
... |
... |
int main(int argc, char *argv[]) |
1475 |
1475 |
|
|
1476 |
1476 |
/* Bootstrap tox */ |
/* Bootstrap tox */ |
1477 |
1477 |
tox_options_default(&tox_options); |
tox_options_default(&tox_options); |
1478 |
|
if(min_log_level >= L_DEBUG2) |
|
1479 |
|
{ |
|
1480 |
|
tox_options.log_callback = on_tox_log; |
|
1481 |
|
} |
|
1482 |
|
tox_options.udp_enabled = 1; |
|
1483 |
|
tox_options.local_discovery_enabled = 1; |
|
1484 |
|
tox_options.tcp_port = tcp_relay_port; |
|
1485 |
|
tox_options.start_port = udp_start_port; |
|
1486 |
|
tox_options.end_port = udp_end_port; |
|
1487 |
|
tox_options.hole_punching_enabled = 1; |
|
1488 |
|
|
|
1489 |
|
log_printf(L_INFO, "Using %d for TCP relay port and %d-%d for UDP", |
|
1490 |
|
tox_options.tcp_port, |
|
1491 |
|
tox_options.start_port, |
|
1492 |
|
tox_options.end_port |
|
1493 |
|
); |
|
|
1478 |
|
if(min_log_level >= L_DEBUG2) |
|
1479 |
|
{ |
|
1480 |
|
tox_options.log_callback = on_tox_log; |
|
1481 |
|
} |
|
1482 |
|
tox_options.udp_enabled = 1; |
|
1483 |
|
tox_options.local_discovery_enabled = 1; |
|
1484 |
|
tox_options.tcp_port = tcp_relay_port; |
|
1485 |
|
tox_options.start_port = udp_start_port; |
|
1486 |
|
tox_options.end_port = udp_end_port; |
|
1487 |
|
tox_options.hole_punching_enabled = 1; |
|
1488 |
|
|
|
1489 |
|
log_printf(L_INFO, "Using %d for TCP relay port and %d-%d for UDP", |
|
1490 |
|
tox_options.tcp_port, |
|
1491 |
|
tox_options.start_port, |
|
1492 |
|
tox_options.end_port |
|
1493 |
|
); |
1494 |
1494 |
|
|
1495 |
1495 |
if((!client_mode) || load_saved_toxid_in_client_mode) |
if((!client_mode) || load_saved_toxid_in_client_mode) |
1496 |
1496 |
{ |
{ |