1{ lib
2, stdenv
3, fetchurl
4, flex
5, bison
6, bluez
7, libnl
8, libxcrypt
9, pkg-config
10, withBluez ? false
11, withRemote ? false
12
13# for passthru.tests
14, ettercap
15, nmap
16, ostinato
17, tcpreplay
18, vde2
19, wireshark
20, python3
21, haskellPackages
22}:
23
24stdenv.mkDerivation rec {
25 pname = "libpcap";
26 version = "1.10.4";
27
28 src = fetchurl {
29 url = "https://www.tcpdump.org/release/${pname}-${version}.tar.gz";
30 hash = "sha256-7RmgOD+tcuOtQ1/SOdfNgNZJFrhyaVUBWdIORxYOvl8=";
31 };
32
33 buildInputs = lib.optionals stdenv.isLinux [ libnl ]
34 ++ lib.optionals withRemote [ libxcrypt ];
35
36 nativeBuildInputs = [ flex bison ]
37 ++ lib.optionals stdenv.isLinux [ pkg-config ]
38 ++ lib.optionals withBluez [ bluez.dev ];
39
40 # We need to force the autodetection because detection doesn't
41 # work in pure build environments.
42 configureFlags = [
43 "--with-pcap=${if stdenv.isLinux then "linux" else "bpf"}"
44 ] ++ lib.optionals stdenv.isDarwin [
45 "--disable-universal"
46 ] ++ lib.optionals withRemote [
47 "--enable-remote"
48 ] ++ lib.optionals (stdenv.hostPlatform == stdenv.buildPlatform)
49 [ "ac_cv_linux_vers=2" ];
50
51 postInstall = ''
52 if [ "$dontDisableStatic" -ne "1" ]; then
53 rm -f $out/lib/libpcap.a
54 fi
55 '';
56
57 passthru.tests = {
58 inherit ettercap nmap ostinato tcpreplay vde2 wireshark;
59 inherit (python3.pkgs) pcapy-ng scapy;
60 haskell-pcap = haskellPackages.pcap;
61 };
62
63 meta = with lib; {
64 homepage = "https://www.tcpdump.org";
65 description = "Packet Capture Library";
66 mainProgram = "pcap-config";
67 platforms = platforms.unix;
68 maintainers = with maintainers; [ fpletz ];
69 license = licenses.bsd3;
70 };
71}