From: Florian Fainelli Date: Mon, 6 Jul 2009 11:36:46 +0000 (+0000) Subject: [package] print machines, patch from Daniel Dickinson (#5373) X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fsvn-archive%2Farchive.git;a=commitdiff_plain;h=201ca9c796ce388aa981256fd74a01207319f514 [package] print machines, patch from Daniel Dickinson (#5373) SVN-Revision: 16711 --- diff --git a/net/netdiscover/Makefile b/net/netdiscover/Makefile index 639d9e533a..e70ec59775 100644 --- a/net/netdiscover/Makefile +++ b/net/netdiscover/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=netdiscover PKG_VERSION:=0.3-beta6 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://nixgeneration.com/~jaime/netdiscover/releases/ diff --git a/net/netdiscover/patches/00-add-machine-ouput.patch b/net/netdiscover/patches/00-add-machine-ouput.patch new file mode 100644 index 0000000000..eed7f0fd5a --- /dev/null +++ b/net/netdiscover/patches/00-add-machine-ouput.patch @@ -0,0 +1,467 @@ +diff -Naur netdiscover-0.3-beta6.orig/src/ifaces.c netdiscover-0.3-beta6/src/ifaces.c +--- netdiscover-0.3-beta6.orig/src/ifaces.c 2009-06-24 18:21:11.000000000 -0400 ++++ netdiscover-0.3-beta6/src/ifaces.c 2009-06-24 21:44:05.000000000 -0400 +@@ -127,6 +127,7 @@ + memcpy(type, packet + 20, 2); /* ARP Opcode */ + new_arprep_l->header = new_header; /* Add header */ + new_arprep_l->count = 1; /* Count */ ++ new_arprep_l->printed = 0; + new_arprep_l->next = NULL; + + /* Source IP */ +diff -Naur netdiscover-0.3-beta6.orig/src/main.c netdiscover-0.3-beta6/src/main.c +--- netdiscover-0.3-beta6.orig/src/main.c 2009-06-24 18:21:11.000000000 -0400 ++++ netdiscover-0.3-beta6/src/main.c 2009-06-24 21:34:59.000000000 -0400 +@@ -30,6 +30,7 @@ + #include + #include + #include ++#include + #include "ifaces.h" + #include "screen.h" + +@@ -39,8 +40,17 @@ + char *disp; + char *sip; + int autos; ++ int machine; + }; + ++/* Injection Thread data structure */ ++struct t_inject { ++ struct t_data *datos; ++ pthread_t *sniffer; ++ pthread_t *screen; ++ pthread_t *keys; ++ int scan_secs; ++}; + + void *inject_arp(void *arg); + void *screen_refresh(void *arg); +@@ -77,7 +87,7 @@ + + + pthread_t injection, sniffer, screen, keys; +-int fastmode, pcount, node, ssleep; ++int fastmode, pcount, node, ssleep, nokeywait; + long sleept; + + +@@ -86,7 +96,9 @@ + { + while ( 1 == 1 ) + { +- read_key(); ++ struct t_data *datos; ++ datos = (struct t_data *)arg; ++ read_key(datos->machine); + } + } + +@@ -97,20 +109,24 @@ + int c; + int esniff = 0; + int erange = 0; ++ int scan_secs = 0; + struct t_data datos; +- ++ struct t_inject injectdata; ++ + datos.sip = NULL; + datos.disp = NULL; ++ datos.machine = 0; + datos.autos = 0; + sleept = 99; + node = 67; + pcount = 1; ++ nokeywait = 0; + + current_network = (char *) malloc ((sizeof(char)) * 16); + sprintf(current_network,"Starting."); + + /* Fetch parameters */ +- while ((c = getopt(argc, argv, "i:s:r:n:c:pSfh")) != EOF) ++ while ((c = getopt(argc, argv, "i:s:r:n:c:t:pSfhkm")) != EOF) + { + switch (c) + { +@@ -138,12 +154,20 @@ + case 'n': + node = atoi(optarg); + break; ++ ++ case 't': ++ scan_secs = atoi(optarg); ++ break; + + case 'r': + datos.sip = (char *) malloc (sizeof(char) * strlen(optarg)); + sprintf(datos.sip, "%s", optarg); + erange = 1; + break; ++ ++ case 'm': ++ datos.machine = 1; ++ break; + + case 'f': + fastmode = 1; +@@ -153,6 +177,10 @@ + usage(argv[0]); + exit(1); + break; ++ ++ case 'k': ++ nokeywait = 1; ++ break; + + default: + break; +@@ -181,7 +209,7 @@ + /* Init some stuff */ + lnet_init(datos.disp); + init_lists(); +- system("clear"); ++ if (!datos.machine) system("clear"); + + /* If no mode was selected, enable auto scan */ + if ((erange != 1) && (esniff != 1)) +@@ -189,9 +217,15 @@ + datos.autos = 1; + } + ++ + /* Start the execution */ +- pthread_create(&screen, NULL, screen_refresh, (void *)NULL); +- pthread_create(&keys, NULL, keys_thread, (void *)NULL); ++ pthread_create(&screen, NULL, screen_refresh, (void *)&datos); ++ if (!nokeywait) { ++ pthread_create(&keys, NULL, keys_thread, (void *)&datos); ++ injectdata.keys = &keys; ++ } else { ++ injectdata.keys = NULL; ++ } + pthread_create(&sniffer, NULL, start_sniffer, (void *)&datos); + + if (esniff == 1) +@@ -201,10 +235,19 @@ + } + else + { +- if (pthread_create(&injection, NULL, inject_arp, (void *)&datos)) ++ injectdata.datos = &datos; ++ injectdata.sniffer = &sniffer; ++ injectdata.screen = &screen; ++ injectdata.scan_secs = scan_secs; ++ ++ if (pthread_create(&injection, NULL, inject_arp, (void *)&injectdata)) + perror("Could not create injection thread"); + +- pthread_join(sniffer,NULL); ++ if (scan_secs > 0) { ++ pthread_join(injection,NULL); ++ } else { ++ pthread_join(sniffer,NULL); ++ } + } + + +@@ -215,10 +258,11 @@ + /* Refresh screen function called by screen thread */ + void *screen_refresh(void *arg) + { +- ++ struct t_data *datos; ++ datos = (struct t_data *)arg; + while (1==1) + { +- print_screen(); ++ print_screen(datos->machine); + sleep(1); + } + +@@ -228,9 +272,11 @@ + /* Inject ARP Replys to the network */ + void *inject_arp(void *arg) + { ++ struct t_inject *inject; + struct t_data *datos; + +- datos = (struct t_data *)arg; ++ inject = (struct t_inject *)arg; ++ datos = inject->datos; + sleep(2); + + if ( datos->autos != 1 ) +@@ -251,6 +297,12 @@ + + sprintf(current_network,"Finished!"); + lnet_destroy(); ++ if (inject->scan_secs > 0) { ++ sleep(inject->scan_secs); ++ pthread_kill(*(inject->sniffer), SIGKILL); ++ pthread_kill(*(inject->screen), SIGKILL); ++ pthread_kill(*(inject->keys), SIGKILL); ++ } + + return NULL; + } +@@ -400,6 +452,9 @@ + " -n node: last ip octet used for scanning (from 2 to 253)\n" + " -S enable sleep time supression betwen each request (hardcore mode)\n" + " -f enable fastmode scan, saves a lot of time, recommended for auto\n\n" ++ " -k nokeywait: Don't wait for keypress\n" ++ " -t time: maximum time to listen after last arp request sent (seconds)\n" ++ " -m don't clear and format screen, just output replies\n" + "If -p or -r arent enabled, netdiscover will scan for common lan addresses\n", + VERSION, comando); + } +diff -Naur netdiscover-0.3-beta6.orig/src/screen.c netdiscover-0.3-beta6/src/screen.c +--- netdiscover-0.3-beta6.orig/src/screen.c 2009-06-24 18:21:11.000000000 -0400 ++++ netdiscover-0.3-beta6/src/screen.c 2009-06-25 19:15:24.000000000 -0400 +@@ -114,7 +114,7 @@ + + + /* Read input keys */ +-void read_key() ++void read_key(int machine) + { + int ch; + ch = getchar(); +@@ -162,12 +162,12 @@ + smode = 2; + } + +- print_screen(); ++ print_screen(machine); + } + + + /* Clear and fill the screen */ +-void print_screen() ++void print_screen(int machine) + { + /* Get Console Size */ + if (ioctl(0, TIOCGWINSZ, &win_sz) < 0) +@@ -177,16 +177,16 @@ + } + + /* Flush and print screen */ +- fprintf( stderr, "\33[1;1H" ); +- fill_screen(); +- fprintf( stderr, "\33[J" ); ++ if (!machine) fprintf( stderr, "\33[1;1H" ); ++ fill_screen(machine); ++ if (!machine) fprintf( stderr, "\33[J" ); + fflush(stdout); + } + + + /* Fills the screen using white spaces to avoid refresh problems * + * not a very smart way, but it works :) */ +-void fill_screen() ++void fill_screen(int machine) + { + int x, j; + struct arp_rep_l *arprep_l; +@@ -196,40 +196,42 @@ + + pthread_mutex_lock(listm); + +- sprintf(line, " Currently scanning: %s | Our Mac is: %s - %i", +- current_network, ourmac, scroll); +- printf("%s", line); +- +- /* Fill with spaces */ +- for (j=strlen(line); jcount, arprep_count->hosts, arprep_count->length); +- printf("%s", line); +- +- /* Fill with spaces */ +- for (j=strlen(line); jcount, arprep_count->hosts, arprep_count->length); ++ printf("%s", line); ++ ++ /* Fill with spaces */ ++ for (j=strlen(line); jsip); ++ sprintf(tline, "%s ", arprep_l->sip); + strcat(line, tline); +- +- /* Fill with spaces */ +- for (j=strlen(line); j<17; j++) +- strcat(line, blank); ++ ++ /* Fill with spaces */ ++ for (j=strlen(line); j<17; j++) ++ strcat(line, blank); + + /* IP & MAC */ + sprintf(tline, "%02x:%02x:%02x:%02x:%02x:%02x ", +@@ -260,21 +262,29 @@ + /* Count, Length & Vendor */ + sprintf(tline, "%02d %03d %s", arprep_l->count, + arprep_l->header->length, arprep_l->vendor ); +- strcat(line, tline); +- +- /* Fill again with spaces */ +- for (j=strlen(line); jprinted) { ++ printf("%s\n", line); ++ arprep_l->printed = 1; ++ if (!machine) { ++ arprep_l->printed = 0; ++ } ++ } + } + + arprep_l = arprep_l->next; + x += 1; +- +- /* Check if end of screen was reached */ +- if (x >= ( (win_sz.ws_row + scroll) - 7)) +- break; ++ ++ if (!machine) { ++ /* Check if end of screen was reached */ ++ if (x >= ( (win_sz.ws_row + scroll) - 7)) ++ break; ++ } + } + + } /* Print only arp request */ +@@ -292,10 +302,10 @@ + /* Get source IP */ + sprintf(tline, "%s ", arprep_l->sip); + strcat(line, tline); +- +- /* Fill with spaces */ +- for (j=strlen(line); j<17; j++) +- strcat(line, blank); ++ ++ /* Fill with spaces */ ++ for (j=strlen(line); j<17; j++) ++ strcat(line, blank); + + /* Get source MAC */ + sprintf(tline, "%02x:%02x:%02x:%02x:%02x:%02x ", +@@ -308,27 +318,29 @@ + sprintf(tline, "%s", arprep_l->dip); + strcat(line, tline); + +- /* Fill with spaces */ +- for (j=strlen(line); j<54; j++) +- strcat(line, blank); ++ /* Fill with spaces */ ++ for (j=strlen(line); j<54; j++) ++ strcat(line, blank); + + /* Count, Length & Vendor */ + sprintf(tline, "%02d", arprep_l->count); + strcat(line, tline); + +- /* Fill again with spaces */ +- for (j=strlen(line); jnext; + x += 1; +- +- /* Check if end of screen was reached */ +- if (x >= ( (win_sz.ws_row + scroll) - 7)) +- break; ++ ++ if (!machine) { ++ /* Check if end of screen was reached */ ++ if (x >= ( (win_sz.ws_row + scroll) - 7)) ++ break; ++ } + } + } + else if(smode == 2) +diff -Naur netdiscover-0.3-beta6.orig/src/screen.h netdiscover-0.3-beta6/src/screen.h +--- netdiscover-0.3-beta6.orig/src/screen.h 2009-06-24 18:21:11.000000000 -0400 ++++ netdiscover-0.3-beta6/src/screen.h 2009-06-24 21:42:13.000000000 -0400 +@@ -60,6 +60,7 @@ + char *vendor; + short type; + unsigned int count; ++ int printed; + struct arp_rep_l *next; + }; +