移植 iftop 到海思 3559 平台

移植 iftop 到海思 3559 平台 张显显 2023-10-16 11:31:40 1682

一、下载

http://www.ex-parrot.com/~pdw/iftop/

二、编译

报错 1

configure: WARNING: If you wanted to set the --build type, don't use --host.
    If a cross compiler is detected then cross compile mode will be used.
checking build system type... x86_64-unknown-linux-gnu
checking host system type... Invalid configuration `aarch64-himix100-linux': machine `aarch64-himix100' not recognized
configure: error: /bin/sh config/config.sub aarch64-himix100-linux failed

解决 1

config/config.sub 文件的第 231 行后面加一行 | aarch64-himix100 \ 就能认到了

# Decode aliases for certain CPU-COMPANY combinations.
case $basic_machine in
        # Recognize the basic CPU types without company name.
        # Some are omitted here because they have special meanings below.
        1750a | 580 \
        | a29k \
        | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
        | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
        | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \
        | aarch64-himix100 \
        | c4x | clipper \
        | d10v | d30v | dlx | dsp16xx \
        | fr30 | frv \
        | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
        | i370 | i860 | i960 | ia64 \
        | ip2k \
        | m32r | m68000 | m68k | m88k | mcore \
        | mips | mipsbe | mipseb | mipsel | mipsle \
        | mips16 \

报错 2

checking where to find pcap.h... /usr/include
checking for pcap_open_live in -lpcap... no
configure: error: can't find libpcap
  You're not going to get very far without libpcap.

解决 2

使用 --with-libpcap 引入交叉编译好的库--with-libpcap=/hisi_ext/3rd/libpcap-1.9.1/_install

报错 3

checking for a curses library containing mvchgat... none found
configure: error: Curses! Foiled again!
  (Can't find a curses library supporting mvchgat.)
  Consider installing ncurses.

分析 3

这个问题网上千篇一律的都是说安装库,但是我们这是交叉编译,直接命令安装库的方法是用不了的。

很显然,解决这个问题的重点就是如何正确引入 ncurses 相关项。

我一开始只是添加了 --with-ncurses=/hisi_ext/3rd/ncurses-6.2/_install LDFLAGS="-L/hisi_ext/3rd/ncurses-6.2/_install/lib -lncurses" CPPFLAGS="-I/hisi_ext/3rd/ncurses-6.2/_install/include" 这些项,头文件路径,库文件路径,库文件都正确引入了,但是仍然报一样的错误。理论上我已经引入了 ncurses ,应该不会有问题的。于是我仔细看了一下 configure 文件里是如何判断失败的,如何拷贝里面的判断方法,自己在外面手动编译一下才发现少引用了一个头文件路径 -I/hisi_ext/3rd/ncurses-6.2/_install/include/ncurses

测试

  • 创建 main.c
$ cat main.c
#include <curses.h>

int main ()
{
  mvchgat(0, 0, 1, A_REVERSE, 0, NULL) ;
  return 0;
}
  • 编译 main.c
$ aarch64-himix100-linux-gcc main.c -lncurses -L/hisi_ext/3rd/ncurses-6.2/_install/lib -I/hisi_ext/3rd/ncurses-6.2/_install/include/ncurses
In file included from main.c:1:0:
/hisi_ext/3rd/ncurses-6.2/_install/include/ncurses/curses.h:61:33: fatal error: ncurses/ncurses_dll.h: No such file or directory
#include <ncurses/ncurses_dll.h>
        ^
compilation terminated.

竟然报错,猜测 configure 文件里只要报错就算作失败,不管错误原因是什么,都是抛出一样的错误 ... Can't find a curses library supporting mvchgat ...。我们可以在 ncurses 路径里面找到缺失的 ncurses_dll.h 文件,如下:

$ ls ../ncurses-6.2/_install/include/ncurses
curses.h     cursesf.h  cursesp.h  cursslk.h  etip.h  menu.h      ncurses.h      panel.h  term_entry.h  tic.h
cursesapp.h  cursesm.h  cursesw.h  eti.h      form.h  nc_tparm.h  ncurses_dll.h  term.h   termcap.h     unctrl.h

所以引入这个新路径就可以编译通过

解决 3

./configure --prefix=/hisi_ext/3rd/iftop-0.17/_install\
--host=aarch64-himix100-linux\
--with-libpcap=/hisi_ext/3rd/libpcap-1.9.1/_install\
--with-ncurses=/hisi_ext/3rd/ncurses-6.2/_install\
LDFLAGS="-L/hisi_ext/3rd/ncurses-6.2/_install/lib -lncurses"\
CPPFLAGS="-I/hisi_ext/3rd/ncurses-6.2/_install/include/ncurses -I/hisi_ext/3rd/ncurses-6.2/_install/include"

三、安装

make
make install

四、使用

拷贝 iftop 到开发板后,运行

/mnt/wzy # ./iftop
./iftop: error while loading shared libraries: libpcap.so.1: cannot open shared object file: No such file or directory

解决:拷贝对应库到开发板的环境变量的 LD_LIBRARY_PATH 路径

用法

/mnt/wzy # ./iftop -h
iftop: display bandwidth usage on an interface by host

Synopsis: iftop -h | [-npbBP] [-i interface] [-f filter code] [-N net/mask]

   -h                  display this message
   -n                  don't do hostname lookups
   -N                  don't convert port numbers to services
   -p                  run in promiscuous mode (show traffic between other
                       hosts on the same network segment)
   -b                  don't display a bar graph of traffic
   -B                  Display bandwidth in bytes
   -i interface        listen on named interface
   -f filter code      use filter code to select packets to count
                       (default: none, but only IP packets are counted)
   -F net/mask         show traffic flows in/out of network
   -P                  show ports as well as hosts
   -m limit            sets the upper limit for the bandwidth scale
   -c config file      specifies an alternative configuration file

iftop, version 0.17
copyright (c) 2002 Paul Warren <pdw@ex-parrot.com> and contributors

测试

/mnt/wzy # ./iftop -i eth0
interface: eth0
IP address is: 192.168.12.150
MAC address is: 00:0c:29:58:00:50
Error opening terminal: xterm.

解决:拷贝你交叉编译出来的 ncurses 目录到开发板,并修改环境变量为对应路径和值:

/mnt/wzy # env | grep -i term
TERMINFO=/mnt/wzy/ncurses-6.2/share/terminfo
TERM=xterm

四、用法略解

执行 ./iftop -i eth0 后串口终端显示结果(会动态刷新)如下所示:

                 19.1Mb            38.1Mb           57.2Mb            76.3Mb      95.4Mb
└────────────────┴─────────────────┴────────────────┴─────────────────┴─────────────────
192.168.12.150                 => 192.168.12.128                 12.2Mb  12.2Mb  12.3Mb
192.168.12.150                 => 192.168.12.106                 12.2Mb  12.2Mb  12.3Mb
192.168.12.150                 => 192.168.12.69                  8.04Mb  8.04Mb  8.19Mb
192.168.12.255                 => 192.168.12.152                    0b      0b      0b
10.0.1.255                     => 10.0.1.15                         0b      0b      0b
10.69.2.255                    => 10.69.2.152                       0b      0b      0b
192.168.12.150                 => 192.168.12.133                    0b     42b     10b
10.69.2.255                    => 10.69.2.43                        0b      0b      0b
192.168.12.255                 => 192.168.12.43                     0b      0b      0b
255.255.255.255                => 10.69.2.69                        0b      0b      0b








────────────────────────────────────────────────────────────────────────────────────────
TX:             cumm:   278MB   peak:   40.7Mb          rates:   32.5Mb  32.4Mb  32.9Mb
RX:                    1.03MB            152Kb                    122Kb   123Kb   125Kb
TOTAL:                  279MB           40.8Mb                   32.6Mb  32.5Mb  33.0Mb

h? 显示帮助信息

Host display:                          General:
 n - toggle DNS host resolution         P - pause display
 s - toggle show source host            h - toggle this help display
 d - toggle show destination host       b - toggle bar graph display
 t - cycle line display mode            B - cycle bar graph average
                                        T - toggle cummulative line totals
Port display:                           j/k - scroll display
 N - toggle service resolution          f - edit filter code
 S - toggle show source port            l - set screen filter
 D - toggle show destination port       L - lin/log scales
 p - toggle port display                ! - shell command
                                        q - quit
Sorting:
 1/2/3 - sort by 1st/2nd/3rd column
 < - sort by source name
 > - sort by dest name
 o - freeze current order

iftop, version 0.17


声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包 1 收藏 评论 打赏
评论
0个
内容存在敏感词
手气红包
    易百纳技术社区暂无数据
相关专栏
置顶时间设置
结束时间
删除原因
  • 广告/SPAM
  • 恶意灌水
  • 违规内容
  • 文不对题
  • 重复发帖
打赏作者
易百纳技术社区
张显显
您的支持将鼓励我继续创作!
打赏金额:
¥1易百纳技术社区
¥5易百纳技术社区
¥10易百纳技术社区
¥50易百纳技术社区
¥100易百纳技术社区
支付方式:
微信支付
支付宝支付
易百纳技术社区微信支付
易百纳技术社区
打赏成功!

感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

审核成功

发布时间设置
发布时间:
是否关联周任务-专栏模块

审核失败

失败原因
备注
拼手气红包 红包规则
祝福语
恭喜发财,大吉大利!
红包金额
红包最小金额不能低于5元
红包数量
红包数量范围10~50个
余额支付
当前余额:
可前往问答、专栏板块获取收益 去获取
取 消 确 定

小包子的红包

恭喜发财,大吉大利

已领取20/40,共1.6元 红包规则

    易百纳技术社区