X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nbtscanner.c;fp=nbtscanner.c;h=223965cecacd61994ebe507dc3311dc526803554;hb=7aa185f7ffbfb86dd631682014d3397c5ca82342;hp=cbc894527014a6924d46e65b6cfb57cf2b2c5b49;hpb=ab5d8a35c1c111f64137f76939c68365cf4d22fb;p=nbtscanner diff --git a/nbtscanner.c b/nbtscanner.c index cbc8945..223965c 100644 --- a/nbtscanner.c +++ b/nbtscanner.c @@ -32,7 +32,6 @@ #include #include #include -#include #include "nbtscanner.h" #include "mysql_interface.h" @@ -299,43 +298,59 @@ void scan_range(struct in_addr ip, int rangesize) int main(int argc, char *argv[]) { - int junk = mtrace(); int fd = open_sockets(); int i; - id_list_init(); - init_stats(); - server_fd = fd; parse_configfile(); - /* really ugly to have here */ if (use_mysql) { init_mysql(mysql_host, mysql_username, mysql_password); } - for (i = 0; i < ranges; i++) { - scan_range(scanrange[i], scanrangesize[i]); - } + for ( ;; ) { + struct timeval start, now; + unsigned int delay_ms; + + id_list_init(); + init_stats(); + + gettimeofday(&start, NULL); + + for (i = 0; i < ranges; i++) { + scan_range(scanrange[i], scanrangesize[i]); + } - /* - * receive answers and resend packets until all answers have - * been received, or all packets have been timed out - */ - status = RETRYING; - while (get_num_free_ids() != 65536) { - recv_nbt_packets(fd); - resend_timed_out_packets(fd); - } + /* + * receive answers and resend packets until all answers have + * been received, or all packets have been timed out + */ + status = RETRYING; + while (get_num_free_ids() != 65536) { + recv_nbt_packets(fd); + resend_timed_out_packets(fd); + } - if (use_mysql) { - finish_mysql(); - } + if (verbosity >= 3) { + print_stats(1); + fprintf(stderr, "\n"); + } - if (verbosity >= 3) { - print_stats(1); - fprintf(stderr, "\n"); - } + id_list_destroy(); + gettimeofday(&now, NULL); + + delay_ms = scan_interval - mydifftime(start, now); + if (scan_wait > delay_ms) delay_ms = scan_wait; + + return 0; + + if (verbosity >= 3) { + fprintf(stderr, "Scan took %d ms, waiting %d ms for next scan...\r", + mydifftime(start, now), delay_ms); + usleep(delay_ms * 1000); + } + } + /* finish_mysql(); */ return 0; }