pax_global_header 0000666 0000000 0000000 00000000064 12635577042 0014525 g ustar 00root root 0000000 0000000 52 comment=70f945ac889d9a867f6dfe8f7eaa6f11a6ad7bdd
nethogs-0.8.1/ 0000775 0000000 0000000 00000000000 12635577042 0013202 5 ustar 00root root 0000000 0000000 nethogs-0.8.1/.cproject 0000664 0000000 0000000 00000076062 12635577042 0015027 0 ustar 00root root 0000000 0000000
makealltruetruetruemakealltruetruetrue
nethogs-0.8.1/.cvsignore 0000664 0000000 0000000 00000000025 12635577042 0015177 0 ustar 00root root 0000000 0000000 nethogs
decpcap_test
nethogs-0.8.1/.gitignore 0000664 0000000 0000000 00000000041 12635577042 0015165 0 ustar 00root root 0000000 0000000 nethogs
decpcap_test
TAGS
*.o
*~
nethogs-0.8.1/.project 0000664 0000000 0000000 00000004603 12635577042 0014654 0 ustar 00root root 0000000 0000000
nethogsorg.eclipse.cdt.managedbuilder.core.genmakebuilderclean,full,incremental,?name?org.eclipse.cdt.make.core.append_environmenttrueorg.eclipse.cdt.make.core.autoBuildTargetallorg.eclipse.cdt.make.core.buildArgumentsorg.eclipse.cdt.make.core.buildCommandmakeorg.eclipse.cdt.make.core.buildLocation${workspace_loc:/nethogs/Debug}org.eclipse.cdt.make.core.cleanBuildTargetcleanorg.eclipse.cdt.make.core.contentsorg.eclipse.cdt.make.core.activeConfigSettingsorg.eclipse.cdt.make.core.enableAutoBuildfalseorg.eclipse.cdt.make.core.enableCleanBuildtrueorg.eclipse.cdt.make.core.enableFullBuildtrueorg.eclipse.cdt.make.core.fullBuildTargetallorg.eclipse.cdt.make.core.stopOnErrortrueorg.eclipse.cdt.make.core.useDefaultBuildCmdtrueorg.eclipse.cdt.managedbuilder.core.ScannerConfigBuilderorg.eclipse.cdt.core.ccnatureorg.eclipse.cdt.managedbuilder.core.ScannerConfigNatureorg.eclipse.cdt.managedbuilder.core.managedBuildNatureorg.eclipse.cdt.core.cnature
nethogs-0.8.1/.travis.yml 0000664 0000000 0000000 00000000117 12635577042 0015312 0 ustar 00root root 0000000 0000000 language: cpp
addons:
apt:
packages:
- libpcap0.8-dev
script: make
nethogs-0.8.1/COPYING 0000664 0000000 0000000 00000043254 12635577042 0014245 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
nethogs-0.8.1/Changelog 0000664 0000000 0000000 00000005052 12635577042 0015016 0 ustar 00root root 0000000 0000000 Changelog
12/05/13 (muzso)
- added new command line switches:
-s Sorts output by the sent column.
-c Limits the number of updates (useful for tracemode and scripting the
output).
-v Sets view mode (0 = KB/s, 1 = total KB, 2 = total B, 3 = total MB)
- changed needrefresh default value from true to false
(upon startup there's no useful info on network usage, so displaying
any results has no use for the user)
31/08/10 (Arnout)
- support for screens wider than 80 characters, thanks to Shock
at https://bugs.launchpad.net/ubuntu/+source/nethogs/+bug/627626
10/08/08 (Arnout)
- compile with g++ 4.3, thanks to Leslie P. Polzer - skypher
08/06/08 (Arnout, thanks to MeneerJansen for sparking some activity again :) )
- add 'if (DEBUG)' to debug message
- fix compiler warning by marking some constant
strings 'const'
- set view mode to 'kbps' by default,
instead of the 'grand total' number of bytes
- some fixes thanks to Bart Martens
27/08/05 (Arnout)
- giving all unknown connections their own
`unknown' process
- Initial work on UDP support
- investigated memleak, turns out to be a problem in libc:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=273051
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=103142
18/09/04 (Arnout)
- also compile with gcc-3.4
-------------------------------------------------
17/09/04 (Arnout)
-Wrapped pcap stuff in nicer 'decpcap' module
-Support for IPv6 and PPP
-using standard C++ maps instead of custom structures
-many more code cleanups
-documentation
-split up ui code in seperate module
-------------------------------------------------
15/08/04 (Fabian)
-Totals (in curses mode)
-------------------------------------------------
29/07/04 (Fabian)
-tracemode (-t)
-------------------------------------------------
06/07/04 (Arnout)
-added support for monitoring multiple interfaces
at once
-------------------------------------------------
02/07/04 (Arnout)
-enabled 'q' for quitting
-------------------------------------------------
29/06/04 (Fabian) <-> 0.5.1
-Adding forceExit when device is ifdown
(handle was null => segfault)
-Changelog activated
-------------------------------------------------
10/05/04 (Arnout)
-cleanups
-splitting out incoming and outgoing traffic
(based on 'I/O by balance' by Fabian)
-------------------------------------------------
06/04/04 (Fabian)
-getLocal
-I/O by balance
-forceExit
-------------------------------------------------
14/02/04 (Fabian)
-Refresh delay
-Help
-Handling command-line options
-------------------------------------------------
nethogs-0.8.1/DESIGN 0000664 0000000 0000000 00000002267 12635577042 0014105 0 ustar 00root root 0000000 0000000 Rough design notitions:
decpcap handles pcap. nethogs.cpp asks to be notified of all IPv4 or IPv6
TCP packets.
the IP callbacks store the source and destination addresses into the user
data. The TCP callback makes a Packet out of it, finds the Connection
corresponding to that packet, and adds the packet to the connection.
If no connection is found, a new one is constructed, and the process
related to that connection is found though getProcess.
If needed, the screen is refreshed.
If, in getProcess, no corresponding process is found, the connection is
added to the 'unknown' process.
To prevent connections from accidentally ending up in the 'unknown' process,
and then staying there indefinitely, we should maybe walk though
the unknownproc's connections whenever the connection-to-inode table is
refreshed.
And maybe, while there are still unknown connections, the connection-to-inode
table should be updated regularly.
There are some global data structures:
connection.cpp:
connections. 'ConnList' list containting all currently known connections.
A connection removes itself from the global 'connections' list in its
destructor.
processes. 'ProcList *' containing all processes.
nethogs-0.8.1/INSTALL 0000664 0000000 0000000 00000000212 12635577042 0014226 0 ustar 00root root 0000000 0000000 make ; make install
you need the 'libpcap-dev' and 'libpcap' packages.
let me know if you have any other problems on nethogs@bzzt.net
nethogs-0.8.1/Makefile 0000664 0000000 0000000 00000004532 12635577042 0014646 0 ustar 00root root 0000000 0000000 VERSION := 0
SUBVERSION := 8
MINORVERSION := 1
#prefix := /usr
prefix := /usr/local
sbin := $(prefix)/sbin
man8 := $(prefix)/share/man/man8/
all: nethogs decpcap_test
runtests: test
./test
# nethogs_testsum
CFLAGS?=-Wall -Wextra
CXXFLAGS?=-Wall -Wextra
OBJS=packet.o connection.o process.o refresh.o decpcap.o cui.o inode2prog.o conninode.o devices.o
NCURSES_LIBS?=-lncurses
.PHONY: tgz
tgz: clean
cd .. ; tar czvf nethogs-$(VERSION).$(SUBVERSION).$(MINORVERSION).tar.gz --exclude-vcs nethogs/*
.PHONY: check
check:
echo "Not implemented"
install: nethogs nethogs.8
install -d -m 755 $(DESTDIR)$(sbin)
install -m 755 nethogs $(DESTDIR)$(sbin)
install -d -m 755 $(DESTDIR)$(man8)
install -m 644 nethogs.8 $(DESTDIR)$(man8)
test: test.cpp
$(CXX) $(CXXFLAGS) $(LDFLAGS) test.cpp -o test -lpcap -lm ${NCURSES_LIBS} -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
nethogs: main.cpp nethogs.cpp $(OBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) main.cpp $(OBJS) -o nethogs -lpcap -lm ${NCURSES_LIBS} -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
nethogs_testsum: nethogs_testsum.cpp $(OBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) nethogs_testsum.cpp $(OBJS) -o nethogs_testsum -lpcap -lm ${NCURSES_LIBS} -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
decpcap_test: decpcap_test.cpp decpcap.o
$(CXX) $(CXXFLAGS) $(LDFLAGS) decpcap_test.cpp decpcap.o -o decpcap_test -lpcap -lm
#-lefence
refresh.o: refresh.cpp refresh.h nethogs.h
$(CXX) $(CXXFLAGS) -c refresh.cpp
process.o: process.cpp process.h nethogs.h
$(CXX) $(CXXFLAGS) -c process.cpp
packet.o: packet.cpp packet.h nethogs.h
$(CXX) $(CXXFLAGS) -c packet.cpp
connection.o: connection.cpp connection.h nethogs.h
$(CXX) $(CXXFLAGS) -c connection.cpp
decpcap.o: decpcap.c decpcap.h
$(CC) $(CFLAGS) -c decpcap.c
inode2prog.o: inode2prog.cpp inode2prog.h nethogs.h
$(CXX) $(CXXFLAGS) -c inode2prog.cpp
conninode.o: conninode.cpp nethogs.h conninode.h
$(CXX) $(CXXFLAGS) -c conninode.cpp
#devices.o: devices.cpp devices.h
# $(CXX) $(CXXFLAGS) -c devices.cpp
cui.o: cui.cpp cui.h nethogs.h
$(CXX) $(CXXFLAGS) -c cui.cpp -DVERSION=\"$(VERSION)\" -DSUBVERSION=\"$(SUBVERSION)\" -DMINORVERSION=\"$(MINORVERSION)\"
.PHONY: clean
clean:
rm -f $(OBJS)
rm -f nethogs
rm -f test
rm -f decpcap_test
nethogs-0.8.1/README.decpcap.txt 0000664 0000000 0000000 00000005113 12635577042 0016276 0 ustar 00root root 0000000 0000000 This is a brainstorm about a libpcap-wrapper.
It should make it possible to add callbacks requesting specific packets, for example asking
for all TCP packets, whether they are sent over IPv4 or IPv6.
Return value of the callback specifies of the packet should 'fall through', i.e.,
if it should be sent to other callbacks, too.
give the programmer the opportunity to let packages re-enter the 'stream'.
Callbacks should be called from high to low level. When a callback returns 'true', no lower
callbacks should be called. The payload is available in a nice struct (union?), too.
= Examples - how it'd work =
== For the developers of the lib ==
When the sniffer is started, we learn what kind of packets are on the wire
(ethernet, ppp, etc) and start pcap. Whenever a packet arrives, it is parsed.
After parsing, if a callback is defined for this type of packet, the callback
is pushed onto a stack. After that the payload is parsed. This goes on until
the payload is, as far as we're concerned, raw data. Then the callbacks on
the stack are called, until one of them returns 'true' ('done parsing this
packet')
Undefined callbacks move the parser to the next level.
-- alternatively --
When the sniffer is started, we learn what kind of packets are on the wire
(ethernet, ppp, etc) and start pcap. Whenever a packet arrives, it is parsed.
After parsing, if a callback is defined for this type of packet, that
callback is called. If it returns 'true', the packet is 'done', and discarded.
If it returns 'false', it's passed on to the next level, leaving any changes
to the user data intact.
== For the users of the lib ==
If you want to sniff only tcp packets, add a callback for the 'packet_tcp'
packet type. If you also want to count the total amount of IP traffic, make
sure the 'packet_tcp' handler returns 'false' - that means after the tcp
callback the packet will go on and be presented to the IP callback also.
If you want to sniff specifically IPv4 TCP packets, you add a callback for
IPv4 that calls the function to parse the payload directly, and then returns
'false'.
If you modify the 'user' data in top-level callbacks which return 'false',
-- alternatively --
If you want to sniff only tcp packets, simply only add a callback for
'dp_packet_tcp'. If, on top of that, you also want to count the total amount
of IP traffic, make sure it returns 'false' and return.
If you want to sniff specifically IPv4 TCP packets, you can do 2 things:
add a 'true'-returning callback to everything else apart from IPv4 (which
is ugly), or only add a callback for IPv4 and call the TCP-parsing code
by hand.
nethogs-0.8.1/README.md 0000664 0000000 0000000 00000003146 12635577042 0014465 0 ustar 00root root 0000000 0000000 Nethogs
=======
[](https://travis-ci.org/raboof/nethogs)
http://nethogs.sf.net
Introduction
------------
NetHogs is a small 'net top' tool. Instead of breaking the traffic down per protocol or per subnet, like most tools do, it groups bandwidth by process. NetHogs does not rely on a special kernel module to be loaded. If there's suddenly a lot of network traffic, you can fire up NetHogs and immediately see which PID is causing this. This makes it easy to indentify programs that have gone wild and are suddenly taking up your bandwidth.
Since NetHogs heavily relies on /proc, it currently runs on Linux only.
Status
------
Nethogs is a mature piece of software included in most Linux distributions.
Ideas for features, as well as open bugs, can be found at https://github.com/raboof/nethogs/issues
Coding standards
----------------
Can anyone recommend a sensible set? :)
For now:
* '{'
* on a new line for function definitions
* on a new line for enums
* on the same line for conditionals/loops
* omitted when possible
* use tab for indentation
* use doxygen/javadoc-style comments.
* for multiline doxygen docs, add a newline after '/**'
* case
* classes: camelcased, start uppercase
* enums: camelcased, start uppercase
* functions: camelcased, start lowercase
* local variables: camelcased, start lowercase
License
-------
Copyright 2004-2005, 2008, 2010-2012, 2015 Arnout Engelen
License: nethogs may be redistributed under the terms of the GPLv2 or any
later version. See the COPYING file for the license text.
nethogs-0.8.1/connection.cpp 0000664 0000000 0000000 00000012504 12635577042 0016047 0 ustar 00root root 0000000 0000000 /*
* connection.cpp
*
* Copyright (c) 2004-2006,2008 Arnout Engelen
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include
#include
#include
#include "nethogs.h"
#include "connection.h"
#include "process.h"
ConnList * connections = NULL;
void PackList::add (Packet * p)
{
if (content == NULL)
{
content = new PackListNode (new Packet (*p));
return;
}
if (content->val->time.tv_sec == p->time.tv_sec)
{
content->val->len += p->len;
return;
}
/* store copy of packet, so that original may be freed */
content = new PackListNode(new Packet (*p), content);
}
/* sums up the total bytes used and removes 'old' packets */
u_int32_t PackList::sumanddel (timeval t)
{
u_int32_t retval = 0;
PackListNode * current = content;
PackListNode * previous = NULL;
while (current != NULL)
{
//std::cout << "Comparing " << current->val->time.tv_sec << " <= " << t.tv_sec - PERIOD << endl;
if (current->val->time.tv_sec <= t.tv_sec - PERIOD)
{
if (current == content)
content = NULL;
else if (previous != NULL)
previous->next = NULL;
delete current;
return retval;
}
retval += current->val->len;
previous = current;
current = current->next;
}
return retval;
}
/* packet may be deleted by caller */
Connection::Connection (Packet * packet)
{
assert (packet != NULL);
connections = new ConnList (this, connections);
sent_packets = new PackList ();
recv_packets = new PackList ();
sumSent = 0;
sumRecv = 0;
if (DEBUG)
{
std::cout << "New connection, with package len " << packet->len << std::endl;
}
if (packet->Outgoing())
{
sumSent += packet->len;
sent_packets->add(packet);
refpacket = new Packet (*packet);
} else {
sumRecv += packet->len;
recv_packets->add(packet);
refpacket = packet->newInverted();
}
lastpacket = packet->time.tv_sec;
if (DEBUG)
std::cout << "New reference packet created at " << refpacket << std::endl;
}
Connection::~Connection ()
{
if (DEBUG)
std::cout << "Deleting connection" << std::endl;
/* refpacket is not a pointer to one of the packets in the lists
* so deleted */
delete (refpacket);
if (sent_packets != NULL)
delete sent_packets;
if (recv_packets != NULL)
delete recv_packets;
ConnList * curr_conn = connections;
ConnList * prev_conn = NULL;
while (curr_conn != NULL)
{
if (curr_conn->getVal() == this)
{
ConnList * todelete = curr_conn;
curr_conn = curr_conn->getNext();
if (prev_conn == NULL)
{
connections = curr_conn;
} else {
prev_conn->setNext(curr_conn);
}
delete (todelete);
}
else
{
prev_conn = curr_conn;
curr_conn = curr_conn->getNext();
}
}
}
/* the packet will be freed by the calling code */
void Connection::add (Packet * packet)
{
lastpacket = packet->time.tv_sec;
if (packet->Outgoing())
{
if (DEBUG)
{
std::cout << "Outgoing: " << packet->len << std::endl;
}
sumSent += packet->len;
sent_packets->add (packet);
}
else
{
if (DEBUG)
{
std::cout << "Incoming: " << packet->len << std::endl;
}
sumRecv += packet->len;
if (DEBUG)
{
std::cout << "sumRecv now: " << sumRecv << std::endl;
}
recv_packets->add (packet);
}
}
Connection * findConnectionWithMatchingSource(Packet * packet) {
assert(packet->Outgoing());
ConnList * current = connections;
while (current != NULL)
{
/* the reference packet is always outgoing */
if (packet->matchSource(current->getVal()->refpacket))
{
return current->getVal();
}
current = current->getNext();
}
return NULL;
}
Connection * findConnectionWithMatchingRefpacketOrSource(Packet * packet) {
ConnList * current = connections;
while (current != NULL)
{
/* the reference packet is always *outgoing* */
if (packet->match(current->getVal()->refpacket))
{
return current->getVal();
}
current = current->getNext();
}
return findConnectionWithMatchingSource(packet);
}
/*
* finds connection to which this packet belongs.
* a packet belongs to a connection if it matches
* to its reference packet
*/
Connection * findConnection (Packet * packet)
{
if (packet->Outgoing())
return findConnectionWithMatchingRefpacketOrSource(packet);
else
{
Packet * invertedPacket = packet->newInverted();
Connection * result = findConnectionWithMatchingRefpacketOrSource(invertedPacket);
delete invertedPacket;
return result;
}
}
/*
* Connection::sumanddel
*
* sums up the total bytes used
* and removes 'old' packets.
*
* Returns sum of sent packages (by address)
* sum of recieved packages (by address)
*/
void Connection::sumanddel (timeval t, u_int32_t * recv, u_int32_t * sent)
{
(*sent)=(*recv)=0;
*sent = sent_packets->sumanddel(t);
*recv = recv_packets->sumanddel(t);
}
nethogs-0.8.1/connection.h 0000664 0000000 0000000 00000005045 12635577042 0015516 0 ustar 00root root 0000000 0000000 /*
* connection.h
*
* Copyright (c) 2004-2006,2008 Arnout Engelen
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef __CONNECTION_H
#define __CONNECTION_H
#include
#include "packet.h"
class PackListNode
{
public:
PackListNode (Packet * m_val, PackListNode * m_next = NULL)
{
val = m_val;
next = m_next;
}
~PackListNode ()
{
delete val;
if (next != NULL)
delete next;
}
PackListNode * next;
Packet * val;
};
class PackList
{
public:
PackList ()
{
content = NULL;
}
PackList (Packet * m_val)
{
assert (m_val != NULL);
content = new PackListNode(m_val);
}
~PackList ()
{
if (content != NULL)
delete content;
}
/* sums up the total bytes used and removes 'old' packets */
u_int32_t sumanddel (timeval t);
/* calling code may delete packet */
void add (Packet * p);
private:
PackListNode * content;
};
class Connection
{
public:
/* constructs a connection, makes a copy of
* the packet as 'refpacket', and adds the
* packet to the packlist */
/* packet may be deleted by caller */
Connection (Packet * packet);
~Connection();
/* add a packet to the packlist
* will delete the packet structure
* when it is 'merged with' (added to) another
* packet
*/
void add (Packet * packet);
int getLastPacket ()
{ return lastpacket; }
/* sums up the total bytes used
* and removes 'old' packets. */
void sumanddel(timeval curtime, u_int32_t * recv, u_int32_t * sent);
/* for checking if a packet is part of this connection */
/* the reference packet is always *outgoing*. */
Packet * refpacket;
/* total sum or sent/received bytes */
u_int32_t sumSent;
u_int32_t sumRecv;
private:
PackList * sent_packets;
PackList * recv_packets;
int lastpacket;
};
/* Find the connection this packet belongs to */
/* (the calling code may free the packet afterwards) */
Connection * findConnection (Packet * packet);
#endif
nethogs-0.8.1/conninode.cpp 0000664 0000000 0000000 00000013523 12635577042 0015666 0 ustar 00root root 0000000 0000000 /*
* conninode.cpp
*
* Copyright (c) 2008,2009 Arnout Engelen
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include
#include