diff -Nru iptraf-1.2.0.orig/src/externs.h iptraf-1.2.0/src/externs.h --- iptraf-1.2.0.orig/src/externs.h Sun May 31 09:52:38 1998 +++ iptraf-1.2.0/src/externs.h Fri Jun 19 00:45:17 1998 @@ -6,14 +6,13 @@ ***/ -void ipmon(int rev_lookup, int servnames, int logging, int filtered, struct filterlist *fl, +void ipmon(const struct OPTIONS *options, int filtered, struct filterlist *fl, struct othpoptions *ofilter, unsigned int tm); void selectiface(char *ifname, int *aborted); -void ifstats(int logging, time_t logspan); -void detstats(char *iface, int logging, time_t logspan); -void servmon(char *iface, struct porttab *ports, int logging, time_t logspan, - int servnames); -void hostmon(int logging, time_t logspan); +void ifstats(const struct OPTIONS *options); +void detstats(char *iface, const struct OPTIONS *options); +void servmon(char *iface, struct porttab *ports, const struct OPTIONS *options); +void hostmon(const struct OPTIONS *options); void ethdescmgr(void); void setoptions(struct OPTIONS *options, struct porttab **ports); void loadoptions(struct OPTIONS *options); diff -Nru iptraf-1.2.0.orig/src/hostmon.c iptraf-1.2.0/src/hostmon.c --- iptraf-1.2.0.orig/src/hostmon.c Fri Jun 12 10:10:17 1998 +++ iptraf-1.2.0/src/hostmon.c Fri Jun 19 00:54:46 1998 @@ -38,6 +38,7 @@ #include "log.h" #include "timer.h" #include "ethdesc.h" +#include "options.h" #ifndef _I386_TYPES_H #include @@ -387,8 +388,9 @@ } } -void hostmon(int logging, time_t logspan) +void hostmon(const struct OPTIONS *options) { + int logging = options->logging; int fd; struct ethtab table; struct ethtabent *entry; @@ -403,6 +405,7 @@ time_t starttime; time_t now = 0; time_t statbegin = 0, startlog = 0; + time_t updtime = 0; struct desclist list; @@ -497,12 +500,15 @@ updateethrates(&table, starttime, now, idx); starttime = now; } - if (((now - startlog) >= logspan) && (logging)) { + if (((now - startlog) >= options->logspan) && (logging)) { writeethlog(table.head, now - statbegin, logfile); startlog = now; } - update_panels(); - doupdate(); + if (now - updtime >= options->updrate) { + update_panels(); + doupdate(); + updtime = now; + } } while (!endloop); if (logging) { diff -Nru iptraf-1.2.0.orig/src/ifstats.c iptraf-1.2.0/src/ifstats.c --- iptraf-1.2.0.orig/src/ifstats.c Fri Jun 12 16:48:13 1998 +++ iptraf-1.2.0/src/ifstats.c Fri Jun 19 00:54:05 1998 @@ -44,6 +44,7 @@ #include "error.h" #include "serv.h" #include "timer.h" +#include "options.h" #define SCROLLUP 0 #define SCROLLDOWN 1 @@ -337,8 +338,9 @@ } } -void ifstats(int logging, time_t logspan) +void ifstats(const struct OPTIONS *options) { + int logging = options->logging; struct iftab table; char buf[8192]; @@ -368,6 +370,7 @@ time_t statbegin = 0; time_t now = 0; time_t startlog = 0; + time_t updtime = 0; initiftab(&table); @@ -460,12 +463,15 @@ printelapsedtime(statbegin, now, LINES - 3, 1, table.borderwin); starttime = now; } - if (((now - startlog) >= logspan) && (logging)) { + if (((now - startlog) >= options->logspan) && (logging)) { writegstatlog(&table, time((time_t *) NULL) - statbegin, logfile); startlog = now; } - update_panels(); - doupdate(); + if (now - updtime >= options->updrate) { + update_panels(); + doupdate(); + updtime = now; + } } close(fd); @@ -637,8 +643,10 @@ wprintw(win, "%8d", totals->g1500); } -void detstats(char *iface, int logging, time_t logspan) +void detstats(char *iface, const struct OPTIONS *options) { + int logging = options->logging; + WINDOW *statwin; PANEL *statpanel; @@ -661,6 +669,7 @@ int ch; + time_t updtime = 0; int endloop = 0; time_t starttime, now; time_t statbegin, startlog; @@ -835,13 +844,16 @@ if (pps > peakpps) peakpps = pps; } - if (((now - startlog) >= logspan) && (logging)) { + if (((now - startlog) >= options->logspan) && (logging)) { writedstatlog(iface, activity, pps, peakactivity, peakpps, &totals, time((time_t *) NULL) - statbegin, logfile); startlog = now; } - update_panels(); - doupdate(); + if (now - updtime >= options->updrate) { + update_panels(); + doupdate(); + updtime = now; + } } close(fd); diff -Nru iptraf-1.2.0.orig/src/iptraf.c iptraf-1.2.0/src/iptraf.c --- iptraf-1.2.0.orig/src/iptraf.c Sat Jun 13 04:29:22 1998 +++ iptraf-1.2.0/src/iptraf.c Fri Jun 19 00:38:48 1998 @@ -100,25 +100,24 @@ switch (row) { case 1: - ipmon(options->revlook, options->servnames, options->logging, + ipmon(options, filtered, &fl, &ofilter, options->timeout); break; case 2: - ifstats(options->logging, options->logspan); + ifstats(options); break; case 3: selectiface(ifname, &aborted); if (!aborted) - detstats(ifname, options->logging, options->logspan); + detstats(ifname, options); break; case 4: selectiface(ifname, &aborted); if (!aborted) - servmon(ifname, ports, options->logging, options->logspan, - options->servnames); + servmon(ifname, ports, options); break; case 5: - hostmon(options->logging, options->logspan); + hostmon(options); break; case 6: tcpfilterselect(&fl, &filtered, &faborted); @@ -144,21 +143,20 @@ } else { switch (opt) { case 'i': - ipmon(options->revlook, options->servnames, options->logging, + ipmon(options, filtered, &fl, &ofilter, options->timeout); break; case 'g': - ifstats(options->logging, options->logspan); + ifstats(options); break; case 'd': - detstats(optarg, options->logging, options->logspan); + detstats(optarg, options); break; case 's': - servmon(optarg, ports, options->logging, options->logspan, - options->servnames); + servmon(optarg, ports, options); break; case 'e': - hostmon(options->logging, options->logspan); + hostmon(options); break; } } diff -Nru iptraf-1.2.0.orig/src/itrafmon.c iptraf-1.2.0/src/itrafmon.c --- iptraf-1.2.0.orig/src/itrafmon.c Sat Jun 13 16:20:08 1998 +++ iptraf-1.2.0/src/itrafmon.c Fri Jun 19 01:16:50 1998 @@ -36,6 +36,7 @@ #include "dirs.h" #include "timer.h" #include "ipfrag.h" +#include "options.h" #define SCROLLUP 0 #define SCROLLDOWN 1 @@ -262,10 +263,11 @@ * The IP Traffic Monitor */ -void ipmon(int rev_look, int servnames, int logging, int filtered, +void ipmon(const struct OPTIONS *options, int filtered, struct filterlist *fl, struct othpoptions *ofilter, unsigned int tcptm) { + int logging = options->logging; struct sockaddr_pkt fromaddr; /* iface info */ int fd; /* raw socket */ char tpacket[8192]; /* raw packet data */ @@ -279,6 +281,7 @@ time_t starttime = 0, now = 0; time_t timeint = 0; + time_t updtime = 0; WINDOW *statwin; PANEL *statpanel; @@ -330,13 +333,13 @@ init_tcp_table(&table); init_othp_table(&othptbl); - if (rev_look) + if (options->revlook) if (checkrvnamed()) open_rvn_socket(&rvnfd); else rvnfd = 0; - if (servnames) + if (options->servnames) setservent(1); ipmonhelp(); @@ -446,7 +449,7 @@ othpent = add_othp_entry(&othptbl, &table, 0, 0, NOT_IP, fromaddr.spkt_protocol, fromaddr.spkt_family, (char *) tpacket, ifname, 0, 0, - 0, logging, logfile, servnames, &nomem); + 0, logging, logfile, options->servnames, &nomem); noniptotal++; continue; @@ -488,6 +491,7 @@ * pass fragment to fragment processor * if first fragment already in { * pass sport, dport, and bytes + * } * if first frag not in; get next frame * } * DM @@ -514,9 +518,7 @@ (!(utfilter(fl, ippacket->saddr, ippacket->daddr, ntohs(sport), ntohs(dport))))) { show_ip_stats(statwin, iptotal, tcptotal, udptotal, icmptotal, noniptotal); - update_panels(); - doupdate(); - continue; + goto cont; } tcpentry = in_table(&table, ippacket->saddr, ippacket->daddr, ntohs(sport), ntohs(dport), &isclosed, @@ -546,8 +548,8 @@ (unsigned long) ippacket->saddr, (unsigned long) ippacket->daddr, sport, dport, ippacket->protocol, ifname, - rev_look, rvnfd, - servnames, &nomem); + options->revlook, rvnfd, + options->servnames, &nomem); if ((tcpentry != NULL) && (logging)) { sprintf(msgstring, "TCP: %s:%s to %s:%s first packet received ", @@ -580,15 +582,15 @@ */ if (!(tcpentry->stat & FLAG_RST)) { - if (rev_look) { + if (options->revlook) { p_sstat = tcpentry->s_fstat; p_dstat = tcpentry->d_fstat; } updateentry(&table, tcpentry, transpacket, nbplen, - br, ippacket->frag_off, logging, rev_look, + br, ippacket->frag_off, logging, options->revlook, rvnfd, logfile, &nomem); - if ((rev_look) && (((p_sstat != RESOLVED) && (tcpentry->s_fstat == RESOLVED)) || + if ((options->revlook) && (((p_sstat != RESOLVED) && (tcpentry->s_fstat == RESOLVED)) || ((p_dstat != RESOLVED) && (tcpentry->d_fstat == RESOLVED)))) { clearaddr(&table, tcpentry, screen_idx); clearaddr(&table, tcpentry->oth_connection, screen_idx); @@ -607,7 +609,7 @@ if (((tcpentry->oth_connection->finsent == 2) && /* FINed and ACKed */ (ntohl(transpacket->seq) == tcpentry->oth_connection->finack)) || - ((rev_look) && + ((options->revlook) && (((p_sstat != RESOLVED) && (tcpentry->s_fstat == RESOLVED)) || ((p_dstat != RESOLVED) && (tcpentry->d_fstat == RESOLVED))))) printentry(&table, tcpentry->oth_connection, screen_idx, mode); @@ -647,11 +649,12 @@ ippacket->saddr, ippacket->daddr, IS_IP, ippacket->protocol, 0, (char *) transpacket, ifname, - rev_look, rvnfd, tcptm, logging, logfile, - servnames, &nomem); + options->revlook, rvnfd, tcptm, logging, logfile, + options->servnames, &nomem); } } +cont: show_ip_stats(statwin, iptotal, tcptotal, udptotal, icmptotal, noniptotal); } @@ -661,13 +664,16 @@ timeint = now; } - update_panels(); - doupdate(); + if (now - updtime >= options->updrate) { + update_panels(); + doupdate(); + updtime = now; + } } killrvnamed(); - if (servnames) + if (options->servnames) endservent(); close_rvn_socket(rvnfd); diff -Nru iptraf-1.2.0.orig/src/options.c iptraf-1.2.0/src/options.c --- iptraf-1.2.0.orig/src/options.c Fri Jun 12 10:14:24 1998 +++ iptraf-1.2.0/src/options.c Fri Jun 19 01:14:26 1998 @@ -36,7 +36,7 @@ void makeoptionmenu(struct MENU *menu) { - initmenu(menu, 12, 25, 7, 15); + initmenu(menu, 13, 25, 7, 15); additem(menu, " ^R^everse DNS lookups", "Toggles resolution of IP addresses into host names"); additem(menu, " ^S^ervice names", "Displays TCP/UDP service names instead of numeric ports"); additem(menu, " ^P^romiscuous operation", "Toggles capture of all packets by Ethernet interfaces"); @@ -44,6 +44,7 @@ additem(menu, " ^L^ogging", "Toggles logging of traffic to a data file"); additem(menu, " TCP ^t^imeout...", "Determines how long TCP entries may remain idle"); additem(menu, " Logging ^i^nterval...", "Sets the time between loggings for interface, host, and service stats"); + additem(menu, " ^U^pdate rate...", "Set the screen update rate in seconds"); additem(menu, " ^A^dditional port...", "Allows you to add custom ports for the service stats"); additem(menu, " ^D^elete port...", "Deletes a port earlier added"); additem(menu, " E^x^it menu", "Return to main menu"); @@ -123,6 +124,7 @@ options->logging = 0; options->timeout = 15; options->logspan = 3600; + options->updrate = 1; } void loadoptions(struct OPTIONS *options) @@ -146,10 +148,12 @@ void updatetimes(struct OPTIONS *options, WINDOW * win) { - wmove(win, 7, 20); + wmove(win, 6, 20); wprintw(win, "%3u mins", options->timeout); - wmove(win, 8, 20); + wmove(win, 7, 20); wprintw(win, "%3u mins", options->logspan / 60); + wmove(win, 8, 20); + wprintw(win, "%3u secs", options->updrate); } void showoptions(struct OPTIONS *options, WINDOW * win) @@ -162,7 +166,7 @@ updatetimes(options, win); } -void settimeout(unsigned int *value) +void settimeout(unsigned int *value, const char *units, int allow_zero) { WINDOW *dlgwin; PANEL *dlgpanel; @@ -180,7 +184,7 @@ wattrset(dlgwin, STDATTR); wmove(dlgwin, 2, 2); - wprintw(dlgwin, "Enter value in minutes"); + wprintw(dlgwin, "Enter value in %s", units); wmove(dlgwin, 5, 2); stdkeyhelp(dlgwin); @@ -192,10 +196,10 @@ if (!aborted) { tmval = atoi(field.list->buf); - if (tmval == 0) + if (!allow_zero && tmval == 0) errbox("Invalid timeout value", ANYKEY_MSG, &resp); } - } while ((tmval == 0) && (!aborted)); + } while (!allow_zero && tmval == 0 && (!aborted)); if (!aborted) *value = tmval; @@ -219,7 +223,7 @@ makeoptionmenu(&menu); - statwin = newwin(10, 30, 7, 40); + statwin = newwin(11, 30, 7, 40); statpanel = new_panel(statwin); wattrset(statwin, BOXATTR); @@ -228,10 +232,12 @@ wmove(statwin, 0, 1); wprintw(statwin, " Enabled Options "); wattrset(statwin, STDATTR); - wmove(statwin, 7, 2); + wmove(statwin, 6, 2); wprintw(statwin, "TCP timeout:"); - wmove(statwin, 8, 2); + wmove(statwin, 7, 2); wprintw(statwin, "Log interval:"); + wmove(statwin, 8, 2); + wprintw(statwin, "Update rate:"); showoptions(options, statwin); do { @@ -256,24 +262,28 @@ options->logging = ~(options->logging); break; case 6: - settimeout(&(options->timeout)); + settimeout(&(options->timeout), "minutes", 0); updatetimes(options, statwin); break; case 7: - settimeout((unsigned int *) &(options->logspan)); + settimeout((unsigned int *) &(options->logspan), "minutes", 0); options->logspan = options->logspan * 60; updatetimes(options, statwin); break; case 8: - addmoreports(ports); + settimeout(&options->updrate, "seconds", 1); + updatetimes(options, statwin); break; case 9: + addmoreports(ports); + break; + case 10: removeaport(ports); break; } indicatesetting(row, options, statwin); - } while (row != 10); + } while (row != 11); destroymenu(&menu); del_panel(statpanel); diff -Nru iptraf-1.2.0.orig/src/options.h iptraf-1.2.0/src/options.h --- iptraf-1.2.0.orig/src/options.h Sun May 31 09:52:38 1998 +++ iptraf-1.2.0/src/options.h Fri Jun 19 00:26:19 1998 @@ -7,4 +7,5 @@ dummy:10; unsigned int timeout; unsigned int logspan; + unsigned int updrate; }; diff -Nru iptraf-1.2.0.orig/src/serv.c iptraf-1.2.0/src/serv.c --- iptraf-1.2.0.orig/src/serv.c Fri Jun 12 10:16:18 1998 +++ iptraf-1.2.0/src/serv.c Fri Jun 19 00:55:17 1998 @@ -44,6 +44,7 @@ #include "error.h" #include "log.h" #include "timer.h" +#include "options.h" #define SCROLLUP 0 #define SCROLLDOWN 1 @@ -293,9 +294,9 @@ } } -void servmon(char *ifname, struct porttab *ports, int logging, time_t logspan, - int servnames) +void servmon(char *ifname, struct porttab *ports, const struct OPTIONS *options) { + int logging = options->logging; int fd; char buf[8192]; char *ipacket; @@ -312,6 +313,7 @@ unsigned int dport = 0; time_t starttime, startlog, timeint, now; + time_t updtime = 0; int csum; int ck; @@ -331,7 +333,7 @@ update_panels(); doupdate(); - if (servnames) + if (options->servnames) setservent(1); if (logging) { @@ -400,10 +402,10 @@ (((struct iphdr *) ipacket)->protocol == IPPROTO_UDP)) { printport(&list, ((struct iphdr *) ipacket)->protocol, sport, ntohs(((struct iphdr *) ipacket)->tot_len), - idx, 0, ports, servnames); + idx, 0, ports, options->servnames); printport(&list, ((struct iphdr *) ipacket)->protocol, dport, ntohs(((struct iphdr *) ipacket)->tot_len), - idx, 1, ports, servnames); + idx, 1, ports, options->servnames); } } } @@ -413,12 +415,15 @@ printelapsedtime(starttime, now, LINES - 3, 20, list.borderwin); timeint = now; } - if (((now - startlog) >= logspan) && (logging)) { + if (((now - startlog) >= options->logspan) && (logging)) { writeutslog(list.head, now - starttime, logfile); startlog = now; } - update_panels(); - doupdate(); + if (now - updtime >= options->updrate) { + update_panels(); + doupdate(); + updtime = now; + } } while (!exitloop); if (logging) { @@ -426,7 +431,7 @@ writelog(logging, logfile, "******** TCP/UDP service monitor stopped"); fclose(logfile); } - if (servnames) + if (options->servnames) endservent(); del_panel(list.panel);