1 diff -Naur netdiscover-0.3-beta6.orig/src/ifaces.c netdiscover-0.3-beta6/src/ifaces.c
2 --- netdiscover-0.3-beta6.orig/src/ifaces.c 2009-06-24 18:21:11.000000000 -0400
3 +++ netdiscover-0.3-beta6/src/ifaces.c 2009-06-24 21:44:05.000000000 -0400
5 memcpy(type, packet + 20, 2); /* ARP Opcode */
6 new_arprep_l->header = new_header; /* Add header */
7 new_arprep_l->count = 1; /* Count */
8 + new_arprep_l->printed = 0;
9 new_arprep_l->next = NULL;
12 diff -Naur netdiscover-0.3-beta6.orig/src/main.c netdiscover-0.3-beta6/src/main.c
13 --- netdiscover-0.3-beta6.orig/src/main.c 2009-06-24 18:21:11.000000000 -0400
14 +++ netdiscover-0.3-beta6/src/main.c 2009-06-24 21:34:59.000000000 -0400
30 +/* Injection Thread data structure */
32 + struct t_data *datos;
39 void *inject_arp(void *arg);
40 void *screen_refresh(void *arg);
44 pthread_t injection, sniffer, screen, keys;
45 -int fastmode, pcount, node, ssleep;
46 +int fastmode, pcount, node, ssleep, nokeywait;
55 + struct t_data *datos;
56 + datos = (struct t_data *)arg;
57 + read_key(datos->machine);
68 + struct t_inject injectdata;
79 current_network = (char *) malloc ((sizeof(char)) * 16);
80 sprintf(current_network,"Starting.");
82 /* Fetch parameters */
83 - while ((c = getopt(argc, argv, "i:s:r:n:c:pSfh")) != EOF)
84 + while ((c = getopt(argc, argv, "i:s:r:n:c:t:pSfhkm")) != EOF)
94 + scan_secs = atoi(optarg);
98 datos.sip = (char *) malloc (sizeof(char) * strlen(optarg));
99 sprintf(datos.sip, "%s", optarg);
121 /* Init some stuff */
122 lnet_init(datos.disp);
125 + if (!datos.machine) system("clear");
127 /* If no mode was selected, enable auto scan */
128 if ((erange != 1) && (esniff != 1))
134 /* Start the execution */
135 - pthread_create(&screen, NULL, screen_refresh, (void *)NULL);
136 - pthread_create(&keys, NULL, keys_thread, (void *)NULL);
137 + pthread_create(&screen, NULL, screen_refresh, (void *)&datos);
139 + pthread_create(&keys, NULL, keys_thread, (void *)&datos);
140 + injectdata.keys = &keys;
142 + injectdata.keys = NULL;
144 pthread_create(&sniffer, NULL, start_sniffer, (void *)&datos);
147 @@ -201,10 +235,19 @@
151 - if (pthread_create(&injection, NULL, inject_arp, (void *)&datos))
152 + injectdata.datos = &datos;
153 + injectdata.sniffer = &sniffer;
154 + injectdata.screen = &screen;
155 + injectdata.scan_secs = scan_secs;
157 + if (pthread_create(&injection, NULL, inject_arp, (void *)&injectdata))
158 perror("Could not create injection thread");
160 - pthread_join(sniffer,NULL);
161 + if (scan_secs > 0) {
162 + pthread_join(injection,NULL);
164 + pthread_join(sniffer,NULL);
169 @@ -215,10 +258,11 @@
170 /* Refresh screen function called by screen thread */
171 void *screen_refresh(void *arg)
174 + struct t_data *datos;
175 + datos = (struct t_data *)arg;
179 + print_screen(datos->machine);
184 /* Inject ARP Replys to the network */
185 void *inject_arp(void *arg)
187 + struct t_inject *inject;
188 struct t_data *datos;
190 - datos = (struct t_data *)arg;
191 + inject = (struct t_inject *)arg;
192 + datos = inject->datos;
195 if ( datos->autos != 1 )
198 sprintf(current_network,"Finished!");
200 + if (inject->scan_secs > 0) {
201 + sleep(inject->scan_secs);
202 + pthread_kill(*(inject->sniffer), SIGKILL);
203 + pthread_kill(*(inject->screen), SIGKILL);
204 + pthread_kill(*(inject->keys), SIGKILL);
210 " -n node: last ip octet used for scanning (from 2 to 253)\n"
211 " -S enable sleep time supression betwen each request (hardcore mode)\n"
212 " -f enable fastmode scan, saves a lot of time, recommended for auto\n\n"
213 + " -k nokeywait: Don't wait for keypress\n"
214 + " -t time: maximum time to listen after last arp request sent (seconds)\n"
215 + " -m don't clear and format screen, just output replies\n"
216 "If -p or -r arent enabled, netdiscover will scan for common lan addresses\n",
219 diff -Naur netdiscover-0.3-beta6.orig/src/screen.c netdiscover-0.3-beta6/src/screen.c
220 --- netdiscover-0.3-beta6.orig/src/screen.c 2009-06-24 18:21:11.000000000 -0400
221 +++ netdiscover-0.3-beta6/src/screen.c 2009-06-25 19:15:24.000000000 -0400
225 /* Read input keys */
227 +void read_key(int machine)
231 @@ -162,12 +162,12 @@
236 + print_screen(machine);
240 /* Clear and fill the screen */
242 +void print_screen(int machine)
244 /* Get Console Size */
245 if (ioctl(0, TIOCGWINSZ, &win_sz) < 0)
246 @@ -177,16 +177,16 @@
249 /* Flush and print screen */
250 - fprintf( stderr, "\33[1;1H" );
252 - fprintf( stderr, "\33[J" );
253 + if (!machine) fprintf( stderr, "\33[1;1H" );
254 + fill_screen(machine);
255 + if (!machine) fprintf( stderr, "\33[J" );
260 /* Fills the screen using white spaces to avoid refresh problems *
261 * not a very smart way, but it works :) */
263 +void fill_screen(int machine)
266 struct arp_rep_l *arprep_l;
267 @@ -196,40 +196,42 @@
269 pthread_mutex_lock(listm);
271 - sprintf(line, " Currently scanning: %s | Our Mac is: %s - %i",
272 - current_network, ourmac, scroll);
273 - printf("%s", line);
275 - /* Fill with spaces */
276 - for (j=strlen(line); j<win_sz.ws_col - 1; j++)
280 - /* Print blank line with spaces */
281 - for (j=0; j<win_sz.ws_col - 1; j++)
286 - sprintf(line, " %d Captured ARP Req/Rep packets, from %d hosts. Total size: %d",
287 - arprep_count->count, arprep_count->hosts, arprep_count->length);
288 - printf("%s", line);
290 - /* Fill with spaces */
291 - for (j=strlen(line); j<win_sz.ws_col - 1; j++)
296 - /* Print Header and counters */
297 - printf(" _____________________________________________________________________________\n");
298 - if (smode == 0 || (oldmode == 0 && smode == 2))
299 - printf(" IP At MAC Address Count Len MAC Vendor \n");
300 - else if (smode == 1 || (oldmode == 1 && smode == 2))
301 - printf(" IP At MAC Address Requests IP Count \n");
302 - printf(" ----------------------------------------------------------------------------- \n");
307 + sprintf(line, " Currently scanning: %s | Our Mac is: %s - %i",
308 + current_network, ourmac, scroll);
309 + printf("%s", line);
311 + /* Fill with spaces */
312 + for (j=strlen(line); j<win_sz.ws_col - 1; j++)
316 + /* Print blank line with spaces */
317 + for (j=0; j<win_sz.ws_col - 1; j++)
322 + sprintf(line, " %d Captured ARP Req/Rep packets, from %d hosts. Total size: %d",
323 + arprep_count->count, arprep_count->hosts, arprep_count->length);
324 + printf("%s", line);
326 + /* Fill with spaces */
327 + for (j=strlen(line); j<win_sz.ws_col - 1; j++)
332 + /* Print Header and counters */
333 + printf(" _____________________________________________________________________________\n");
334 + if (smode == 0 || (oldmode == 0 && smode == 2))
335 + printf(" IP At MAC Address Count Len MAC Vendor \n");
336 + else if (smode == 1 || (oldmode == 1 && smode == 2))
337 + printf(" IP At MAC Address Requests IP Count \n");
338 + printf(" ----------------------------------------------------------------------------- \n");
341 /* Print each found station trough arp reply */
344 @@ -243,12 +245,12 @@
348 - sprintf(tline, "%s ", arprep_l->sip);
349 + sprintf(tline, "%s ", arprep_l->sip);
352 - /* Fill with spaces */
353 - for (j=strlen(line); j<17; j++)
354 - strcat(line, blank);
356 + /* Fill with spaces */
357 + for (j=strlen(line); j<17; j++)
358 + strcat(line, blank);
361 sprintf(tline, "%02x:%02x:%02x:%02x:%02x:%02x ",
362 @@ -260,21 +262,29 @@
363 /* Count, Length & Vendor */
364 sprintf(tline, "%02d %03d %s", arprep_l->count,
365 arprep_l->header->length, arprep_l->vendor );
366 - strcat(line, tline);
368 - /* Fill again with spaces */
369 - for (j=strlen(line); j<win_sz.ws_col - 1; j++)
370 - strcat(line, blank);
371 + strcat(line, tline);
373 - printf("%s\n", line);
374 + /* Fill again with spaces */
375 + for (j=strlen(line); j<win_sz.ws_col - 1; j++)
376 + strcat(line, blank);
378 + if (!arprep_l->printed) {
379 + printf("%s\n", line);
380 + arprep_l->printed = 1;
382 + arprep_l->printed = 0;
387 arprep_l = arprep_l->next;
390 - /* Check if end of screen was reached */
391 - if (x >= ( (win_sz.ws_row + scroll) - 7))
395 + /* Check if end of screen was reached */
396 + if (x >= ( (win_sz.ws_row + scroll) - 7))
401 } /* Print only arp request */
402 @@ -292,10 +302,10 @@
404 sprintf(tline, "%s ", arprep_l->sip);
407 - /* Fill with spaces */
408 - for (j=strlen(line); j<17; j++)
409 - strcat(line, blank);
411 + /* Fill with spaces */
412 + for (j=strlen(line); j<17; j++)
413 + strcat(line, blank);
416 sprintf(tline, "%02x:%02x:%02x:%02x:%02x:%02x ",
417 @@ -308,27 +318,29 @@
418 sprintf(tline, "%s", arprep_l->dip);
421 - /* Fill with spaces */
422 - for (j=strlen(line); j<54; j++)
423 - strcat(line, blank);
424 + /* Fill with spaces */
425 + for (j=strlen(line); j<54; j++)
426 + strcat(line, blank);
428 /* Count, Length & Vendor */
429 sprintf(tline, "%02d", arprep_l->count);
432 - /* Fill again with spaces */
433 - for (j=strlen(line); j<win_sz.ws_col - 1; j++)
434 - strcat(line, blank);
435 + /* Fill again with spaces */
436 + for (j=strlen(line); j<win_sz.ws_col - 1; j++)
437 + strcat(line, blank);
439 printf("%s\n", line);
442 arprep_l = arprep_l->next;
445 - /* Check if end of screen was reached */
446 - if (x >= ( (win_sz.ws_row + scroll) - 7))
450 + /* Check if end of screen was reached */
451 + if (x >= ( (win_sz.ws_row + scroll) - 7))
457 diff -Naur netdiscover-0.3-beta6.orig/src/screen.h netdiscover-0.3-beta6/src/screen.h
458 --- netdiscover-0.3-beta6.orig/src/screen.h 2009-06-24 18:21:11.000000000 -0400
459 +++ netdiscover-0.3-beta6/src/screen.h 2009-06-24 21:42:13.000000000 -0400
465 struct arp_rep_l *next;