branch Attitude Adjustment packages
[12.09/packages.git] / net / netdiscover / patches / 00-add-machine-ouput.patch
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
4 @@ -127,6 +127,7 @@
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;
10        
11        /* Source IP */
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
15 @@ -30,6 +30,7 @@
16  #include <unistd.h>
17  #include <stdlib.h>
18  #include <string.h>
19 +#include <signal.h>
20  #include "ifaces.h"
21  #include "screen.h"
22  
23 @@ -39,8 +40,17 @@
24         char *disp;
25         char *sip;
26         int autos;
27 +       int machine;
28  };
29  
30 +/* Injection Thread data structure */
31 +struct t_inject {
32 +  struct t_data *datos;
33 +  pthread_t *sniffer;
34 +  pthread_t *screen;
35 +  pthread_t *keys;
36 +  int scan_secs;
37 +};
38  
39  void *inject_arp(void *arg);
40  void *screen_refresh(void *arg);
41 @@ -77,7 +87,7 @@
42  
43  
44  pthread_t injection, sniffer, screen, keys;
45 -int fastmode, pcount, node, ssleep;
46 +int fastmode, pcount, node, ssleep, nokeywait;
47  long sleept;
48  
49  
50 @@ -86,7 +96,9 @@
51  {
52      while ( 1 == 1 )
53      {
54 -        read_key();
55 +       struct t_data *datos;
56 +       datos = (struct t_data *)arg;
57 +        read_key(datos->machine);
58      }
59  }
60  
61 @@ -97,20 +109,24 @@
62         int c;
63         int esniff = 0;
64         int erange = 0;
65 +       int scan_secs = 0;
66         struct t_data datos;
67 -       
68 +       struct t_inject injectdata;
69 +
70         datos.sip = NULL;
71         datos.disp = NULL;
72 +       datos.machine = 0;
73         datos.autos = 0;
74         sleept = 99;
75         node = 67;
76         pcount = 1;
77 +       nokeywait = 0;
78         
79         current_network = (char *) malloc ((sizeof(char)) * 16);
80         sprintf(current_network,"Starting.");
81         
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)
85         {
86                 switch (c)
87                 {
88 @@ -138,12 +154,20 @@
89                         case  'n':
90                                 node = atoi(optarg);
91                                 break;
92 +
93 +                       case 't':
94 +                               scan_secs = atoi(optarg);
95 +                                break;
96                         
97                         case  'r':
98                                 datos.sip = (char *) malloc (sizeof(char) * strlen(optarg));
99                                 sprintf(datos.sip, "%s", optarg);
100                                 erange = 1;
101                                 break;
102 +
103 +                       case 'm':
104 +                              datos.machine = 1;
105 +                              break;
106                         
107                         case  'f':
108                                 fastmode = 1;
109 @@ -153,6 +177,10 @@
110                                 usage(argv[0]);
111                                 exit(1);
112                                 break;
113 +
114 +                               case 'k':
115 +                               nokeywait = 1;
116 +                               break;
117                         
118                         default:
119                                 break;
120 @@ -181,7 +209,7 @@
121         /* Init some stuff */
122         lnet_init(datos.disp);
123         init_lists();
124 -       system("clear");
125 +       if (!datos.machine) system("clear");
126         
127         /* If no mode was selected, enable auto scan */
128         if ((erange != 1) && (esniff != 1))
129 @@ -189,9 +217,15 @@
130                 datos.autos = 1;
131         }
132         
133 +       
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);
138 +       if (!nokeywait) {
139 +         pthread_create(&keys, NULL, keys_thread, (void *)&datos);
140 +         injectdata.keys = &keys;
141 +       } else {
142 +         injectdata.keys = NULL;
143 +       }
144         pthread_create(&sniffer, NULL, start_sniffer, (void *)&datos);
145         
146         if (esniff == 1)
147 @@ -201,10 +235,19 @@
148         }
149         else
150         {
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;
156 +
157 +               if (pthread_create(&injection, NULL, inject_arp, (void *)&injectdata))
158                         perror("Could not create injection thread");
159                 
160 -               pthread_join(sniffer,NULL);
161 +               if (scan_secs > 0) {
162 +                 pthread_join(injection,NULL);
163 +               } else {
164 +                 pthread_join(sniffer,NULL);
165 +               }
166         }
167         
168         
169 @@ -215,10 +258,11 @@
170  /* Refresh screen function called by screen thread */
171  void *screen_refresh(void *arg)
172  {
173 -       
174 +       struct t_data *datos;
175 +       datos = (struct t_data *)arg;
176         while (1==1)
177         {
178 -               print_screen();
179 +               print_screen(datos->machine);
180                 sleep(1);
181         }
182         
183 @@ -228,9 +272,11 @@
184  /* Inject ARP Replys to the network */
185  void *inject_arp(void *arg)
186  {      
187 +        struct t_inject *inject;
188         struct t_data *datos;
189                 
190 -       datos = (struct t_data *)arg;
191 +       inject = (struct t_inject *)arg;
192 +       datos = inject->datos;
193         sleep(2);
194         
195         if ( datos->autos != 1 )
196 @@ -251,6 +297,12 @@
197         
198         sprintf(current_network,"Finished!");
199         lnet_destroy();
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);
205 +       }
206         
207         return NULL;
208  }
209 @@ -400,6 +452,9 @@
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",
217                 VERSION, comando);
218  }
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
222 @@ -114,7 +114,7 @@
223  
224  
225  /* Read input keys */
226 -void read_key()
227 +void read_key(int machine)
228  {
229      int ch;
230      ch = getchar();
231 @@ -162,12 +162,12 @@
232         smode = 2;
233      }
234          
235 -        print_screen();
236 +        print_screen(machine);
237  }
238  
239  
240  /* Clear and fill the screen */
241 -void print_screen()
242 +void print_screen(int machine)
243  {
244         /* Get Console Size */
245     if (ioctl(0, TIOCGWINSZ, &win_sz) < 0)
246 @@ -177,16 +177,16 @@
247     }
248          
249         /* Flush and print screen */
250 -       fprintf( stderr, "\33[1;1H" );
251 -       fill_screen();
252 -       fprintf( stderr, "\33[J" );
253 +        if (!machine) fprintf( stderr, "\33[1;1H" );
254 +       fill_screen(machine);
255 +       if (!machine) fprintf( stderr, "\33[J" );
256         fflush(stdout);
257  }
258  
259  
260  /* Fills the screen using white spaces to avoid refresh problems  *
261   * not a very smart way, but it works :)                          */
262 -void fill_screen()
263 +void fill_screen(int machine)
264  {
265     int x, j;
266     struct arp_rep_l *arprep_l;
267 @@ -196,40 +196,42 @@
268     
269     pthread_mutex_lock(listm);  
270         
271 -   sprintf(line, " Currently scanning: %s   |   Our Mac is: %s - %i", 
272 -           current_network, ourmac, scroll);
273 -   printf("%s", line);
274 -       
275 -   /* Fill with spaces */
276 -   for (j=strlen(line); j<win_sz.ws_col - 1; j++)
277 -         printf(" ");
278 -   printf("\n");
279 -       
280 -       /* Print blank line with spaces */
281 -   for (j=0; j<win_sz.ws_col - 1; j++)
282 -         printf(" ");
283 -   printf("\n");
284 -
285 -
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);
289 -       
290 -   /* Fill with spaces */
291 -   for (j=strlen(line); j<win_sz.ws_col - 1; j++)
292 -         printf(" ");
293 -   printf("\n");
294 -       
295 -       
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");
303 -
304 -
305 +   
306 +   if (!machine) {
307 +     sprintf(line, " Currently scanning: %s   |   Our Mac is: %s - %i", 
308 +            current_network, ourmac, scroll);
309 +     printf("%s", line);
310 +       
311 +     /* Fill with spaces */
312 +     for (j=strlen(line); j<win_sz.ws_col - 1; j++)
313 +       printf(" ");
314 +     printf("\n");
315 +     
316 +     /* Print blank line with spaces */
317 +     for (j=0; j<win_sz.ws_col - 1; j++)
318 +       printf(" ");
319 +     printf("\n");
320 +     
321 +
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);
325 +     
326 +     /* Fill with spaces */
327 +     for (j=strlen(line); j<win_sz.ws_col - 1; j++)
328 +       printf(" ");
329 +     printf("\n");
330 +       
331 +     
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");
339 +   }
340 +   
341     /* Print each found station trough arp reply */
342     if (smode == 0)
343     {
344 @@ -243,12 +245,12 @@
345              sprintf(tline, " ");
346              
347              /* Set IP */
348 -            sprintf(tline, "%s ", arprep_l->sip);
349 +            sprintf(tline, "%s ", arprep_l->sip);          
350              strcat(line, tline);
351 -            
352 -            /* Fill with spaces */
353 -            for (j=strlen(line); j<17; j++)
354 -               strcat(line, blank);
355 +   
356 +           /* Fill with spaces */
357 +           for (j=strlen(line); j<17; j++)
358 +             strcat(line, blank);
359              
360              /* IP & MAC */
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);
367 -            
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);
372              
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);
377 +
378 +           if (!arprep_l->printed) {
379 +             printf("%s\n", line);         
380 +             arprep_l->printed = 1;
381 +             if (!machine) {
382 +               arprep_l->printed = 0;
383 +             }
384 +           }
385           }
386           
387           arprep_l = arprep_l->next;
388           x += 1;
389 -      
390 -         /* Check if end of screen was reached */
391 -         if (x >= ( (win_sz.ws_row + scroll) - 7))
392 -            break;
393 +
394 +        if (!machine) {
395 +          /* Check if end of screen was reached */
396 +          if (x >= ( (win_sz.ws_row + scroll) - 7))
397 +            break;
398 +        }
399        }
400        
401     } /* Print only arp request */
402 @@ -292,10 +302,10 @@
403              /* Get source IP */
404              sprintf(tline, "%s ", arprep_l->sip);
405              strcat(line, tline);
406 -            
407 -            /* Fill with spaces */
408 -            for (j=strlen(line); j<17; j++)
409 -               strcat(line, blank);
410 +
411 +           /* Fill with spaces */
412 +           for (j=strlen(line); j<17; j++)
413 +             strcat(line, blank);
414              
415              /* Get source MAC */
416              sprintf(tline, "%02x:%02x:%02x:%02x:%02x:%02x   ",
417 @@ -308,27 +318,29 @@
418              sprintf(tline, "%s", arprep_l->dip);
419              strcat(line, tline);
420              
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);
427              
428              /* Count, Length & Vendor */
429              sprintf(tline, "%02d", arprep_l->count);
430              strcat(line, tline);
431              
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);
438              
439              printf("%s\n", line);
440           }
441           
442           arprep_l = arprep_l->next;
443           x += 1;
444 -      
445 -         /* Check if end of screen was reached */
446 -         if (x >= ( (win_sz.ws_row + scroll) - 7))
447 -            break;
448 +
449 +        if (!machine) {
450 +          /* Check if end of screen was reached */
451 +          if (x >= ( (win_sz.ws_row + scroll) - 7))
452 +            break;
453 +        }
454        }
455     }
456     else if(smode == 2)
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
460 @@ -60,6 +60,7 @@
461         char *vendor;
462         short type;
463         unsigned int count;
464 +        int printed;
465         struct arp_rep_l *next;
466  };
467