Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Paul Warren
iftop
Commits
36700cef
Commit
36700cef
authored
Oct 25, 2002
by
pdw
Browse files
Added regexp based screen filtering.
parent
5624d5f6
Changes
7
Hide whitespace changes
Inline
Side-by-side
CHANGES
View file @
36700cef
Change log for iftop
$Id$
0.10
User selectable sort criteria
On-the-fly filter code changes
Shell escape
Alternative resolver back-ends
Improved totals display
0.9 22/10/02
Now works on FreeBSD
...
...
Makefile
View file @
36700cef
...
...
@@ -70,9 +70,9 @@ LDLIBS += -lpcap -lcurses -lm
SRCS
=
iftop.c addr_hash.c hash.c ns_hash.c resolver.c ui.c util.c sorted_list.c
\
options.c serv_hash.c threadprof.c edline.c
options.c serv_hash.c threadprof.c edline.c
screenfilter.c
HDRS
=
addr_hash.h hash.h iftop.h ns_hash.h resolver.h sorted_list.h ui.h options.h sll.h
\
serv_hash.h threadprof.h ether.h ip.h tcp.h
serv_hash.h threadprof.h ether.h ip.h tcp.h
screenfilter.h
TXTS
=
README CHANGES INSTALL TODO iftop.8 COPYING
SPECFILE
=
iftop.spec iftop.spec.in
...
...
options.c
View file @
36700cef
...
...
@@ -96,6 +96,7 @@ static void set_defaults() {
options
.
showhelp
=
0
;
options
.
bandwidth_in_bytes
=
0
;
options
.
sort
=
OPTION_SORT_DIV2
;
options
.
screenfilter
=
NULL
;
}
static
void
die
(
char
*
msg
)
{
...
...
options.h
View file @
36700cef
...
...
@@ -49,6 +49,8 @@ typedef struct {
int
bandwidth_in_bytes
;
option_sort_t
sort
;
char
*
screenfilter
;
}
options_t
;
#endif
/* __OPTIONS_H_ */
screenfilter.c
0 → 100644
View file @
36700cef
/*
* screenfilter.c:
*
* Copyright (c) 2002 DecisionSoft Ltd.
* Paul Warren (pdw) Fri Oct 25 10:21:00 2002
*
*/
#include <sys/types.h>
#include <regex.h>
#include <stdio.h>
#include "iftop.h"
#include "options.h"
static
const
char
rcsid
[]
=
"$Id$"
;
extern
options_t
options
;
regex_t
preg
;
int
screen_filter_set
(
char
*
s
)
{
int
r
;
if
(
options
.
screenfilter
!=
NULL
)
{
xfree
(
options
.
screenfilter
);
options
.
screenfilter
=
NULL
;
regfree
(
&
preg
);
}
r
=
regcomp
(
&
preg
,
s
,
0
);
if
(
r
==
0
)
{
options
.
screenfilter
=
s
;
return
1
;
}
else
{
xfree
(
s
);
return
0
;
}
}
int
screen_filter_match
(
char
*
s
)
{
int
r
;
if
(
options
.
screenfilter
==
NULL
)
{
return
1
;
}
r
=
regexec
(
&
preg
,
s
,
0
,
NULL
,
0
);
if
(
r
==
0
)
{
return
1
;
}
else
{
return
0
;
}
}
screenfilter.h
0 → 100644
View file @
36700cef
/*
* screenfilter.h:
*
* Copyright (c) 2002 DecisionSoft Ltd.
* Paul Warren (pdw) Fri Oct 25 10:25:50 2002
*
* RCS: $Id$
*/
#ifndef __SCREENFILTER_H_
/* include guard */
#define __SCREENFILTER_H_
int
screen_filter_set
(
char
*
s
);
int
screen_filter_match
(
char
*
s
);
#endif
/* __SCREENFILTER_H_ */
ui.c
View file @
36700cef
...
...
@@ -22,6 +22,7 @@
#include "resolver.h"
#include "sorted_list.h"
#include "options.h"
#include "screenfilter.h"
#define HOSTNAME_LENGTH 256
...
...
@@ -36,9 +37,9 @@
" s - toggle show source host h - toggle this help display\n"\
" d - toggle show destination host b - toggle bar graph display\n"\
" f - edit filter code\n"\
"Port display:
!
- s
hell command
\n"\
" R - toggle service resolution
q
-
quit
\n"\
" S - toggle show source port\n"\
"Port display:
l
- s
et screen filter
\n"\
" R - toggle service resolution
!
-
shell command
\n"\
" S - toggle show source port
q - quit
\n"\
" D - toggle show destination port\n"\
" p - toggle port display\n"\
"\n"\
...
...
@@ -450,7 +451,7 @@ void sprint_host(char * line, struct in_addr* addr, unsigned int port, unsigned
void
ui_print
()
{
sorted_list_node
*
nn
=
NULL
;
char
host
name
[
HOSTNAME_LENGTH
];
char
host
1
[
HOSTNAME_LENGTH
],
host2
[
HOSTNAME_LENGTH
];
static
char
*
line
;
static
int
lcols
;
int
y
=
0
;
...
...
@@ -482,17 +483,23 @@ void ui_print() {
while
((
y
<
LINES
-
5
)
&&
((
nn
=
sorted_list_next_item
(
&
screen_list
,
nn
))
!=
NULL
))
{
int
x
=
0
,
L
;
host_pair_line
*
screen_line
=
(
host_pair_line
*
)
nn
->
data
;
if
(
y
<
LINES
-
5
)
{
L
=
(
COLS
-
8
*
HISTORY_DIVISIONS
-
4
)
/
2
;
if
(
L
>
sizeof
hostname
)
{
L
=
sizeof
hostname
;
if
(
L
>
HOSTNAME_LENGTH
)
{
L
=
HOSTNAME_LENGTH
;
}
sprint_host
(
line
,
&
(
screen_line
->
ap
.
src
),
screen_line
->
ap
.
src_port
,
screen_line
->
ap
.
protocol
,
L
);
sprint_host
(
host1
,
&
(
screen_line
->
ap
.
src
),
screen_line
->
ap
.
src_port
,
screen_line
->
ap
.
protocol
,
L
);
sprint_host
(
host2
,
&
(
screen_line
->
ap
.
dst
),
screen_line
->
ap
.
dst_port
,
screen_line
->
ap
.
protocol
,
L
);
if
(
!
screen_filter_match
(
host1
)
&&
!
screen_filter_match
(
host2
))
{
continue
;
}
mvaddstr
(
y
,
x
,
line
);
mvaddstr
(
y
,
x
,
host1
);
x
+=
L
;
mvaddstr
(
y
,
x
,
" => "
);
...
...
@@ -500,9 +507,8 @@ void ui_print() {
x
+=
4
;
sprint_host
(
line
,
&
(
screen_line
->
ap
.
dst
),
screen_line
->
ap
.
dst_port
,
screen_line
->
ap
.
protocol
,
L
);
mvaddstr
(
y
,
x
,
line
);
mvaddstr
(
y
,
x
,
host2
);
draw_line_totals
(
y
,
screen_line
);
...
...
@@ -763,7 +769,7 @@ void ui_loop() {
case
'f'
:
{
char
*
s
;
dontshowdisplay
=
1
;
if
((
s
=
edline
(
0
,
"
F
ilter"
,
options
.
filtercode
)))
{
if
((
s
=
edline
(
0
,
"
Net f
ilter"
,
options
.
filtercode
)))
{
char
*
m
;
if
(
!
(
m
=
set_filter_code
(
s
)))
{
xfree
(
options
.
filtercode
);
...
...
@@ -784,6 +790,17 @@ void ui_loop() {
dontshowdisplay
=
0
;
break
;
}
case
'l'
:
{
char
*
s
;
dontshowdisplay
=
1
;
if
((
s
=
edline
(
0
,
"Screen filter"
,
options
.
screenfilter
)))
{
if
(
!
screen_filter_set
(
s
))
{
showhelp
(
"Invalid regexp"
);
}
}
dontshowdisplay
=
0
;
break
;
}
case
'!'
:
{
char
*
s
;
dontshowdisplay
=
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment