diff options
Diffstat (limited to 'opentracker.c')
| -rw-r--r-- | opentracker.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/opentracker.c b/opentracker.c index f829171..bcc075c 100644 --- a/opentracker.c +++ b/opentracker.c | |||
| @@ -7,9 +7,11 @@ | |||
| 7 | /* System */ | 7 | /* System */ |
| 8 | #include <ctype.h> | 8 | #include <ctype.h> |
| 9 | #include <errno.h> | 9 | #include <errno.h> |
| 10 | #include <limits.h> | ||
| 10 | #include <pthread.h> | 11 | #include <pthread.h> |
| 11 | #include <pwd.h> | 12 | #include <pwd.h> |
| 12 | #include <signal.h> | 13 | #include <signal.h> |
| 14 | #include <stdint.h> | ||
| 13 | #include <stdio.h> | 15 | #include <stdio.h> |
| 14 | #include <stdlib.h> | 16 | #include <stdlib.h> |
| 15 | #include <string.h> | 17 | #include <string.h> |
| @@ -23,7 +25,6 @@ | |||
| 23 | #include "io.h" | 25 | #include "io.h" |
| 24 | #include "iob.h" | 26 | #include "iob.h" |
| 25 | #include "ip6.h" | 27 | #include "ip6.h" |
| 26 | #include "scan.h" | ||
| 27 | #include "socket.h" | 28 | #include "socket.h" |
| 28 | 29 | ||
| 29 | /* Opentracker */ | 30 | /* Opentracker */ |
| @@ -32,6 +33,7 @@ | |||
| 32 | #include "ot_http.h" | 33 | #include "ot_http.h" |
| 33 | #include "ot_livesync.h" | 34 | #include "ot_livesync.h" |
| 34 | #include "ot_mutex.h" | 35 | #include "ot_mutex.h" |
| 36 | #include "ot_scan.h" | ||
| 35 | #include "ot_random.h" | 37 | #include "ot_random.h" |
| 36 | #include "ot_stats.h" | 38 | #include "ot_stats.h" |
| 37 | #include "ot_udp.h" | 39 | #include "ot_udp.h" |
| @@ -380,8 +382,9 @@ char *set_config_option(char **option, char *value) { | |||
| 380 | return *option = strdup(value); | 382 | return *option = strdup(value); |
| 381 | } | 383 | } |
| 382 | 384 | ||
| 383 | static int scan_ip6_port(const char *src, ot_ip6 ip, uint16 *port) { | 385 | static int scan_ip6_port(const char *src, ot_ip6 ip, uint16_t *port) { |
| 384 | const char *s = src; | 386 | const char *s = src; |
| 387 | uint64_t value; | ||
| 385 | int off, bracket = 0; | 388 | int off, bracket = 0; |
| 386 | while (isspace(*s)) | 389 | while (isspace(*s)) |
| 387 | ++s; | 390 | ++s; |
| @@ -404,13 +407,15 @@ static int scan_ip6_port(const char *src, ot_ip6 ip, uint16 *port) { | |||
| 404 | if (*(s++) != ':') | 407 | if (*(s++) != ':') |
| 405 | return 0; | 408 | return 0; |
| 406 | } | 409 | } |
| 407 | if (!(off = scan_ushort(s, port))) | 410 | if (!(off = scan_udec(s, &value, 65535))) |
| 408 | return 0; | 411 | return 0; |
| 412 | *port = (uint16_t)value; | ||
| 409 | return off + s - src; | 413 | return off + s - src; |
| 410 | } | 414 | } |
| 411 | 415 | ||
| 412 | static int scan_ip6_net(const char *src, ot_net *net) { | 416 | static int scan_ip6_net(const char *src, ot_net *net) { |
| 413 | const char *s = src; | 417 | const char *s = src; |
| 418 | uint64_t value; | ||
| 414 | int off; | 419 | int off; |
| 415 | while (isspace(*s)) | 420 | while (isspace(*s)) |
| 416 | ++s; | 421 | ++s; |
| @@ -421,8 +426,9 @@ static int scan_ip6_net(const char *src, ot_net *net) { | |||
| 421 | net->bits = 128; | 426 | net->bits = 128; |
| 422 | else { | 427 | else { |
| 423 | s++; | 428 | s++; |
| 424 | if (!(off = scan_int(s, &net->bits))) | 429 | if (!(off = scan_udec(s, &value, 128))) |
| 425 | return 0; | 430 | return 0; |
| 431 | net->bits = (int)value; | ||
| 426 | if (ip6_isv4mapped(net->address)) | 432 | if (ip6_isv4mapped(net->address)) |
| 427 | net->bits += 96; | 433 | net->bits += 96; |
| 428 | if (net->bits > 128) | 434 | if (net->bits > 128) |
| @@ -523,7 +529,8 @@ int parse_configfile(char *config_filename) { | |||
| 523 | } | 529 | } |
| 524 | 530 | ||
| 525 | while (fgets(inbuf, sizeof(inbuf), config_file_handle)) { | 531 | while (fgets(inbuf, sizeof(inbuf), config_file_handle)) { |
| 526 | char *p = inbuf, *end; | 532 | char *p = inbuf, *end; |
| 533 | uint64_t value; | ||
| 527 | uint16_t tmpport = 6969; | 534 | uint16_t tmpport = 6969; |
| 528 | 535 | ||
| 529 | /* Skip white spaces */ | 536 | /* Skip white spaces */ |
| @@ -568,7 +575,8 @@ int parse_configfile(char *config_filename) { | |||
| 568 | ++bound; | 575 | ++bound; |
| 569 | break; | 576 | break; |
| 570 | case CONFIG_LISTEN_UDP_WORKERS: | 577 | case CONFIG_LISTEN_UDP_WORKERS: |
| 571 | scan_uint(p, &g_udp_workers); | 578 | if (scan_udec(p, &value, UINT_MAX)) |
| 579 | g_udp_workers = (unsigned int)value; | ||
| 572 | break; | 580 | break; |
| 573 | #ifdef WANT_ACCESSLIST_WHITE | 581 | #ifdef WANT_ACCESSLIST_WHITE |
| 574 | case CONFIG_ACCESS_WHITELIST: | 582 | case CONFIG_ACCESS_WHITELIST: |
| @@ -634,9 +642,9 @@ int parse_configfile(char *config_filename) { | |||
| 634 | void load_state(const char *const state_filename) { | 642 | void load_state(const char *const state_filename) { |
| 635 | FILE *state_filehandle; | 643 | FILE *state_filehandle; |
| 636 | char inbuf[512]; | 644 | char inbuf[512]; |
| 637 | ot_hash infohash; | 645 | ot_hash infohash; |
| 638 | unsigned long long base, downcount; | 646 | uint64_t base, downcount; |
| 639 | int consumed; | 647 | int consumed; |
| 640 | 648 | ||
| 641 | state_filehandle = fopen(state_filename, "r"); | 649 | state_filehandle = fopen(state_filename, "r"); |
| 642 | 650 | ||
| @@ -653,10 +661,10 @@ void load_state(const char *const state_filename) { | |||
| 653 | continue; | 661 | continue; |
| 654 | i = 2 * sizeof(ot_hash); | 662 | i = 2 * sizeof(ot_hash); |
| 655 | 663 | ||
| 656 | if (inbuf[i++] != ':' || !(consumed = scan_ulonglong(inbuf + i, &base))) | 664 | if (inbuf[i++] != ':' || !(consumed = scan_udec(inbuf + i, &base, UINT64_MAX))) |
| 657 | continue; | 665 | continue; |
| 658 | i += consumed; | 666 | i += consumed; |
| 659 | if (inbuf[i++] != ':' || !(consumed = scan_ulonglong(inbuf + i, &downcount))) | 667 | if (inbuf[i++] != ':' || !(consumed = scan_udec(inbuf + i, &downcount, UINT64_MAX))) |
| 660 | continue; | 668 | continue; |
| 661 | add_torrent_from_saved_state(infohash, base, downcount); | 669 | add_torrent_from_saved_state(infohash, base, downcount); |
| 662 | } | 670 | } |
| @@ -725,7 +733,7 @@ int main(int argc, char **argv) { | |||
| 725 | ot_ip6 serverip; | 733 | ot_ip6 serverip; |
| 726 | ot_net tmpnet; | 734 | ot_net tmpnet; |
| 727 | int bound = 0, scanon = 1; | 735 | int bound = 0, scanon = 1; |
| 728 | uint16_t tmpport; | 736 | uint64_t value; |
| 729 | char *statefile = 0; | 737 | char *statefile = 0; |
| 730 | pthread_t thread_id; /* time cacher */ | 738 | pthread_t thread_id; /* time cacher */ |
| 731 | 739 | ||
| @@ -764,28 +772,28 @@ int main(int argc, char **argv) { | |||
| 764 | break; | 772 | break; |
| 765 | #endif | 773 | #endif |
| 766 | case 'p': | 774 | case 'p': |
| 767 | if (!scan_ushort(optarg, &tmpport)) { | 775 | if (!scan_udec(optarg, &value, 65535)) { |
| 768 | usage(argv[0]); | 776 | usage(argv[0]); |
| 769 | exit(1); | 777 | exit(1); |
| 770 | } | 778 | } |
| 771 | ot_try_bind(serverip, tmpport, FLAG_TCP); | 779 | ot_try_bind(serverip, (uint16_t)value, FLAG_TCP); |
| 772 | bound++; | 780 | bound++; |
| 773 | break; | 781 | break; |
| 774 | case 'P': | 782 | case 'P': |
| 775 | if (!scan_ushort(optarg, &tmpport)) { | 783 | if (!scan_udec(optarg, &value, 65535)) { |
| 776 | usage(argv[0]); | 784 | usage(argv[0]); |
| 777 | exit(1); | 785 | exit(1); |
| 778 | } | 786 | } |
| 779 | ot_try_bind(serverip, tmpport, FLAG_UDP); | 787 | ot_try_bind(serverip, (uint16_t)value, FLAG_UDP); |
| 780 | bound++; | 788 | bound++; |
| 781 | break; | 789 | break; |
| 782 | #ifdef WANT_SYNC_LIVE | 790 | #ifdef WANT_SYNC_LIVE |
| 783 | case 's': | 791 | case 's': |
| 784 | if (!scan_ushort(optarg, &tmpport)) { | 792 | if (!scan_udec(optarg, &value, 65535)) { |
| 785 | usage(argv[0]); | 793 | usage(argv[0]); |
| 786 | exit(1); | 794 | exit(1); |
| 787 | } | 795 | } |
| 788 | livesync_bind_mcast(serverip, tmpport); | 796 | livesync_bind_mcast(serverip, (uint16_t)value); |
| 789 | break; | 797 | break; |
| 790 | #endif | 798 | #endif |
| 791 | case 'd': | 799 | case 'd': |
