diff -ru /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/Makefile dstumbler/Makefile --- /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/Makefile Mon May 12 00:33:06 2003 +++ dstumbler/Makefile Mon May 12 18:50:33 2003 @@ -1,7 +1,8 @@ CC = gcc -CFLAGS = -Wall -I/usr/local/include +CFLAGS = -Wall -I/usr/local/include -DHEADLESS TARGET = dstumbler -LDFLAGS = -L/usr/local/lib -lncurses -lpcap +#LDFLAGS = -L/usr/local/lib -lncurses -lpcap +LDFLAGS = -L/usr/local/lib -lpcap PREFIX = /usr/local OBJS = main.o\ misc.o\ diff -ru /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/README dstumbler/README --- /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/README Tue Feb 26 11:52:41 2002 +++ dstumbler/README Sun May 11 22:50:04 2003 @@ -22,6 +22,13 @@ realtime logging. other features with his adaptations will possibly be included in future versions. +www.wirelessleiden.nl / dumstertruck project +- a kill -HUP will reopen the logfile. Useful for + ratation. +- a log file starting with a | is taken as a pipe. +- a log file which looks like [hostname]: + will spawn a small deamon which can beconnected to + for live logging. current features of dstumbler include: diff -ru /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/aps.c dstumbler/aps.c --- /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/aps.c Tue Feb 26 12:01:31 2002 +++ dstumbler/aps.c Mon May 12 18:58:23 2003 @@ -44,12 +44,6 @@ #include #include -#ifdef __OpenBSD__ -#include -#else -#include -#endif - #include "dstumbler.h" #include "screen.h" @@ -98,18 +92,22 @@ add_ap(&new); +#ifndef HEADLESS redraw_aps(); +#endif if(audiomode) audio_play((!new.weped || new.weped == 2) ? SPKR_AP_PLAY_NOWEP : SPKR_AP_PLAY_WEP); +#ifndef HEADLESS if(aps_new == 0 || autosel) redraw_apinfo(); /* if we're in autoselect mode, make sure we refresh stats for this ap */ if(!nodemode && autosel) redraw_graph(); +#endif } else { @@ -138,6 +136,7 @@ if(found != aps_new || autosel) APNEW(found); +#ifndef HEADLESS redraw_aps(); if(found == aps_cur || autosel) @@ -147,6 +146,7 @@ if(!nodemode) redraw_graph(); } +#endif } if(!scanmode) @@ -178,6 +178,7 @@ return found; } +#ifndef HEADLESS /* * redraw the ap screen with all of the aps in the aps linked list */ @@ -448,6 +449,9 @@ waddch(graph_scr, ' '); } } +#endif + + /* * add ap to the linked list (along with a log of the addition) Only in /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler: aps.o Only in /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler: audio.o Only in /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler: dstumbler diff -ru /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/dstumbler.h dstumbler/dstumbler.h --- /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/dstumbler.h Mon May 12 00:33:06 2003 +++ dstumbler/dstumbler.h Tue Jun 17 17:26:21 2003 @@ -49,16 +49,16 @@ #include +#ifdef DEBUG +#include "debug.h" +#endif + #ifdef __OpenBSD__ #include #else #include #endif -#ifdef DEBUG -#include "debug.h" -#endif - #include #include "config.h" @@ -237,7 +237,9 @@ #ifdef __FreeBSD__ #define htole16(x) (x) #define le16toh(x) (x) +#ifndef O_SYNC #define O_SYNC O_FSYNC +#endif #else #ifdef __OpenBSD__ #define le16toh(x) letoh16(x) @@ -317,12 +319,12 @@ int node_scr_lines, middle_border_lines, menu_scr_cols, right_border_cols; int autosel, resolvmfg, nodemode, audiomode, menumode; int prism2, scanmode, monmode, chanlock, macreset, macint; -int ncurse, nodevice, usegps, uselog; +int ncurse, nodevice, usegps, uselog,headless; int apchange, apnew; int aps_len, aps_cur, aps_new, aps_win, aps_max, aps_lst; int nodechange, nodenew; int node_new, node_win, node_lst; -int gps_fd, sp_fd; +int gps_fd, sp_fd, min_sat_in_view; int ch, sigwinch; char *device, *gps, *logfile; FILE *log_fd; diff -ru /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/gps.c dstumbler/gps.c --- /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/gps.c Sat Feb 16 02:19:30 2002 +++ dstumbler/gps.c Tue Jun 17 17:41:46 2003 @@ -105,6 +105,10 @@ void gps_close(int fd) { + if (!usegps) + return; + usegps=0; + if(fd == -1) { alert("error: unable to close gps device: %s", strerror(errno)); @@ -156,7 +160,7 @@ /* * 3 satelites are required for a reliable gps lock */ - if(numsats < 3) + if(numsats < min_sat_in_view) { ns.dir = 'N'; ns.coordinates = 0; Only in /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler: gps.o diff -ru /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/log.c dstumbler/log.c --- /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/log.c Tue Jan 22 01:43:18 2002 +++ dstumbler/log.c Mon May 12 15:32:22 2003 @@ -40,13 +40,26 @@ #include #include +#include #include #include #include #include +#include +#include +#include +#include +#include +#include +#include + #include "dstumbler.h" +#ifndef SHELL_PATH +#define SHELL_PATH "/bin/sh" +#endif + /* * write an ap log to the logfile */ @@ -187,6 +200,187 @@ node->adhoc = 0; } +#define pdie(x) { perror(x); exit(1); } + +pid_t child_pid; +int child_fd; + +static void log_child(int fd, int port) +{ +char * wbuff[ FD_SETSIZE], lline[ 1024 ],buff[1024]; +int offset = 0, gen[ FD_SETSIZE]; +unsigned int curgen = 0; +struct sockaddr_in any; +fd_set readset,writeset,exceptset; +int s,maxfd=0,i,n; + +for(i=0; i < FD_SETSIZE;i++) + if (i != fd) close(i); + +signal(SIGHUP, SIG_DFL); +signal(SIGINT, SIG_DFL); +signal(SIGKILL, SIG_DFL); +signal(SIGPIPE, SIG_DFL); +signal(SIGALRM, SIG_DFL); +signal(SIGTERM, SIG_DFL); +signal(SIGWINCH, SIG_DFL); + +if ((s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == -1) + pdie("Could not open socket"); + +bzero((void*)&any,sizeof(any)); +any.sin_family = AF_INET; +any.sin_port = htons(port); +any.sin_addr.s_addr = INADDR_ANY; + +if (bind(s,(const struct sockaddr *)&any,sizeof(any)) == -1) + pdie("Could not bind to listen port"); + +if (listen(s,32) == -1) + pdie("Could not listen.."); + +openlog("dstumbler",LOG_PID,LOG_DAEMON); + +FD_ZERO(&readset); +FD_ZERO(&writeset); +FD_ZERO(&exceptset); + +FD_SET(s,&readset); +FD_SET(s,&exceptset); + +FD_SET(fd,&readset); +FD_SET(fd,&exceptset); + +bzero(gen,sizeof(gen)); +bzero(wbuff,sizeof(wbuff)); +maxfd = MAX(fd,s); + +syslog(LOG_INFO,"Logging child started\n"); +while(1) { + fd_set r = readset; + fd_set w = writeset; + fd_set e = exceptset; + if (select(1+maxfd,&r,&w,&e,NULL) == -1) { + if (errno == EAGAIN) + continue; + if (errno == EINTR) + continue; + syslog(LOG_ERR,"Aborting - Select failed: %s",strerror(errno)); + pdie("select"); + }; + if (FD_ISSET(s,&r)) { + struct sockaddr_in addr; + int len = sizeof(addr); + int n; + if ((n = accept(s,(struct sockaddr *)&addr,&len)) == -1) { + syslog(LOG_INFO,"Failed to accept new connection: %s",strerror(errno)); + continue; + }; + syslog(LOG_INFO,"New connection %d from %s\n",n,inet_ntoa(addr.sin_addr)); + + FD_SET(n,&writeset); + FD_SET(n,&exceptset); + FD_SET(n,&readset); /* To detect a client close */ + maxfd = MAX(n,maxfd); + + if (wbuff[i]) + free(wbuff[i]); + + wbuff[n] = NULL; + gen[n] = 0; + } + if (FD_ISSET(fd,&r)) { + int n, i, lv = 0; + n = read(fd,buff+offset,sizeof(buff)-offset); + if (n < 0) { + if ((errno=EAGAIN) || (errno == EINTR)) + continue; + syslog(LOG_ERR,"Error on logging connection, aborting: %s\n",strerror(errno)); + perror("Read error on logging com socket"); + exit(0); + }; + if (n == 0) { + syslog(LOG_ERR,"Lost logging connection, aborting.\n"); + exit(0); + }; + /* Buffer. Last write wrote from 0 .. offset, no \n seen + */ + for(i=0;i%s<\n",lline); +#endif + } + lv = i + offset; + }; + }; + if (lv == offset+i) { + offset = 0; + } else + /* Otherwise; move what we have to the start of the buffer. */ + if (lv) { + strncpy(buff,buff+lv,offset+n-lv); + offset=0; + } else { + offset += n; + }; + if (offset >= sizeof(buff)-1) + offset = 0; + } + + if (FD_ISSET(s,&e)) + pdie("Connection error on listen socket"); + + if (FD_ISSET(fd,&e)) + pdie("Connection error on logging comms socket"); + + for(i=0;i #include #include - -#ifdef __OpenBSD__ -#include -#else -#include -#endif +#include +#include #include "dstumbler.h" #include "screen.h" +#ifndef MINSATINVIEW +#define MINSATINVIEW 3 +#endif + extern char *optarg; +void +restartlogs(int s) { + s=s; + if (!uselog) + return; + log_stop(log_fd); + if (uselog && (log_fd = log_start(logfile)) == NULL) { + fprintf(stderr,"Failed to reopen the log, logging disabled.\n"); + openlog("dstumbler",LOG_CONS|LOG_PERROR|LOG_PID,LOG_USER); + syslog(LOG_ERR,"Failed to reopen the log, logging disabled.\n"); + closelog(); + uselog = 0; + } +} + /* * parse arguments and jump to ap scan loop */ @@ -63,7 +78,6 @@ main(int argc, char **argv) { int c; - /* process command line arguments */ if(argc < 2) print_usage(argv[0]); @@ -78,7 +92,7 @@ device = argv[1]; } - while((c = getopt(argc, argv, "ospnm:dg:l:")) != -1) + while((c = getopt(argc, argv, "osS:nNm:dg:l:p:")) != -1) { switch(c) { @@ -91,10 +105,20 @@ case 'n': ncurse = 0; break; + case 'N': + headless = 1; + break; case 'm': macreset = 1; macint = MAX(atoi(optarg), 0); break; + case 'S': + min_sat_in_view = atoi(optarg); + if ((min_sat_in_view<0) || (min_sat_in_view>5)) { + fprintf(stderr,"Sat in view range 0 .. 5\n"); + exit(1); + } + break; case 'd': nodevice = 1; break; @@ -102,6 +126,13 @@ usegps = 1; gps = optarg; break; + case 'p': + { FILE * fp; + if ((fp=fopen(optarg,"w"))==NULL) { perror("Cannot open pid file for writing"); exit(1); }; + fprintf(fp,"%d\n",getpid()); + fclose(fp); + }; + break; case 'l': uselog = 1; logfile = optarg; @@ -129,13 +160,25 @@ macint = 0; } + signal(SIGHUP, restartlogs); + signal(SIGINT, exitclean); + signal(SIGKILL, exitclean); + signal(SIGPIPE, exitclean); + signal(SIGALRM, exitclean); + signal(SIGTERM, exitclean); + signal(SIGWINCH, handle_sigwinch); - /* initialize curses interface and start up devices */ - init_curses(); + openlog("dstumber",LOG_PID,LOG_DAEMON); - redraw_menu(); - PRINTBANNER(); - smart_redraw(); +#ifndef HEADLESS + /* initialize curses interface and start up devices */ + if (!headless) { + init_curses(); + redraw_menu(); + PRINTBANNER(); + smart_redraw(); + } +#endif if(!nodevice) wi_start(device); @@ -162,14 +205,21 @@ void print_usage(const char *progname) { +#define xstr(s) str(s) +#define str(s) #s + fprintf(stderr, - "usage: %s [-d] [-osn] [-m ] [-g ] [-l ]\n" + "usage: %s [-d] [-osnN] [-S ] [-m ] [-g ] [-l ]\n" " -d: run dstumbler without specifying a wireless device\n" " -o: specify the use of prism2 card in monitor mode\n" " -s: disable scan mode on the card, instead do old style stat polling\n" " -n: use basic ascii characters for limited terminal fonts\n" + " -N: run headless\n" " -m: randomly set mac address at specified interval or 0 for startup\n" " -g: specify gps device to use\n" + " -p: Write pid file\n" + " -S: Minimal number of satellites in view " + "(default " xstr(MINSATINVIEW) ")\n" " -l: specify logfile to use for realtime logging\n", progname); exit(2); } @@ -186,7 +236,10 @@ void start_loop(const char *iface) { - int r, c, max_fd; + int r, max_fd; +# ifndef HEADLESS + int c; +#endif struct timeval tout, now, then; time_t start, t; fd_set rset; @@ -248,23 +301,28 @@ if(r == 0) break; +#ifndef HEADLESS else if(FD_ISSET(STDIN_FILENO, &rset) && (c = getch())) parse_cmd(c); +#endif else if(usegps && FD_ISSET(gps_fd, &rset)) gps_parse(gps_fd); +#ifndef HEADLESS if(sigwinch) refreshclean(); +#endif gettimeofday(&now, NULL); } if(nodevice) { +#ifndef HEADLESS smart_redraw(); +#endif continue; } - /* * if we're in monitor mode, grab the next packet off the wire so we can * analyze @@ -272,7 +330,9 @@ if(monmode && mon_next(iface) == -1) { SETMONCHAN(); +#ifndef HEADLESS smart_redraw(); +#endif continue; } @@ -280,27 +340,25 @@ parse_node(iface); SETMONCHAN(); +#ifndef HEADLESS smart_redraw(); +#endif apchange = apnew = 0; } } +#ifndef HEADLESS /* * initialize curses and draw windows */ void init_curses(void) { - main_scr = initscr(); + if(headless) + return; - signal(SIGHUP, exitclean); - signal(SIGINT, exitclean); - signal(SIGKILL, exitclean); - signal(SIGPIPE, exitclean); - signal(SIGALRM, exitclean); - signal(SIGTERM, exitclean); - signal(SIGWINCH, handle_sigwinch); + main_scr = initscr(); keypad(stdscr, TRUE); nodelay(stdscr, TRUE); @@ -346,6 +404,8 @@ draw_screen(void) { int i; + if (headless) + return; node_scr_lines = (nodemode ? NODE_SCR_LINES_TOGGLE : 0); middle_border_lines = (nodemode ? MIDDLE_BORDER_LINES_TOGGLE : 0); @@ -444,6 +504,7 @@ scrollok(ap_scr, TRUE); scrollok(graph_scr, TRUE); } +#endif /* * make sure all the global variables are initialized properly @@ -510,6 +571,8 @@ nodemode = 0; audiomode = 0; menumode = 0; + headless = 0; + min_sat_in_view = MINSATINVIEW; /* set chans defaults */ ch = 1; @@ -546,6 +609,7 @@ sigwinch++; } +#ifndef HEADLESS /* * handle screen refreshes and resizes when the code is worked out to do so. * make sure that this is only run once at a time, since there are often @@ -554,6 +618,10 @@ void refreshclean(void) { + if (headless) { + sigwinch = 0; + return; + } getscrmaxyx(); if(max_lines < MIN_SCREEN_Y || max_cols < MIN_SCREEN_X) @@ -634,6 +702,7 @@ sigwinch = 0; } +#endif /* * make sure if we receive a signal or ctrl+c or something, we exit cleanly @@ -644,7 +713,10 @@ { int i, j, k; - endwin(); +#ifndef HEADLESS + if (!headless) + endwin(); +#endif if(val != EXIT_WIERR && !nodevice) wi_stop(device); @@ -678,7 +750,8 @@ free(aps); - putchar('\n'); + if (!headless) + putchar('\n'); exit(val < 0 ? 2 : val); } Only in /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler: main.o diff -ru /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/menu.c dstumbler/menu.c --- /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/menu.c Sun Jan 13 00:19:02 2002 +++ dstumbler/menu.c Mon May 12 18:52:45 2003 @@ -44,15 +44,18 @@ #include #include +#ifndef HEADLESS #ifdef __OpenBSD__ #include #else #include #endif +#endif #include "dstumbler.h" #include "screen.h" +#ifndef HEADLESS /* * parse commands by the user */ @@ -61,6 +64,8 @@ { int ans; char note_buf[NOTE_BUFFERLEN]; + if(headless) + return; switch(c) { @@ -288,6 +293,8 @@ { int i, mode = 0; char menu[] = MENU; + if(headless) + return; for(i = 0; i < strlen(menu); i++) { @@ -312,6 +319,8 @@ void redraw_toggle(int toggle, int num, char chr) { + if(headless) + return; mvwaddch(top_right_border, num, 0, chr | (toggle ? BORDER_COLOR_BOLD : BORDER_COLOR)); wrefresh(top_right_border); @@ -478,3 +487,4 @@ PRINTBANNER(); } +#endif Only in /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler: menu.o diff -ru /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/misc.c dstumbler/misc.c --- /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/misc.c Sat Jan 12 17:24:00 2002 +++ dstumbler/misc.c Mon May 12 18:59:41 2003 @@ -43,6 +43,7 @@ #include #include #include +#include #include "dstumbler.h" #include "screen.h" @@ -85,6 +86,8 @@ return 0; } + +#ifndef HEADLESS /* * smart redraw function so you can mark windows for redraw and draw them when * ready @@ -93,6 +96,8 @@ smart_redraw(void) { int i = 0; + if (headless) + return; if(redraw.all && ++i) refresh(); @@ -169,6 +174,7 @@ waddch(alert_scr, ']'); redraw.alert_scr++; } +#endif /* * print alert to the alert screen and wait for user input. @@ -176,15 +182,26 @@ int alert(const char *fmt, ...) { - int i, ans; + int i, ans = 0; char buffer[ALERT_SCR_COLS - 6]; va_list ap; + /* build buffer to print to alert window */ va_start(ap, fmt); - vsnprintf(buffer, ALERT_SCR_COLS - 6, fmt, ap); +#ifndef HEADLESS + if (headless) { +#endif + vsyslog(LOG_ERR,fmt,ap); +#ifndef HEADLESS + } else { + vsnprintf(buffer, ALERT_SCR_COLS - 6, fmt, ap); + }; va_end(ap); + if (headless) + return ans; + werase(alert_scr); /* print alert */ @@ -212,4 +229,5 @@ smart_redraw(); return ans; +#endif } Only in /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler: misc.o Only in /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler: mon.o diff -ru /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/nodes.c dstumbler/nodes.c --- /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/nodes.c Tue Feb 26 12:01:31 2002 +++ dstumbler/nodes.c Mon May 12 18:56:13 2003 @@ -44,12 +44,6 @@ #include #include -#ifdef __OpenBSD__ -#include -#else -#include -#endif - #include "dstumbler.h" #include "screen.h" @@ -85,6 +79,7 @@ add_node(ap, &new); +#ifndef HEADLESS if(nodemode && ap == aps_cur) { redraw_nodes(); @@ -93,6 +88,7 @@ if(autosel) redraw_node_graph(); } +#endif } else { @@ -111,7 +107,9 @@ { aps[ap]->node[node]->keyid = new.keyid; aps[ap]->wepid = 1; +#ifndef HEADLESS redraw_aps(); +#endif } gettimeofday(&new.lastseen, NULL); @@ -136,6 +134,7 @@ if(node != node_new || autosel) NODENEW(node); +#ifndef HEADLESS if(nodemode) { redraw_nodes(); @@ -143,6 +142,7 @@ if(node == aps[aps_cur]->node_cur || autosel) redraw_node_graph(); } +#endif } } } @@ -202,8 +202,10 @@ aps[i]->node[found]->any = any ? 1 : 2; } +#ifndef HEADLESS if(nodemode) redraw_nodes(); +#endif } /* @@ -220,10 +222,13 @@ aps[i]->node[found]->srate = srate; } +#ifndef HEADLESS if(nodemode) redraw_nodes(); +#endif } +#ifndef HEADLESS /* * redraw the ap screen with all of the aps in the aps linked list */ @@ -385,6 +390,7 @@ redraw.graph_scr++; } +#endif /* * add ap to the linked list (along with a log of the addition) Only in /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler: nodes.o diff -ru /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/wistat.c dstumbler/wistat.c --- /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler/wistat.c Fri Jan 11 16:05:43 2002 +++ dstumbler/wistat.c Mon May 12 15:32:22 2003 @@ -44,12 +44,6 @@ #include #include -#ifdef __OpenBSD__ -#include -#else -#include -#endif - #include "dstumbler.h" #define wi_getval(x, y) wi_ioctl(x, y, SIOCGWAVELAN) Only in /usr/ports/net/bsd-airtools/work/bsd-airtools/dstumbler: wistat.o