##
##  dsniff.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

##  FIXME: rse: this package is a very sensible one. It depends on
##  FIXME: rse: particular versions of libnet and libnids and libnids
##  FIXME: rse: in turn also depends on the particular libnet version.
##  FIXME: rse: The below versions (plus the patches in dsniff.patch)
##  FIXME: rse: are able to successfully build dsniff 2.3. Neither just
##  FIXME: rse: dsniff 2.4b1, nor libnids 1.17rc1 nor libnet 1.1.0 alone
##  FIXME: rse: can solve the problem. So, until dsniff 2.4 will support
##  FIXME: rse: the version in our libnids and libnet packages, let's
##  FIXME: rse: keep the local copies here. And do not blindly try to
##  FIXME: rse: upgrade them!

#   package versions
%define       V_dsniff  2.3
%define       V_libnet  1.0.2a
%define       V_libnids 1.16

#   package information
Name:         dsniff
Summary:      Network Auditing & Penetration Testing
URL:          http://www.monkey.org/~dugsong/dsniff/
Vendor:       Dug Song
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Capturing
License:      BSD-style
Version:      %{V_dsniff}
Release:      20080101

#   list of sources
Source0:      http://www.monkey.org/~dugsong/dsniff/dsniff-%{V_dsniff}.tar.gz
Source1:      http://www.packetfactory.net/libnet/dist/deprecated/libnet-%{V_libnet}.tar.gz
Source2:      http://www.packetfactory.net/projects/libnids/dist/libnids-%{V_libnids}.tar.gz
Patch0:       dsniff.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  db, db::with_compat = yes, openssl, libpcap, libnet, libnids
PreReq:       db, db::with_compat = yes, openssl, libpcap, libnet, libnids

%description
    Dsniff is a collection of tools for network auditing and penetration
    testing. dsniff, filesnarf, mailsnarf, msgsnarf, urlsnarf, and
    webspy passively monitor a network for interesting data (passwords,
    e-mail, files, etc.). arpspoof, dnsspoof, and macof facilitate the
    interception of network traffic normally unavailable to an attacker
    (e.g, due to layer-2 switching). sshmitm and webmitm implement
    active monkey-in-the-middle attacks against redirected SSH and HTTPS
    sessions by exploiting weak bindings in ad-hoc PKI.

%track
    prog dsniff = {
        version   = %{version}
        url       = http://www.monkey.org/~dugsong/dsniff/
        regex     = dsniff-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2
    %patch -p0

%build
    ( cd Libnet-%{V_libnet}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      ./configure \
          --prefix=%{l_prefix}
      %{l_make} %{l_mflags -O}
    ) || exit $?
    ( cd libnids-%{V_libnids}
      PATH="`pwd`/../Libnet-%{V_libnet}:$PATH"
      define="LIBNET_LIL_ENDIAN"
      case "%{l_platform -t}" in
          sparc*-* ) define="LIBNET_BIG_ENDIAN" ;;
          *68*-*   ) define="LIBNET_BIG_ENDIAN" ;;
      esac
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O} -I`pwd`/src -I`pwd`/../Libnet-%{V_libnet}/include -D$define" \
      LDFLAGS="-L`pwd`/src -L`pwd`/../Libnet-%{V_libnet}/lib %{l_ldflags}" \
      ./configure \
          --prefix=%{l_prefix}
      %{l_make} %{l_mflags -O}
    ) || exit $?
    libs=""
    case "%{l_platform -t}" in
        *-sunos* ) libs="-lrt" ;;
    esac
    CC="%{l_cc}"
    CFLAGS="%{l_cflags -O}"
    CFLAGS="$CFLAGS -I`pwd`/Libnet-%{V_libnet}/include"
    CFLAGS="$CFLAGS `./Libnet-%{V_libnet}/libnet-config --defines`"
    CFLAGS="$CFLAGS -I`pwd`/Libnet-%{V_libnet}/include"
    CFLAGS="$CFLAGS -I`pwd`/libnids-%{V_libnids}/src"
    CFLAGS="$CFLAGS %{l_cppflags}"
    LDFLAGS="-L`pwd`/Libnet-%{V_libnet}/lib"
    LDFLAGS="$LDFLAGS -L`pwd`/libnids-%{V_libnids}/src"
    LDFLAGS="$LDFLAGS %{l_ldflags}"
    LIBS="$libs"
    export CC
    export CFLAGS
    export LDFLAGS
    export LIBS
    ./configure \
        --prefix=%{l_prefix} \
        --libdir=%{l_prefix}/share/dsniff \
        --without-x \
        --with-db=%{l_prefix} \
        --with-libpcap=%{l_prefix} \
        --with-libnet=%{l_prefix} \
        --with-libnids=%{l_prefix} \
        --with-openssl=%{l_prefix}
    %{l_make} %{l_mflags}

%install
    %{l_make} %{l_mflags} install \
        install_prefix=$RPM_BUILD_ROOT
    strip $RPM_BUILD_ROOT%{l_prefix}/sbin/* >/dev/null 2>&1 || true
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

