From 9c31a3ea2d70b5f58a579e4e40f53bcefdf6821a Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sun, 22 Sep 2024 00:57:35 -0400 Subject: [PATCH] darwin.libpcap: init at 135 --- .../apple-source-releases/libpcap/package.nix | 127 ++++++++++++++++++ .../apple-source-releases/versions.json | 4 + 2 files changed, 131 insertions(+) create mode 100644 pkgs/os-specific/darwin/apple-source-releases/libpcap/package.nix diff --git a/pkgs/os-specific/darwin/apple-source-releases/libpcap/package.nix b/pkgs/os-specific/darwin/apple-source-releases/libpcap/package.nix new file mode 100644 index 000000000000..18cde19f1200 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-source-releases/libpcap/package.nix @@ -0,0 +1,127 @@ +{ + lib, + apple-sdk_11, + # apple-sdk_15, + bison, + bluez, + fetchFromGitHub, + flex, + mkAppleDerivation, + stdenv, + stdenvNoCC, + unifdef, + # Provided for compatibility with the top-level derivation. + withBluez ? false, + withRemote ? false, +}: + +let + # Get it from the SDK once the 15.0 SDK is available in nixpkgs. + # xnu = apple-sdk_15.sourceRelease "xnu"; + + xnu = fetchFromGitHub { + owner = "apple-oss-distributions"; + repo = "xnu"; + rev = "xnu-11215.1.10"; + hash = "sha256-9cFPrWtTpCb02YrvKX1KWoExoH2VjPdOBU4dscmKL4A="; + }; + + privateHeaders = stdenvNoCC.mkDerivation { + name = "libpcap-deps-private-headers"; + + nativeBuildInputs = [ unifdef ]; + + buildCommand = '' + mkdir -p "$out/include/net" + unifdef -x 1 -DPRIVATE -o "$out/include/net/droptap.h" '${xnu}/bsd/net/droptap.h' + unifdef -x 1 -DPRIVATE -o "$out/include/net/iptap.h" '${xnu}/bsd/net/iptap.h' + unifdef -x 1 -DPRIVATE -o "$out/include/net/pktap.h" '${xnu}/bsd/net/pktap.h' + + cat < "$out/include/net/bpf.h" + #pragma once + #include_next + $(sed -n \ + -e '/^struct bpf_comp_stats\s*{/,/};/p' \ + -e '/^struct bpf_hdr_ext\s*{/,/};/p' \ + -e '/^#define BIOCGBATCHWRITE\s/p' \ + -e '/^#define BIOCGHDRCOMPSTATS\s/p' \ + -e '/^#define BIOCGIFATTACHCOUNT\s/p' \ + -e '/^#define BIOCGWRITEMAX\s/p' \ + -e '/^#define BIOCSBATCHWRITE\s/p' \ + -e '/^#define BIOCSEXTHDR\s/p' \ + -e '/^#define BIOCSHEADDROP\s/p' \ + -e '/^#define BIOCSPKTHDRV2\s/p' \ + -e '/^#define BIOCSTRUNCATE\s/p' \ + -e '/^#define BIOCSWANTPKTAP\s/p' \ + -e '/^#define BIOCSWRITEMAX\s/p' \ + '${xnu}/bsd/net/bpf.h') + EOF + + cat < "$out/include/net/if.h" + #pragma once + #include_next + #include + EOF + + cat < "$out/include/net/if_private.h" + #pragma once + $(sed -n \ + -e '/^#define IF_DESCSIZE\s/p' \ + -e '/^struct if_descreq\s*{/,/};/p' \ + '${xnu}/bsd/net/if_private.h') + EOF + + mkdir -p "$out/include/sys" + + cat < "$out/include/sys/socket.h" + #pragma once + #include + #include + $(sed -n \ + -e '/^#define SO_TC/p' \ + '${xnu}/bsd/sys/socket_private.h') + #include_next + EOF + + cat < "$out/include/sys/sockio.h" + #pragma once + $(sed -n \ + -e '/^#define SIOCGIFDESC\s/p' \ + -e '/^#define SIOCSIFDESC\s/p' \ + '${xnu}/bsd/sys/sockio_private.h') + #include_next + EOF + ''; + }; +in +mkAppleDerivation { + releaseName = "libpcap"; + + postPatch = '' + substituteInPlace libpcap/Makefile.in \ + --replace-fail '@PLATFORM_C_SRC@' '@PLATFORM_C_SRC@ pcap-darwin.c pcap-util.c pcapng.c' + ''; + + configureFlags = [ + (lib.withFeatureAs true "pcap" (if stdenv.hostPlatform.isLinux then "linux" else "bpf")) + (lib.enableFeature withRemote "remote") + ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ (lib.enableFeature false "universal") ]; + + preConfigure = '' + cd libpcap + ''; + + env.NIX_CFLAGS_COMPILE = "-DHAVE_PKTAP_API -I${privateHeaders}/include"; + + nativeBuildInputs = [ + bison + flex + ] ++ lib.optionals withBluez [ bluez.dev ]; + + buildInputs = [ apple-sdk_11 ]; + + meta = { + description = "Packet Capture Library (with Apple modifications)"; + mainProgram = "pcap-config"; + }; +} diff --git a/pkgs/os-specific/darwin/apple-source-releases/versions.json b/pkgs/os-specific/darwin/apple-source-releases/versions.json index 38e392f8d0e9..4ca1d0645f48 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/versions.json +++ b/pkgs/os-specific/darwin/apple-source-releases/versions.json @@ -55,6 +55,10 @@ "hash": "sha256-4I70hci8SUQ5QERbImP3htjYCGXdZZ0a6RM7ggUnVa4=", "version": "107" }, + "libpcap": { + "hash": "sha256-x5mKK6LXGS3LBRUVNZwxA750a0NoRScTpoDUsumlg+s=", + "version": "135" + }, "libresolv": { "hash": "sha256-FtvwjJKSFX6j9APYPC8WLXVOjbHLZa1Gcoc8yxLy8qE=", "version": "64"