# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           legacysupport 1.1

name                kismet
version             2023-07-R1
revision            0
checksums           rmd160  c39c4f28b01238718e3e7bdc495808e1a1027dce \
                    sha256  f08548e26ca65fa1e567b1debbea1ca4d0e7206bddb96a4f639c90171873e8f7 \
                    size    11144120

categories          net
license             GPL-2
maintainers         nomaintainer
platforms           {darwin >= 15}

description         Wireless network detector and sniffer
long_description    Kismet is an 802.11 layer2 wireless network detector, \
                    sniffer, and intrusion detection system.  Kismet will work \
                    with any wireless card which supports raw monitoring \
                    (rfmon) mode, and can sniff 802.11b, 802.11a, 802.11n, and \
                    802.11g traffic (devices and drivers permitting). It can \
                    work with MacBook and MacBook Pro Atheros-based cards with \
                    which currently KisMac is unable to. Kismet identifies \
                    networks by passively collecting packets and detecting \
                    standard named networks, detecting (and given time, \
                    decloaking) hidden networks, and inferring the presence of \
                    non-beaconing networks via data traffic.
homepage            https://www.kismetwireless.net

master_sites        ${homepage}/code/
use_xz              yes

# macports-libcxx needed for:
# error: no template named 'binary_function' in namespace 'std'
legacysupport.newest_darwin_requires_legacy 17
legacysupport.use_mp_libcxx                 yes

depends_build-append \
                    port:gmake \
                    path:bin/pkg-config:pkgconfig

depends_lib-append \
                    port:libpcap \
                    port:libusb \
                    port:libwebsockets \
                    port:ncurses \
                    path:lib/libssl.dylib:openssl \
                    port:pcre \
                    port:protobuf-c \
                    port:protobuf3-cpp

patchfiles-append   patch-capture_osx_corewlan_wifi-Makefile.diff
patchfiles-append   binary_function.patch

pre-patch {
    reinplace -W ${worksrcpath} "s|-groupadd -r -f|#-groupadd -r -f|" Makefile.in
}

# Needs C++17, as of version 2022-xx-xx
compiler.cxx_standard 2017

configure.cxxflags-append \
                     -Wno-error=unused-command-line-argument \
                     -Wno-deprecated-builtins \
                     -Wno-macro-redefined

configure.post_args-append \
                    --sysconfdir=${prefix}/etc/${name} \
                    --disable-python-tools \
                    --disable-ubertooth

build.type          gnu
build.args-append \
                    OBJCXX="${configure.objcxx}" \
                    OBJCXXFLAGS="${configure.objcxxflags} [get_canonical_archflags objcxx]"

# Install capture tools with suid-root runnable by members of 'staff' group. This
#  eliminates the need to run Kismet as root. Data capture is done under a
#  separate process from the main application.
#
# Ref: https://www.kismetwireless.net/docs/readme/suid/
destroot.target     suidinstall

set doc_dir         ${prefix}/share/doc/${name}
set tools_dir       ${prefix}/share/${name}/log_tools

post-destroot {
    xinstall -d ${destroot}${doc_dir}
    xinstall -W ${worksrcpath} -m 0644 README.md README.SSL ${destroot}${doc_dir}

    xinstall -d ${destroot}${tools_dir}
    foreach f [glob -types {f x} -directory ${worksrcpath}/log_tools *] {
        xinstall -m 0755 ${f} ${destroot}${tools_dir}
    }
}

livecheck.regex     ${name}-((?:\\d+-){2}\\D+\\d+\[a-z\]?)

notes "
Read ${homepage}/docs/readme/config_files/ for configuration file structure.
Create ${prefix}/etc/${name}/${name}_site.conf to store local config options and overrides.
Changes to *.conf files other than ${name}_site.conf are LOST on upgrades/installs.
Additional tools to handle *.kismet files are in ${tools_dir}.

Run ${name} as a standard/regular user only.
*** DO NOT RUN ${name} AS root ***
*** DO NOT RUN \"sudo ${name}\"  ***
"
