X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nbtscanner.c;h=ab454180682ffc9f9356a2f8bf8b3157c90fa6fb;hb=refs%2Fheads%2Fmaster;hp=cbc894527014a6924d46e65b6cfb57cf2b2c5b49;hpb=ab5d8a35c1c111f64137f76939c68365cf4d22fb;p=nbtscanner diff --git a/nbtscanner.c b/nbtscanner.c index cbc8945..ab45418 100644 --- a/nbtscanner.c +++ b/nbtscanner.c @@ -32,7 +32,6 @@ #include #include #include -#include #include "nbtscanner.h" #include "mysql_interface.h" @@ -52,6 +51,7 @@ void interpret_node_status(char *p, struct in_addr in) { int numnames = CVAL(p,0); char hostname[32], fileservername[32], group[32]; + char messenger; /* * hopefully this will be enough to identify the host as unknown @@ -61,6 +61,7 @@ void interpret_node_status(char *p, struct in_addr in) strcpy(hostname, "-unknown-nbtscanner-"); strcpy(fileservername, "-unknown-nbtscanner-"); strcpy(group, "-unknown-nbtscanner-"); + messenger = 'n'; p += 1; while (numnames--) { @@ -101,14 +102,18 @@ void interpret_node_status(char *p, struct in_addr in) if ((p[0] & 0x80) == 0x80 && ((p[0] & 0x1f) == 0x04) && type == 0x00) { strcpy(group, qname); } + /* Messenger up (type 0x03) */ + if (type == 0x03) { + messenger = 'y'; + } p += 2; } if (use_mysql) { - add_record_mysql(inet_ntoa(in), hostname, fileservername, group); + add_record_mysql(inet_ntoa(in), hostname, fileservername, group, messenger); } else { - printf("%s,%s,%s,%s\n", inet_ntoa(in), hostname, fileservername, group); + printf("%s,%s,%s,%s,%c\n", inet_ntoa(in), hostname, fileservername, group, messenger); } } @@ -299,43 +304,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; }