ubuntu系统wireshark源码编译与安装
<p>原文地址:https://www.cnblogs.com/liqinglucky/p/wireshark.html</p><p>官网:https://www.wireshark.org/</p>
<p>官方文档:Wireshark · Documentation</p>
<h1 id="一-介绍">一 介绍</h1>
<p>wireshark<sup class="footnote-ref"></sup>是一款抓包工具。wireshark的GUI(用户界面)框架从开发版本 1.11.0 (2013.11.15)开始项目方向的一个重大变化是由GTK+切换到了Qt<sup class="footnote-ref"></sup>。</p>
<blockquote>
<p>Wireshark 1.11.0 Development Release<sup class="footnote-ref"></sup></p>
<p>November 15, 2013</p>
<p>The following features are new (or have been significantly updated) since version 1.10:</p>
<ul>
<li>Wireshark now uses the Qt application framework.</li>
</ul>
</blockquote>
<h1 id="二-编译">二 编译</h1>
<h2 id="21-编译环境">2.1 编译环境</h2>
<p>Ubuntu 20.04.4 LTS</p>
<h2 id="22-源码">2.2 源码</h2>
<p>源码编译参考:2.7. Building from source under UNIX or Linux (wireshark.org)</p>
<p>从官网下载源码后解压。这里下载的是当前最新版本<code>wireshark-4.0.2</code>。</p>
<pre><code># tar xvf wireshark-4.0.2.tar.xz
</code></pre>
<h2 id="23-安装依赖">2.3 安装依赖</h2>
<p><strong>qt</strong></p>
<pre><code>$ sudo apt-get install build-essential
$ sudo apt-get install qtcreator
$ sudo apt-get install qt5-default
//启动qt
$ qtcreator
</code></pre>
<p><strong>cmake</strong></p>
<pre><code>apt-get install -y make cmake pkg-config
</code></pre>
<p>其他依赖可以根据提示再进行安装。</p>
<h2 id="24-cmake编译">2.4 cmake编译</h2>
<p>cmake编译一般会新建一个编译用的目录</p>
<pre><code>wireshark-4.0.2# mkdir build
</code></pre>
<p>cmake编译生成makefile文件</p>
<pre><code>wireshark-4.0.2# cd build/
wireshark-4.0.2/build# cmake ..
-- Configuring done <<< cmake成功
-- Generating done
</code></pre>
<p>cmake编译后虽然还是很多提示<code>Could NOT find</code>,但只要能运行完成没有error提示就不影响后面的编译。</p>
<h3 id="241-遇到的依赖问题">2.4.1 遇到的依赖问题</h3>
<p>问题1:缺少<code>pkg-config</code></p>
<pre><code>wireshark-4.0.2/build# cmake ..
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
</code></pre>
<p>解决:</p>
<pre><code>apt-get install -y pkg-config
</code></pre>
<p>问题2:缺少<code>GLIB2</code></p>
<pre><code>-- Checking for one of the modules 'glib-2.0'
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find GLIB2 (missing: GLIB2_LIBRARY GLIB2_MAIN_INCLUDE_DIR
</code></pre>
<p>解决:</p>
<pre><code>//1 搜索库
# apt-cache search libglib
gvfs-bin - userspace virtual filesystem - deprecated command-line tools
libglib-object-introspection-perl - Perl bindings for gobject-introspection libraries
libglib-perl - interface to the GLib and GObject libraries
libglib2.0-0 - GLib library of C routines
libglib2.0-bin - Programs for the GLib library
libglib2.0-data - Common files for GLib library
libglib2.0-dev - Development files for the GLib library
libglib2.0-dev-bin - Development utilities for the GLib library
libglib2.0-doc - Documentation files for the GLib library
//2 安装库
# apt-get install -y libglib2.0-dev
</code></pre>
<p>问题3:缺少<code>GCRYPT</code></p>
<pre><code>Could NOT find GCRYPT (missing: GCRYPT_LIBRARY GCRYPT_INCLUDE_DIR)
(Required is at least version "1.8.0")
</code></pre>
<p>解决:</p>
<pre><code>$ sudo apt-file update
$ apt-file search gcrypt.h
apt-get install libgcrypt-dev
</code></pre>
<p>问题4:缺少<code>CARES</code></p>
<pre><code>Could NOT find CARES (missing: CARES_LIBRARY CARES_INCLUDE_DIR) (Required
is at least version "1.13.0")
</code></pre>
<p>解决:</p>
<pre><code>apt-get install libc-ares-dev
</code></pre>
<p>问题5:缺少<code>LEX</code></p>
<pre><code> Could NOT find LEX (missing: LEX_EXECUTABLE)
</code></pre>
<p>解决:</p>
<pre><code>apt-get install flex bison
</code></pre>
<p>问题6:缺少<code>Gettext</code></p>
<pre><code>-- Could NOT find Gettext (missing: GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE)
</code></pre>
<p>解决:</p>
<pre><code>apt-get install gettext
</code></pre>
<p>问题7:缺少<code>LIBSSH</code></p>
<pre><code>-- Could NOT find LIBSSH (missing: LIBSSH_LIBRARIES LIBSSH_INCLUDE_DIRS LIBSSH_VERSION) (Required is at least version "0.6")
</code></pre>
<p>解决:</p>
<pre><code>apt-get install libssh-dev
apt-get install libssh2-1-dev
</code></pre>
<p>问题8:缺少<code>libpcap</code></p>
<pre><code>-- Checking for one of the modules 'libpcap'
-- Could NOT find PCAP (missing: PCAP_LIBRARY PCAP_INCLUDE_DIR)
</code></pre>
<p>解决:</p>
<pre><code>apt-get install libpcap-dev
</code></pre>
<p>问题9:缺少<code>Qt5LinguistTools</code></p>
<pre><code>
Could not find a package configuration file provided by "Qt5LinguistTools"
with any of the following names:
Qt5LinguistToolsConfig.cmake
qt5linguisttools-config.cmake
</code></pre>
<p>解决:</p>
<pre><code>apt-get install qttools5-dev
</code></pre>
<p>问题10:缺少<code>Systemd</code></p>
<pre><code>-- Could NOT find Systemd (missing: SYSTEMD_LIBRARY SYSTEMD_INCLUDE_DIR) (found version "")
</code></pre>
<p>可选依赖库可以忽略。</p>
<h2 id="25-make编译">2.5 make编译</h2>
<p>cmake生成makefile后</p>
<pre><code>wireshark-4.0.2/build# make
Scanning dependencies of target wmem
Building C object wsutil/wmem/CMakeFiles/wmem.dir/wmem_array.c.o
Built target wmem
Scanning dependencies of target l16mono
Linking C shared module ../../../run/plugins/4.0/codecs/l16mono.so
Built target l16mono
</code></pre>
<h2 id="26-运行wireshark">2.6 运行wireshark</h2>
<p>make编译生成可执行文件在<code>build/run</code>目录下,可以直接运行。</p>
<pre><code>wireshark-4.0.2/build# run/wireshark
** (wireshark:208857) 09:47:59.035931 -- Capture Start ...
** (wireshark:208857) 09:47:59.885422 -- Capture started
</code></pre>
<p><img src="https://img2023.cnblogs.com/blog/1037313/202212/1037313-20221217224211475-2099483751.png"></p>
<p>可以运行图形界面说明已经成功了!如果希望安装到系统也可以<code>make install</code>,这样就可以加入环境变量只要用wireshark命令就可以启动了。</p>
<h1 id="三-参考">三 参考</h1>
<hr class="footnotes-sep">
<section class="footnotes">
<ol class="footnotes-list">
<li id="fn1" class="footnote-item"><p>Wireshark - Arch Linux 中文维基 (archlinuxcn.org) ↩︎</p>
</li>
<li id="fn2" class="footnote-item"><p>Wireshark 正在使用 Qt 进行重写 - OSCHINA - 中文开源技术交流社区 ↩︎</p>
</li>
<li id="fn3" class="footnote-item"><p>Wireshark · Wireshark 1.11.0 Development Release ↩︎</p>
</li>
</ol>
</section><br><br>
来源:https://www.cnblogs.com/liqinglucky/p/wireshark.html
頁:
[1]