!3 package init

From: @wangyueliang
Reviewed-by: 
Signed-off-by:
This commit is contained in:
openeuler-ci-bot 2021-03-24 20:01:23 +08:00 committed by Gitee
commit e336e30ade
9 changed files with 1300 additions and 73 deletions

339
LICENSE Normal file
View File

@ -0,0 +1,339 @@
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.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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.
<signature of Ty Coon>, 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.

View File

@ -1,36 +0,0 @@
# iftop
#### Description
display bandwidth usage on an interface
#### Software Architecture
Software architecture description
#### Installation
1. xxxx
2. xxxx
3. xxxx
#### Instructions
1. xxxx
2. xxxx
3. xxxx
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

View File

@ -1,37 +0,0 @@
# iftop
#### 介绍
display bandwidth usage on an interface
#### 软件架构
软件架构说明
#### 安装教程
1. xxxx
2. xxxx
3. xxxx
#### 使用说明
1. xxxx
2. xxxx
3. xxxx
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 码云特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

63
iftop-1.0-gcc10.patch Normal file
View File

@ -0,0 +1,63 @@
Patch by Robert Scheck <robert@fedoraproject.org> for iftop <= 1.0pre4 to avoid a
GCC 10 related build failure due to global variables in a header file with omitted
"extern" declaration, see also: https://gcc.gnu.org/gcc-10/porting_to.html
Example build failure output:
/usr/bin/ld: ui_common.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:36: multiple definition of `screen_list'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:36: first defined here
/usr/bin/ld: ui_common.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: multiple definition of `peaktotal'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: first defined here
/usr/bin/ld: ui_common.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: multiple definition of `peakrecv'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: first defined here
/usr/bin/ld: ui_common.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: multiple definition of `peaksent'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: first defined here
/usr/bin/ld: ui_common.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:37: multiple definition of `totals'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:37: first defined here
/usr/bin/ld: ui_common.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:40: multiple definition of `screen_hash'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:40: first defined here
/usr/bin/ld: ui_common.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:41: multiple definition of `service_hash'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:41: first defined here
/usr/bin/ld: ui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:36: multiple definition of `screen_list'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:36: first defined here
/usr/bin/ld: ui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: multiple definition of `peaksent'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: first defined here
/usr/bin/ld: ui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: multiple definition of `peakrecv'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: first defined here
/usr/bin/ld: ui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: multiple definition of `peaktotal'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: first defined here
/usr/bin/ld: ui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:37: multiple definition of `totals'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:37: first defined here
/usr/bin/ld: ui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:40: multiple definition of `screen_hash'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:40: first defined here
/usr/bin/ld: ui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:41: multiple definition of `service_hash'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:41: first defined here
/usr/bin/ld: tui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:36: multiple definition of `screen_list'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:36: first defined here
/usr/bin/ld: tui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:37: multiple definition of `totals'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:37: first defined here
/usr/bin/ld: tui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: multiple definition of `peaksent'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: first defined here
/usr/bin/ld: tui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: multiple definition of `peakrecv'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: first defined here
/usr/bin/ld: tui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: multiple definition of `peaktotal'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:38: first defined here
/usr/bin/ld: tui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:40: multiple definition of `screen_hash'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:40: first defined here
/usr/bin/ld: tui.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:41: multiple definition of `service_hash'; iftop.o:/builddir/build/BUILD/iftop-1.0pre4/ui_common.h:41: first defined here
collect2: error: ld returned 1 exit status
--- iftop-1.0pre4/ui_common.h 2020-02-02 23:58:40.104880963 +0100
+++ iftop-1.0pre4/ui_common.h.gcc10 2020-02-02 23:59:36.822197955 +0100
@@ -33,12 +33,12 @@
extern options_t options;
-sorted_list_type screen_list;
-host_pair_line totals;
-int peaksent, peakrecv, peaktotal;
+extern sorted_list_type screen_list;
+extern host_pair_line totals;
+extern int peaksent, peakrecv, peaktotal;
extern history_type history_totals;
-hash_type* screen_hash;
-hash_type* service_hash;
+extern hash_type* screen_hash;
+extern hash_type* service_hash;
void analyse_data(void);
void screen_list_init(void);
--- iftop-1.0pre4/ui_common.c 2020-02-02 23:58:40.104880963 +0100
+++ iftop-1.0pre4/ui_common.c.gcc10 2020-02-03 00:06:14.604323838 +0100
@@ -27,6 +27,12 @@
[OPTION_BW_PKTS] = { "p", "Kp", "Mp", "GB"},
};
+sorted_list_type screen_list;
+host_pair_line totals;
+int peaksent, peakrecv, peaktotal;
+hash_type* screen_hash;
+hash_type* service_hash;
+
extern hash_type* history;
extern int history_pos;
extern int history_len;

826
iftop-1.0-git20181003.patch Normal file
View File

@ -0,0 +1,826 @@
--- iftop-1.0pre4/addrs_dlpi.c 2003-10-15 00:33:45.000000000 +0200
+++ iftop-1.0pre4/addrs_dlpi.c.git20181003 2019-07-28 01:42:14.022500086 +0200
@@ -50,7 +50,7 @@
*/
int
-get_addrs_dlpi(char *interface, char if_hw_addr[], struct in_addr *if_ip_addr)
+get_addrs_dlpi(char *interface, u_int8_t if_hw_addr[], struct in_addr *if_ip_addr)
{
int got_hw_addr = 0;
int got_ip_addr = 0;
--- iftop-1.0pre4/addrs_ioctl.c 2014-01-05 19:46:37.000000000 +0100
+++ iftop-1.0pre4/addrs_ioctl.c.git20181003 2019-07-28 01:42:14.022500086 +0200
@@ -45,7 +45,7 @@
*/
int
-get_addrs_ioctl(char *interface, char if_hw_addr[], struct in_addr *if_ip_addr, struct in6_addr *if_ip6_addr)
+get_addrs_ioctl(char *interface, u_int8_t if_hw_addr[], struct in_addr *if_ip_addr, struct in6_addr *if_ip6_addr)
{
int s;
struct ifreq ifr = {};
--- iftop-1.0pre4/addrs_ioctl.h 2014-01-05 20:15:09.000000000 +0100
+++ iftop-1.0pre4/addrs_ioctl.h.git20181003 2019-07-28 01:42:14.022500086 +0200
@@ -7,6 +7,6 @@
#define __ADDRS_IOCTL_H_
int
-get_addrs_ioctl(char *interface, char if_hw_addr[], struct in_addr *if_ip_addr, struct in6_addr *if_ip6_addr);
+get_addrs_ioctl(char *interface, u_int8_t if_hw_addr[], struct in_addr *if_ip_addr, struct in6_addr *if_ip6_addr);
#endif /* __ADDRS_IOCTL_H_ */
--- iftop-1.0pre4/cfgfile.c 2014-01-05 19:47:07.000000000 +0100
+++ iftop-1.0pre4/cfgfile.c.git20181003 2019-07-28 01:42:14.022500086 +0200
@@ -30,7 +30,8 @@
"promiscuous",
"hide-source",
"hide-destination",
- "use-bytes",
+ "use-bytes",
+ "bandwidth-unit",
"sort",
"line-display",
"show-totals",
--- iftop-1.0pre4/ChangeLog 2014-01-19 21:32:50.000000000 +0100
+++ iftop-1.0pre4/ChangeLog.git20181003 2019-07-28 01:42:14.021500079 +0200
@@ -1,11 +1,26 @@
Change log for iftop
-$Id: ChangeLog,v 1.42 2014/01/19 20:32:50 pdw Exp $
Attributions apply to all preceding items up to the next blank line.
Unattributed items are by Paul Warren and Chris Lightfoot.
+
1.0
+* Choose first running interface, rather than first "up" interface (Redhat #1403025)
+ Robert Scheck <robert@fedoraproject.org>
+
+* Support for unlimited number of lines of output for text mode
+ Roman Hoog Antink <rha@open.ch>
+
+* Fix handling of short packets
+ Frédéric Perrin <fperrin@brocade.com>
+
+* Fix MAC address display
+ Kevin Darbyshire-Bryant <kevin@darbyshire-bryant.me.uk>
+
+* Clean up libpcap on exit
+ Brian Russell <brian.russell@brocade.com>
+
* Remove blinking cursor from UI
Gerrit Renker <renker@ualberta.ca>
--- iftop-1.0pre4/iftop.8 2014-01-05 18:22:39.000000000 +0100
+++ iftop-1.0pre4/iftop.8.git20181003 2019-07-28 01:42:14.024500101 +0200
@@ -3,7 +3,7 @@
.\" iftop.8:
.\" Manual page for iftop.
.\"
-.\" $Id: iftop.8,v 1.31 2014/01/05 17:22:39 pdw Exp $
+.\" $Id$
.\"
.SH NAME
@@ -11,7 +11,7 @@
.SH SYNOPSIS
\fBiftop\fP \fB-h\fP |
-[\fB-nNpblBP\fP] [\fB-i\fP \fIinterface\fP] [\fB-f\fP \fIfilter code\fP] [\fB-F\fP \fInet\fP/\fImask\fP]
+[\fB-nNpblP\fP] [\fB-u\fP \fIunit\fP] [\fB-i\fP \fIinterface\fP] [\fB-f\fP \fIfilter code\fP] [\fB-F\fP \fInet\fP/\fImask\fP]
[\fB-G\fP \fInet6\fP/\fImask6\fP]
.SH DESCRIPTION
\fBiftop\fP listens to network traffic on a named \fIinterface\fP, or on the
@@ -75,8 +75,11 @@
\fB-m\fP \fIlimit\fP
Set the upper limit for the bandwidth scale. Specified as a number with a 'K', 'M' or 'G' suffix.
.TP
+\fB-u\fP \fIbits\fP|\fIbytes\fP|\fIpackets\fP
+Display bandwidth rates in the given unit (per second).
+.TP
\fB-B\fP
-Display bandwidth rates in bytes/sec rather than bits/sec.
+Synonym for \fB-u\fP \fIbits\fP.
.TP
\fB-i\fP \fIinterface\fP
Listen to packets on \fIinterface\fP.
@@ -236,8 +239,11 @@
\fBhide-destination:\fP \fI(yes|no)\fP
Hides destination host names.
.TP
+\fBbandwidth-unit:\fP \fI(bits|bytes|packets)\fP
+Use the specified unit for bandwidth display. The default is bits.
+.TP
\fBuse-bytes:\fP \fI(yes|no)\fP
-Use bytes for bandwidth display, rather than bits.
+\fBuse-bytes: yes\fP is a synonym of \fBbandwidth-unit: packets\fP.
.TP
\fBsort:\fP \fI(2s|10s|40s|source|destination)\fP
Sets which column is used to sort the display.
@@ -315,7 +321,7 @@
Paul Warren <pdw@ex-parrot.com>
.SH VERSION
-$Id: iftop.8,v 1.31 2014/01/05 17:22:39 pdw Exp $
+$Id$
.SH COPYING
This program is free software; you can redistribute it and/or modify
--- iftop-1.0pre4/iftop.c 2014-01-19 21:21:19.000000000 +0100
+++ iftop-1.0pre4/iftop.c.git20181003 2019-07-28 01:42:14.024500101 +0200
@@ -55,7 +55,7 @@
/* ethernet address of interface. */
int have_hw_addr = 0;
-char if_hw_addr[6];
+u_int8_t if_hw_addr[6];
/* IP address of interface */
int have_ip_addr = 0;
@@ -146,7 +146,7 @@
if(t - last_timestamp >= RESOLUTION) {
analyse_data();
if (options.no_curses) {
- if (!options.timed_output || (options.timed_output && t - first_timestamp >= options.timed_output)) {
+ if (!options.timed_output || (t - first_timestamp >= options.timed_output)) {
tui_print();
if (options.timed_output) {
finish(SIGINT);
@@ -249,16 +249,16 @@
}
}
-static void handle_ip_packet(struct ip* iptr, int hw_dir)
+static void handle_ip_packet(struct ip* iptr, int hw_dir, int pld_len)
{
int direction = 0; /* incoming */
+ int len;
history_type* ht;
union {
history_type **ht_pp;
void **void_pp;
} u_ht = { &ht };
addr_pair ap;
- unsigned int len = 0;
struct in6_addr scribdst; /* Scratch pad. */
struct in6_addr scribsrc; /* Scratch pad. */
/* Reinterpret packet type. */
@@ -268,7 +268,21 @@
tick(0);
- if( (IP_V(iptr) ==4 && options.netfilter == 0)
+ /*
+ * Sanity check: drop obviously short packets.
+ * pld_len comes from pcaphdr->len - sizeof(struct l2_header).
+ *
+ * It is assumed that the snaplen (currently hard-coded to 1000) is
+ * big enough to always capture the IP header past the L2 encap, and
+ * that pcap never truncates the packet to less than snaplen; in
+ * other words, that pcaphdr->caplen = MIN(pcaphdr->len, snaplen).
+ */
+ if (pld_len < sizeof (struct ip))
+ return;
+ if (IP_V(iptr) == 6 && pld_len < sizeof (struct ip6_hdr))
+ return;
+
+ if( (IP_V(iptr) == 4 && options.netfilter == 0)
|| (IP_V(iptr) == 6 && options.netfilter6 == 0) ) {
/*
* Net filter is off, so assign direction based on MAC address
@@ -424,21 +438,22 @@
break;
}
-
if(hash_find(history, &ap, u_ht.void_pp) == HASH_STATUS_KEY_NOT_FOUND) {
ht = history_create();
hash_insert(history, &ap, ht);
}
/* Do accounting. */
- switch (IP_V(iptr)) {
- case 4:
- len = ntohs(iptr->ip_len);
- break;
- case 6:
- len = ntohs(ip6tr->ip6_plen) + 40;
+ switch (options.bandwidth_unit) {
+ case OPTION_BW_BITS:
+ case OPTION_BW_BYTES:
+ len = pld_len;
+ break;
+ case OPTION_BW_PKTS:
+ len = 1;
+ break;
default:
- break;
+ return;
}
/* Update record */
@@ -468,7 +483,7 @@
static void handle_raw_packet(unsigned char* args, const struct pcap_pkthdr* pkthdr, const unsigned char* packet)
{
- handle_ip_packet((struct ip*)packet, -1);
+ handle_ip_packet((struct ip*)packet, -1, pkthdr->len);
}
#ifdef DLT_PFLOG
@@ -482,18 +497,19 @@
hdrlen = BPF_WORDALIGN(hdr->length);
length -= hdrlen;
packet += hdrlen;
- handle_ip_packet((struct ip*)packet, -1);
+ handle_ip_packet((struct ip*)packet, -1, length);
}
#endif
static void handle_null_packet(unsigned char* args, const struct pcap_pkthdr* pkthdr, const unsigned char* packet)
{
- handle_ip_packet((struct ip*)(packet + 4), -1);
+ handle_ip_packet((struct ip*)(packet + 4), -1, pkthdr->len);
}
-static void handle_llc_packet(const struct llc* llc, int dir) {
-
- struct ip* ip = (struct ip*)((void*)llc + sizeof(struct llc));
+static void handle_llc_packet(const struct llc* llc, int dir, int llclen) {
+ int hdrlen = sizeof(struct llc);
+ int pldlen = llclen - hdrlen;
+ struct ip* ip = (struct ip*)((void*)llc + hdrlen);
/* Taken from tcpdump/print-llc.c */
if(llc->ssap == LLCSAP_SNAP && llc->dsap == LLCSAP_SNAP
@@ -505,11 +521,11 @@
switch(orgcode) {
case OUI_ENCAP_ETHER:
case OUI_CISCO_90:
- handle_ip_packet(ip, dir);
+ handle_ip_packet(ip, dir, pldlen);
break;
case OUI_APPLETALK:
if(et == ETHERTYPE_ATALK) {
- handle_ip_packet(ip, dir);
+ handle_ip_packet(ip, dir, pldlen);
}
break;
default:;
@@ -521,34 +537,36 @@
static void handle_tokenring_packet(unsigned char* args, const struct pcap_pkthdr* pkthdr, const unsigned char* packet)
{
struct token_header *trp;
+ int hdrlen = 0;
int dir = -1;
trp = (struct token_header *)packet;
if(IS_SOURCE_ROUTED(trp)) {
- packet += RIF_LENGTH(trp);
+ hdrlen += RIF_LENGTH(trp);
}
- packet += TOKEN_HDRLEN;
+ hdrlen += TOKEN_HDRLEN;
+ packet += hdrlen;
if(memcmp(trp->token_shost, if_hw_addr, 6) == 0 ) {
/* packet leaving this i/f */
dir = 1;
- }
- else if(memcmp(trp->token_dhost, if_hw_addr, 6) == 0 || memcmp("\xFF\xFF\xFF\xFF\xFF\xFF", trp->token_dhost, 6) == 0) {
+ }
+ else if(memcmp(trp->token_dhost, if_hw_addr, 6) == 0 || memcmp("\xFF\xFF\xFF\xFF\xFF\xFF", trp->token_dhost, 6) == 0) {
/* packet entering this i/f */
dir = 0;
}
/* Only know how to deal with LLC encapsulated packets */
if(FRAME_TYPE(trp) == TOKEN_FC_LLC) {
- handle_llc_packet((struct llc*)packet, dir);
+ handle_llc_packet((struct llc*)packet, dir, pkthdr->len - hdrlen);
}
}
static void handle_ppp_packet(unsigned char* args, const struct pcap_pkthdr* pkthdr, const unsigned char* packet)
{
- register u_int length = pkthdr->len;
- register u_int caplen = pkthdr->caplen;
- u_int proto;
+ register u_int length = pkthdr->len;
+ register u_int caplen = pkthdr->caplen;
+ u_int proto;
if (caplen < 2)
return;
@@ -558,14 +576,14 @@
return;
packet += 2;
- length -= 2;
+ length -= 2;
proto = EXTRACT_16BITS(packet);
packet += 2;
length -= 2;
if(proto == PPP_IP || proto == ETHERTYPE_IP || proto == ETHERTYPE_IPV6) {
- handle_ip_packet((struct ip*)packet, -1);
+ handle_ip_packet((struct ip*)packet, -1, length);
}
}
}
@@ -588,24 +606,25 @@
dir=1;
break;
}
- handle_ip_packet((struct ip*)(packet+SLL_HDR_LEN), dir);
+ handle_ip_packet((struct ip*)(packet+SLL_HDR_LEN), dir,
+ thdr->len - SLL_HDR_LEN);
}
#endif /* DLT_LINUX_SLL */
static void handle_eth_packet(unsigned char* args, const struct pcap_pkthdr* pkthdr, const unsigned char* packet)
{
struct ether_header *eptr;
- int ether_type;
- const unsigned char *payload;
+ int ether_type, hdrlen;
+
eptr = (struct ether_header*)packet;
ether_type = ntohs(eptr->ether_type);
- payload = packet + sizeof(struct ether_header);
+ hdrlen = sizeof(struct ether_header);
if(ether_type == ETHERTYPE_8021Q) {
struct vlan_8021q_header* vptr;
- vptr = (struct vlan_8021q_header*)payload;
+ vptr = (struct vlan_8021q_header*) (packet + hdrlen);
ether_type = ntohs(vptr->ether_type);
- payload += sizeof(struct vlan_8021q_header);
+ hdrlen += sizeof(struct vlan_8021q_header);
}
if(ether_type == ETHERTYPE_IP || ether_type == ETHERTYPE_IPV6) {
@@ -629,8 +648,8 @@
}
/* Distinguishing ip_hdr and ip6_hdr will be done later. */
- iptr = (struct ip*)(payload); /* alignment? */
- handle_ip_packet(iptr, dir);
+ iptr = (struct ip*) (packet + hdrlen); /* alignment? */
+ handle_ip_packet(iptr, dir, pkthdr->len - hdrlen);
}
}
@@ -643,7 +662,8 @@
{
/* 802.11 MAC header is = 34 bytes (not sure if that's universally true) */
/* We could try harder to figure out hardware direction from the MAC header */
- handle_ip_packet((struct ip*)(packet + ((struct radiotap_header *)packet)->it_len + 34),-1);
+ int hdrlen = ((struct radiotap_header *)packet)->it_len + 34;
+ handle_ip_packet((struct ip*)(packet + hdrlen), -1, pkthdr->len - hdrlen);
}
@@ -839,6 +859,8 @@
}
pthread_cancel(thread);
+ pthread_join(thread, NULL);
+ pcap_close(pd);
ui_finish();
--- iftop-1.0pre4/options.c 2014-01-19 21:16:43.000000000 +0100
+++ iftop-1.0pre4/options.c.git20181003 2019-07-28 01:42:14.025500109 +0200
@@ -30,7 +30,7 @@
options_t options;
-char optstr[] = "+i:f:nNF:G:lhpbBPm:c:s:tL:o:";
+char optstr[] = "+i:f:nNF:G:lhpbBu:Pm:c:s:tL:o:";
/* Global options. */
@@ -75,6 +75,13 @@
{ NULL, -1 }
};
+config_enumeration_type bandwidth_unit_enumeration[] = {
+ { "bits", OPTION_BW_BITS },
+ { "bytes", OPTION_BW_BYTES },
+ { "packets", OPTION_BW_PKTS },
+ { NULL, -1 }
+};
+
static int is_bad_interface_name(char *i) {
char **p;
for (p = bad_interface_names; *p; ++p)
@@ -103,7 +110,7 @@
while(nameindex[j].if_index != 0) {
if (strcmp(nameindex[j].if_name, "lo") != 0 && !is_bad_interface_name(nameindex[j].if_name)) {
strncpy(ifr.ifr_name, nameindex[j].if_name, sizeof(ifr.ifr_name));
- if ((s == -1) || (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) || (ifr.ifr_flags & IFF_UP)) {
+ if ((s == -1) || (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) || (ifr.ifr_flags & IFF_RUNNING)) {
i = xstrdup(nameindex[j].if_name);
break;
}
@@ -145,7 +152,7 @@
options.aggregate_dest = 0;
options.paused = 0;
options.showhelp = 0;
- options.bandwidth_in_bytes = 0;
+ options.bandwidth_unit = OPTION_BW_BITS;
options.sort = OPTION_SORT_DIV2;
options.screenfilter = NULL;
options.freezeorder = 0;
@@ -188,7 +195,8 @@
" -p run in promiscuous mode (show traffic between other\n"
" hosts on the same network segment)\n"
" -b don't display a bar graph of traffic\n"
-" -B Display bandwidth in bytes\n"
+" -B display bandwidth in bytes\n"
+" -a display bandwidth in packets\n"
" -i interface listen on named interface\n"
" -f filter code use filter code to select packets to count\n"
" (default: none, but only IP packets are counted)\n"
@@ -271,9 +279,13 @@
break;
case 'B':
- config_set_string("use-bytes", "true");
+ config_set_string("bandwidth-unit", "bytes");
break;
+ case 'u':
+ config_set_string("bandwidth-unit", optarg);
+ break;
+
case 's':
config_set_string("timed-output", optarg);
break;
@@ -370,6 +382,23 @@
return 0;
}
+int options_config_get_bw_unit() {
+ int i;
+
+ if (options_config_get_enum("bandwidth-unit", bandwidth_unit_enumeration,
+ (int*)&options.bandwidth_unit))
+ return 1;
+ /* compatibility with use-bytes / -B */
+ if (options_config_get_bool("use-bytes", &i)) {
+ if (i)
+ options.bandwidth_unit = OPTION_BW_BYTES;
+ else
+ options.bandwidth_unit = OPTION_BW_BITS;
+ return 1;
+ }
+ return 0;
+}
+
int options_config_get_bw_rate(char *directive, long long* result) {
char* units;
long long mult = 1;
@@ -544,7 +573,7 @@
options_config_get_promiscuous();
options_config_get_bool("hide-source", &options.aggregate_src);
options_config_get_bool("hide-destination", &options.aggregate_dest);
- options_config_get_bool("use-bytes", &options.bandwidth_in_bytes);
+ options_config_get_bw_unit();
options_config_get_enum("sort", sort_enumeration, (int*)&options.sort);
options_config_get_enum("line-display", linedisplay_enumeration, (int*)&options.linedisplay);
options_config_get_bool("show-totals", &options.show_totals);
--- iftop-1.0pre4/options.h 2014-01-05 20:16:52.000000000 +0100
+++ iftop-1.0pre4/options.h.git20181003 2019-07-28 01:42:14.025500109 +0200
@@ -34,6 +34,12 @@
OPTION_LINEDISPLAY_ONE_LINE_SENT
} option_linedisplay_t;
+typedef enum {
+ OPTION_BW_BITS,
+ OPTION_BW_BYTES,
+ OPTION_BW_PKTS,
+} option_bw_unit_t;
+
/*
* This structure has to be defined in the same order as the config
* directives in cfgfile.c. Clearly this is EBW.
@@ -59,7 +65,7 @@
int timed_output;
int no_curses;
int num_lines;
- int bandwidth_in_bytes;
+ option_bw_unit_t bandwidth_unit;
option_sort_t sort;
int bar_interval;
--- iftop-1.0pre4/resolver.c 2014-01-19 19:52:33.000000000 +0100
+++ iftop-1.0pre4/resolver.c.git20181003 2019-07-28 01:42:14.025500109 +0200
@@ -438,11 +438,11 @@
char **ch_pp;
void **void_pp;
} u_old = { &old };
- if(hash_find(ns_hash, &addr, u_old.void_pp) == HASH_STATUS_OK) {
+ if(hash_find(ns_hash, &addr.as_addr6, u_old.void_pp) == HASH_STATUS_OK) {
hash_delete(ns_hash, &addr);
xfree(old);
}
- hash_insert(ns_hash, &addr, (void*)hostname);
+ hash_insert(ns_hash, &addr.as_addr6, (void*)hostname);
}
}
@@ -488,7 +488,7 @@
pthread_mutex_lock(&resolver_queue_mutex);
- if(hash_find(ns_hash, raddr, u_hostname.void_pp) == HASH_STATUS_OK) {
+ if(hash_find(ns_hash, &raddr->as_addr6, u_hostname.void_pp) == HASH_STATUS_OK) {
/* Found => already resolved, or on the queue, no need to keep
* it around */
free(raddr);
@@ -497,7 +497,7 @@
hostname = xmalloc(INET6_ADDRSTRLEN);
inet_ntop(af, &raddr->addr, hostname, INET6_ADDRSTRLEN);
- hash_insert(ns_hash, raddr, hostname);
+ hash_insert(ns_hash, &raddr->as_addr6, hostname);
if(((head + 1) % RESOLVE_QUEUE_LENGTH) == tail) {
/* queue full */
--- iftop-1.0pre4/tui.c 2014-01-19 21:07:26.000000000 +0100
+++ iftop-1.0pre4/tui.c.git20181003 2019-07-28 01:42:14.026500117 +0200
@@ -73,7 +73,7 @@
printf("\n");
/* Traverse the list of all connections */
- while((nn = sorted_list_next_item(&screen_list, nn)) != NULL && l < options.num_lines) {
+ while((nn = sorted_list_next_item(&screen_list, nn)) != NULL && (!options.num_lines || l < options.num_lines)) {
/* Increment the line counter */
l++;
@@ -87,7 +87,7 @@
/* Send rate per connection */
printf("%4d %s%s", l, host1, " =>");
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- readable_size(screen_line->sent[j], buf0_10, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(screen_line->sent[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf(" %10s", buf0_10);
}
/* Cumulative sent data per connection */
@@ -97,7 +97,7 @@
/* Receive rate per connection */
printf(" %s%s", host2, " <=");
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- readable_size(screen_line->recv[j], buf0_10, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(screen_line->recv[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf(" %10s", buf0_10);
}
/* Cumulative received data per connection */
@@ -115,21 +115,21 @@
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total send rate:");
printf("%s ", labellong);
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- readable_size((((host_pair_line *)&totals)->sent[j]) , buf0_10, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(((host_pair_line *)&totals)->sent[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' ');
}
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total receive rate:");
printf("%s ", labellong);
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- readable_size((((host_pair_line *)&totals)->recv[j]) , buf0_10, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(((host_pair_line *)&totals)->recv[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' ');
}
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total send and receive rate:");
printf("%s ", labellong);
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- readable_size((((host_pair_line *)&totals)->sent[j] + ((host_pair_line *)&totals)->recv[j]) , buf0_10, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(((host_pair_line *)&totals)->sent[j] + ((host_pair_line *)&totals)->recv[j], buf0_10, 10, 1024, options.bandwidth_unit);
printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' ');
}
@@ -141,9 +141,9 @@
/* Peak traffic */
snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Peak rate (sent/received/total):");
- readable_size(peaksent / RESOLUTION, buf0_10, 10, 1024, options.bandwidth_in_bytes);
- readable_size(peakrecv / RESOLUTION, buf1_10, 10, 1024, options.bandwidth_in_bytes);
- readable_size(peaktotal / RESOLUTION, buf2_10, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(peaksent / RESOLUTION, buf0_10, 10, 1024, options.bandwidth_unit);
+ readable_size(peakrecv / RESOLUTION, buf1_10, 10, 1024, options.bandwidth_unit);
+ readable_size(peaktotal / RESOLUTION, buf2_10, 10, 1024, options.bandwidth_unit);
printf("%s %10s %10s %10s\n", labellong, buf0_10, buf1_10, buf2_10);
/* Cumulative totals */
--- iftop-1.0pre4/ui.c 2014-01-19 19:48:30.000000000 +0100
+++ iftop-1.0pre4/ui.c.git20181003 2019-07-28 01:42:14.026500117 +0200
@@ -71,7 +71,7 @@
/* Barchart scales. */
static struct {
- int max, interval;
+ long max; int interval;
} scale[] = {
{ 64000, 10 }, /* 64 kbit/s */
{ 128000, 10 },
@@ -79,7 +79,9 @@
{ 1000000, 10 }, /* 1 Mbit/s */
{ 10000000, 10 },
{ 100000000, 100 },
- { 1000000000, 100 } /* 1 Gbit/s */
+ { 1000000000, 100 }, /* 1 Gbit/s */
+ {10000000000, 100 },
+ {100000000000, 100 }
};
static int rateidx = 0, wantbiggerrate;
@@ -105,7 +107,7 @@
}
/* rate in bits */
-static int get_bar_length(const int rate) {
+static int get_bar_length(const long rate) {
float l;
if (rate <= 0)
return 0;
@@ -153,7 +155,7 @@
char s[40], *p;
int x;
/* This 1024 vs 1000 stuff is just plain evil */
- readable_size(i, s, sizeof s, options.log_scale ? 1000 : 1024, options.bandwidth_in_bytes);
+ readable_size(i, s, sizeof s, options.log_scale ? 1000 : 1024, options.bandwidth_unit);
p = s + strspn(s, " ");
x = get_bar_length(i * 8);
mvaddch(*y + 1, x, ACS_BTEE);
@@ -177,13 +179,13 @@
}
}
-void draw_line_total(float sent, float recv, int y, int x, option_linedisplay_t linedisplay, int bytes) {
+void draw_line_total(float sent, float recv, int y, int x, option_linedisplay_t linedisplay, option_bw_unit_t unit) {
char buf[10];
float n = 0;
switch(linedisplay) {
case OPTION_LINEDISPLAY_TWO_LINE:
- draw_line_total(sent, recv, y, x, OPTION_LINEDISPLAY_ONE_LINE_SENT, bytes);
- draw_line_total(sent, recv, y+1, x, OPTION_LINEDISPLAY_ONE_LINE_RECV, bytes);
+ draw_line_total(sent, recv, y, x, OPTION_LINEDISPLAY_ONE_LINE_SENT, unit);
+ draw_line_total(sent, recv, y+1, x, OPTION_LINEDISPLAY_ONE_LINE_RECV, unit);
break;
case OPTION_LINEDISPLAY_ONE_LINE_SENT:
n = sent;
@@ -196,7 +198,7 @@
break;
}
if(linedisplay != OPTION_LINEDISPLAY_TWO_LINE) {
- readable_size(n, buf, 10, 1024, bytes);
+ readable_size(n, buf, 10, 1024, unit);
mvaddstr(y, x, buf);
}
}
@@ -214,7 +216,7 @@
int x = (COLS - 8 * HISTORY_DIVISIONS);
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- draw_line_total(line->sent[j], line->recv[j], y, x, linedisplay, options.bandwidth_in_bytes);
+ draw_line_total(line->sent[j], line->recv[j], y, x, linedisplay, options.bandwidth_unit);
x += 8;
}
@@ -247,7 +249,7 @@
draw_line_totals(y, totals, OPTION_LINEDISPLAY_TWO_LINE);
y += 2;
for(j = 0; j < HISTORY_DIVISIONS; j++) {
- readable_size((totals->sent[j] + totals->recv[j]) , buf, 10, 1024, options.bandwidth_in_bytes);
+ readable_size((totals->sent[j] + totals->recv[j]) , buf, 10, 1024, options.bandwidth_unit);
mvaddstr(y, x, buf);
x += 8;
}
@@ -262,6 +264,7 @@
static char *line;
static int lcols;
int y = 0;
+ option_bw_unit_t cumunit;
if (dontshowdisplay)
return;
@@ -375,25 +378,31 @@
/* Cummulative totals */
mvaddstr(y, 16, "cum: ");
- readable_size(history_totals.total_sent, line, 10, 1024, 1);
+ /* Previous versions of iftop always displayed totals in bytes, even when
+ use-bytes = false. Stay compatible when the default unit hasn't been
+ changed. */
+ cumunit = options.bandwidth_unit;
+ if (cumunit == OPTION_BW_BITS)
+ cumunit = OPTION_BW_BYTES;
+ readable_size(history_totals.total_sent, line, 10, 1024, cumunit);
mvaddstr(y, 22, line);
- readable_size(history_totals.total_recv, line, 10, 1024, 1);
+ readable_size(history_totals.total_recv, line, 10, 1024, cumunit);
mvaddstr(y+1, 22, line);
- readable_size(history_totals.total_recv + history_totals.total_sent, line, 10, 1024, 1);
+ readable_size(history_totals.total_recv + history_totals.total_sent, line, 10, 1024, cumunit);
mvaddstr(y+2, 22, line);
/* peak traffic */
mvaddstr(y, 32, "peak: ");
- readable_size(peaksent / RESOLUTION, line, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(peaksent / RESOLUTION, line, 10, 1024, options.bandwidth_unit);
mvaddstr(y, 39, line);
- readable_size(peakrecv / RESOLUTION, line, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(peakrecv / RESOLUTION, line, 10, 1024, options.bandwidth_unit);
mvaddstr(y+1, 39, line);
- readable_size(peaktotal / RESOLUTION, line, 10, 1024, options.bandwidth_in_bytes);
+ readable_size(peaktotal / RESOLUTION, line, 10, 1024, options.bandwidth_unit);
mvaddstr(y+2, 39, line);
mvaddstr(y, COLS - 8 * HISTORY_DIVISIONS - 8, "rates:");
--- iftop-1.0pre4/ui_common.c 2014-01-05 19:40:46.000000000 +0100
+++ iftop-1.0pre4/ui_common.c.git20181003 2019-07-28 01:42:14.026500117 +0200
@@ -21,8 +21,11 @@
int history_divs[HISTORY_DIVISIONS] = {1, 5, 20};
#define UNIT_DIVISIONS 4
-char* unit_bits[UNIT_DIVISIONS] = { "b", "Kb", "Mb", "Gb"};
-char* unit_bytes[UNIT_DIVISIONS] = { "B", "KB", "MB", "GB"};
+char* unit_disp[][UNIT_DIVISIONS] = {
+ [OPTION_BW_BITS] = { "b", "Kb", "Mb", "Gb"},
+ [OPTION_BW_BYTES] = { "B", "KB", "MB", "GB"},
+ [OPTION_BW_PKTS] = { "p", "Kp", "Mp", "GB"},
+};
extern hash_type* history;
extern int history_pos;
@@ -121,29 +124,34 @@
/*
* Format a data size in human-readable format
*/
-void readable_size(float n, char* buf, int bsize, int ksize, int bytes) {
+void readable_size(float n, char* buf, int bsize, int ksize,
+ option_bw_unit_t unit) {
int i = 0;
float size = 1;
/* Convert to bits? */
- if(bytes == 0) {
+ if (unit == OPTION_BW_BITS) {
n *= 8;
}
+ /* Force power of ten for pps */
+ if (unit == OPTION_BW_PKTS)
+ ksize = 1000;
+
while(1) {
if(n < size * 1000 || i >= UNIT_DIVISIONS - 1) {
- snprintf(buf, bsize, " %4.0f%s", n / size, bytes ? unit_bytes[i] : unit_bits[i]);
+ snprintf(buf, bsize, " %4.0f%s", n / size, unit_disp[unit][i]);
break;
}
i++;
size *= ksize;
if(n < size * 10) {
- snprintf(buf, bsize, " %4.2f%s", n / size, bytes ? unit_bytes[i] : unit_bits[i]);
+ snprintf(buf, bsize, " %4.2f%s", n / size, unit_disp[unit][i]);
break;
}
else if(n < size * 100) {
- snprintf(buf, bsize, " %4.1f%s", n / size, bytes ? unit_bytes[i] : unit_bits[i]);
+ snprintf(buf, bsize, " %4.1f%s", n / size, unit_disp[unit][i]);
break;
}
}
@@ -263,9 +271,6 @@
} u_screen_line = { &screen_line };
addr_pair ap;
int i;
- int tsent, trecv;
- tsent = trecv = 0;
-
ap = *(addr_pair*)n->key;
--- iftop-1.0pre4/ui_common.h 2014-01-01 15:17:08.000000000 +0100
+++ iftop-1.0pre4/ui_common.h.git20181003 2019-07-28 01:42:14.026500117 +0200
@@ -43,6 +43,6 @@
void analyse_data(void);
void screen_list_init(void);
void sprint_host(char * line, int af, struct in6_addr* addr, unsigned int port, unsigned int protocol, int L, int unspecified_as_star);
-void readable_size(float, char*, int, int, int);
+void readable_size(float, char*, int, int, option_bw_unit_t);
#endif /* __UI_COMMON_H_ */

25
iftop-1.0-ncursesw.patch Normal file
View File

@ -0,0 +1,25 @@
Patch by Robert Scheck <robert@fedoraproject.org> for iftop <= 1.0pre4 to avoid a
regression that would reopen https://bugzilla.redhat.com/show_bug.cgi?id=546032.
--- iftop-1.0pre4/configure.ac 2014-01-19 21:28:31.000000000 +0100
+++ iftop-1.0pre4/configure.ac.ncursesw 2014-01-20 00:12:54.000000000 +0100
@@ -353,7 +353,7 @@
for curseslib in ncursesw curses ncurses ; do
LIBS="$oldLIBS -l$curseslib"
AC_TRY_LINK([
-#include <$curseslib.h>
+#include <curses.h>
], [
mvchgat(0, 0, 1, A_REVERSE, 0, NULL)
], [
--- iftop-1.0pre4/configure 2014-01-19 21:32:58.000000000 +0100
+++ iftop-1.0pre4/configure.ncursesw 2014-01-20 00:13:15.000000000 +0100
@@ -5745,7 +5745,7 @@
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
-#include <$curseslib.h>
+#include <curses.h>
int
main ()

BIN
iftop-1.0pre4.tar.gz Normal file

Binary file not shown.

43
iftop.spec Normal file
View File

@ -0,0 +1,43 @@
#from https://fedoraproject.org to https://openeuler.org/
Summary: Command line tool that displays bandwidth usage on an interface
Name: iftop
Version: 1.0pre4
Release: 1
License: GPLv2+
URL: http://www.ex-parrot.com/~pdw/%{name}/
Source0: http://www.ex-parrot.com/~pdw/%{name}/download/%{name}-%{version}.tar.gz
Patch0: iftop-1.0-ncursesw.patch
Patch1: iftop-1.0-git20181003.patch
Patch2: iftop-1.0-gcc10.patch
BuildRequires: gcc, make, ncurses-devel, libpcap-devel
%description
iftop does for network usage what top(1) does for CPU usage. It listens to
network traffic on a named interface and displays a table of current bandwidth
usage by pairs of hosts. Handy for answering the question "why is our ADSL link
so slow?".
%prep
%setup -q -n %{name}-%{version}
%patch0 -p1 -b .ncursesw
touch -c -r configure.ac{.ncursesw,}
%patch1 -p1 -b .git20181003
%patch2 -p1 -b .gcc10
%build
%configure
%make_build
%install
%make_install
%files
%license COPYING
%doc ChangeLog README TODO
%{_sbindir}/%{name}
%{_mandir}/man8/%{name}.*
%changelog
* Fri Mar 19 2021 wangyueliang <wangyueliang@kylinos.cn> - 1.0-1
- package init

4
iftop.yaml Normal file
View File

@ -0,0 +1,4 @@
version_control: git
src_repo: https://code.blinkace.com/pdw/iftop.git
tag_prefix: "iftop-"
separator: "."