X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nbtscanner.c;h=ab454180682ffc9f9356a2f8bf8b3157c90fa6fb;hb=HEAD;hp=a7c5e25859f33a879c6ee4bd3cefa543ed43c4e0;hpb=c00b46344cce7b05d6e0db74359de1971d2d09ec;p=nbtscanner diff --git a/nbtscanner.c b/nbtscanner.c index a7c5e25..ab45418 100644 --- a/nbtscanner.c +++ b/nbtscanner.c @@ -51,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 @@ -60,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--) { @@ -100,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,40 +305,58 @@ void scan_range(struct in_addr ip, int rangesize) int main(int argc, char *argv[]) { int fd = open_sockets(); + int i; - id_list_init(); - init_stats(); - - /* note that parse_configfile() will call scan_range()! */ server_fd = fd; - parse_configfile(1); + parse_configfile(); -/* for (i=1;i= 3) { - print_stats(1); - fprintf(stderr, "\n"); - } + 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); + } + + 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; }