%define tcpslice_dir tcpslice-1.6

Name:           tcpdump
Epoch:          14
Version:        4.99.3
Release:        3
Summary:        A network traffic monitoring tool
License:        BSD with advertising
URL:            http://www.tcpdump.org

Source0:        http://www.tcpdump.org/release/tcpdump-%{version}.tar.gz
Source1:        https://www.tcpdump.org/release/%{tcpslice_dir}.tar.gz
Source2:        http://www.tcpdump.org/release/tcpdump-%{version}.tar.gz.sig

Patch0:         backport-0002-Use-getnameinfo-instead-of-gethostbyaddr.patch
Patch1:         backport-0003-Drop-root-priviledges-before-opening-first-savefile-.patch
Patch2:         backport-0007-Introduce-nn-option.patch
Patch3:         backport-0009-Change-n-flag-to-nn-in-TESTonce.patch
Patch4:         tcpdump-Add-sw64-architecture.patch
Patch5:         backport-CVE-2023-1801.patch
Patch6:         backport-CVE-2024-2397.patch

Requires(pre):  shadow-utils
BuildRequires:  automake openssl-devel libpcap-devel git-core gcc make

%description
Tcpdump is a command-line tool for monitoring network traffic.
Tcpdump can capture and display the packet headers on a particular
network interface or on all interfaces.  Tcpdump can display all of
the packet headers, or just the ones that match particular criteria.

Install tcpdump if you need a program to monitor network traffic.

%package help
Summary:        Help documents for tcpdump

%description    help
Man pages and other related help documents for tcpdump.

%prep
%autosetup -a 1 -S git

%build
export CFLAGS="$RPM_OPT_FLAGS $(getconf LFS_CFLAGS) -fno-strict-aliasing"

pushd %{tcpslice_dir}
# update config.{guess,sub}
automake -a -f 2> /dev/null || :
%configure
make %{?_smp_mflags}
popd

%configure --with-crypto --with-user=tcpdump --without-smi
make %{?_smp_mflags}

%install
mkdir -p ${RPM_BUILD_ROOT}%{_libdir}
mkdir -p ${RPM_BUILD_ROOT}%{_mandir}/man8
mkdir -p ${RPM_BUILD_ROOT}%{_sbindir}

pushd %{tcpslice_dir}
install -m755 tcpslice ${RPM_BUILD_ROOT}%{_sbindir}
install -m644 tcpslice.1 ${RPM_BUILD_ROOT}%{_mandir}/man8/tcpslice.8
popd

install -m755 tcpdump ${RPM_BUILD_ROOT}%{_sbindir}
install -m644 tcpdump.1 ${RPM_BUILD_ROOT}%{_mandir}/man8/tcpdump.8

# fix section numbers
sed -i 's/\(\.TH[a-zA-Z ]*\)[1-9]\(.*\)/\18\2/' \
	${RPM_BUILD_ROOT}%{_mandir}/man8/*

%pre
/usr/sbin/groupadd -g 72 tcpdump 2> /dev/null
/usr/sbin/useradd -u 72 -g 72 -s /sbin/nologin -M -r \
	-d / tcpdump 2> /dev/null
exit 0

%check
make check

%files
%doc README.md CHANGES CREDITS
%license LICENSE
%{_sbindir}/tcpdump
%{_sbindir}/tcpslice

%files help
%{_mandir}/man8/tcpslice.8*
%{_mandir}/man8/tcpdump.8*

%changelog
* Mon Apr 08 2024 xinghe <xinghe2@h-partners.com> - 14:4.99.3-3
- Type:CVE
- ID:CVE-2024-2397
- SUG:NA
- DESC:fix CVE-2024-2397

* Thu Apr 13 2023 zengwefeng <zwfeng@huawei.com> - 14:4.99.3-2
- Type:CVE
- ID:CVE-2023-1801
- SUG:NA
- DESC:fix CVE-2023-1801

* Mon Feb 06 2023 xinghe <xinghe2@h-partners.com> - 14:4.99.3-1
- Type:requirements
- ID:NA
- SUG:NA
- DESC:update tcpdump to 4.99.3

* Tue Oct 25 2022 wuzx<wuzx1226@qq.com> - 14:4.99.1-5
- Type:feature
- CVE:NA
- SUG:NA
- DESC:Add sw64 architecture

* Wed Aug 31 2022 gaihuiying <eaglegai@163.com> - 14:4.99.1-4
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:fix git warning when rpmbuild -ba compiling

* Tue Aug 30 2022 xingwei <xingwei14@h-partners.com> - 14:4.99.1-3
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:Set SA_RESTART on non-lethal signals (REQ_INFO, FLUSH_PCAP) to avoid corrupting binary pcap output

* Sat Jun 11 2022 gaihuiying <eaglegai@163.com> - 4.99.1-2
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:enable make check

* Tue Dec 14 2021 xihaochen<xihaochen@huawei.com> - 4.99.1-1
- Type:requirements
- ID:NA
- SUG:NA
- DESC:update tcpdump to 4.99.1

* Fri Dec 18 2020 seuzw <930zhaowei@163.com> - 4.9.3-4
- Type:CVE
- ID:CVE-2020-8037
- SUG:NA
- DESC:fix CVE-2020-8037

* Tue Dec 31 2019 openEuler Buildteam <buildteam@openeuler.org> - 4.9.3-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:optimization the spec

* Sat Dec 21 2019 openEuler Buildteam <buildteam@openeuler.org> - 4.9.3-2
- Package init
