pycapng 0.7__tar.gz → 0.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. pycapng-0.8/.github/workflows/windows-library.yml +118 -0
  2. {pycapng-0.7 → pycapng-0.8}/CMakeLists.txt +8 -1
  3. {pycapng-0.7 → pycapng-0.8}/PKG-INFO +1 -1
  4. {pycapng-0.7 → pycapng-0.8}/bindings/python/pycapng.cpp +18 -0
  5. {pycapng-0.7 → pycapng-0.8}/lib/CMakeLists.txt +8 -0
  6. {pycapng-0.7 → pycapng-0.8}/lib/capture.c +64 -13
  7. {pycapng-0.7 → pycapng-0.8}/lib/dissect.c +5 -1
  8. pycapng-0.8/lib/include/libpcapng/win_compat.h +44 -0
  9. {pycapng-0.7 → pycapng-0.8}/lib/protocols/dhcp.c +5 -1
  10. {pycapng-0.7 → pycapng-0.8}/lib/protocols/dns.c +5 -1
  11. {pycapng-0.7 → pycapng-0.8}/lib/protocols/icmp.c +5 -1
  12. {pycapng-0.7 → pycapng-0.8}/lib/protocols/ipv4.c +5 -1
  13. {pycapng-0.7 → pycapng-0.8}/lib/protocols/ntp.c +5 -1
  14. {pycapng-0.7 → pycapng-0.8}/lib/protocols/rdp.c +5 -1
  15. {pycapng-0.7 → pycapng-0.8}/lib/protocols/ssl.c +5 -1
  16. {pycapng-0.7 → pycapng-0.8}/lib/protocols/tcp.c +5 -1
  17. {pycapng-0.7 → pycapng-0.8}/lib/protocols/udp.c +5 -1
  18. {pycapng-0.7 → pycapng-0.8}/.github/workflows/build.yml +0 -0
  19. {pycapng-0.7 → pycapng-0.8}/.github/workflows/release.yml +0 -0
  20. {pycapng-0.7 → pycapng-0.8}/.gitignore +0 -0
  21. {pycapng-0.7 → pycapng-0.8}/LICENSE +0 -0
  22. {pycapng-0.7 → pycapng-0.8}/README-pypi.md +0 -0
  23. {pycapng-0.7 → pycapng-0.8}/README.md +0 -0
  24. {pycapng-0.7 → pycapng-0.8}/Tutorial.md +0 -0
  25. {pycapng-0.7 → pycapng-0.8}/Tutorial2.md +0 -0
  26. {pycapng-0.7 → pycapng-0.8}/VERSION +0 -0
  27. {pycapng-0.7 → pycapng-0.8}/bin/CMakeLists.txt +0 -0
  28. {pycapng-0.7 → pycapng-0.8}/bin/linenoise/linenoise.c +0 -0
  29. {pycapng-0.7 → pycapng-0.8}/bin/linenoise/linenoise.h +0 -0
  30. {pycapng-0.7 → pycapng-0.8}/bin/pcapsh.c +0 -0
  31. {pycapng-0.7 → pycapng-0.8}/bin/pcapsh.h +0 -0
  32. {pycapng-0.7 → pycapng-0.8}/bin/pcapsh.md +0 -0
  33. {pycapng-0.7 → pycapng-0.8}/bin/pcapsh_eval.c +0 -0
  34. {pycapng-0.7 → pycapng-0.8}/bin/pcapsh_io.c +0 -0
  35. {pycapng-0.7 → pycapng-0.8}/bin/pcapsh_layer.c +0 -0
  36. {pycapng-0.7 → pycapng-0.8}/bin/pcapsh_main.c +0 -0
  37. {pycapng-0.7 → pycapng-0.8}/bin/pcapsh_posa.c +0 -0
  38. {pycapng-0.7 → pycapng-0.8}/bin/protos/ah.posa +0 -0
  39. {pycapng-0.7 → pycapng-0.8}/bin/protos/amqp.posa +0 -0
  40. {pycapng-0.7 → pycapng-0.8}/bin/protos/bacnet.posa +0 -0
  41. {pycapng-0.7 → pycapng-0.8}/bin/protos/bfd.posa +0 -0
  42. {pycapng-0.7 → pycapng-0.8}/bin/protos/bgp.posa +0 -0
  43. {pycapng-0.7 → pycapng-0.8}/bin/protos/cdp.posa +0 -0
  44. {pycapng-0.7 → pycapng-0.8}/bin/protos/coap.posa +0 -0
  45. {pycapng-0.7 → pycapng-0.8}/bin/protos/dccp.posa +0 -0
  46. {pycapng-0.7 → pycapng-0.8}/bin/protos/dhcpv6.posa +0 -0
  47. {pycapng-0.7 → pycapng-0.8}/bin/protos/dnp3.posa +0 -0
  48. {pycapng-0.7 → pycapng-0.8}/bin/protos/dot1q.posa +0 -0
  49. {pycapng-0.7 → pycapng-0.8}/bin/protos/eap.posa +0 -0
  50. {pycapng-0.7 → pycapng-0.8}/bin/protos/eapol.posa +0 -0
  51. {pycapng-0.7 → pycapng-0.8}/bin/protos/eapol_key.posa +0 -0
  52. {pycapng-0.7 → pycapng-0.8}/bin/protos/eigrp.posa +0 -0
  53. {pycapng-0.7 → pycapng-0.8}/bin/protos/esp.posa +0 -0
  54. {pycapng-0.7 → pycapng-0.8}/bin/protos/hsrp.posa +0 -0
  55. {pycapng-0.7 → pycapng-0.8}/bin/protos/icmpv6.posa +0 -0
  56. {pycapng-0.7 → pycapng-0.8}/bin/protos/igmp.posa +0 -0
  57. {pycapng-0.7 → pycapng-0.8}/bin/protos/ikev2.posa +0 -0
  58. {pycapng-0.7 → pycapng-0.8}/bin/protos/ipv6.posa +0 -0
  59. {pycapng-0.7 → pycapng-0.8}/bin/protos/isakmp.posa +0 -0
  60. {pycapng-0.7 → pycapng-0.8}/bin/protos/kerberos.posa +0 -0
  61. {pycapng-0.7 → pycapng-0.8}/bin/protos/l2tp.posa +0 -0
  62. {pycapng-0.7 → pycapng-0.8}/bin/protos/lacp.posa +0 -0
  63. {pycapng-0.7 → pycapng-0.8}/bin/protos/llc.posa +0 -0
  64. {pycapng-0.7 → pycapng-0.8}/bin/protos/modbus_tcp.posa +0 -0
  65. {pycapng-0.7 → pycapng-0.8}/bin/protos/mpls.posa +0 -0
  66. {pycapng-0.7 → pycapng-0.8}/bin/protos/mqtt.posa +0 -0
  67. {pycapng-0.7 → pycapng-0.8}/bin/protos/nbns.posa +0 -0
  68. {pycapng-0.7 → pycapng-0.8}/bin/protos/netflow_v5.posa +0 -0
  69. {pycapng-0.7 → pycapng-0.8}/bin/protos/openflow.posa +0 -0
  70. {pycapng-0.7 → pycapng-0.8}/bin/protos/ospf.posa +0 -0
  71. {pycapng-0.7 → pycapng-0.8}/bin/protos/pim.posa +0 -0
  72. {pycapng-0.7 → pycapng-0.8}/bin/protos/ppp.posa +0 -0
  73. {pycapng-0.7 → pycapng-0.8}/bin/protos/pppoe.posa +0 -0
  74. {pycapng-0.7 → pycapng-0.8}/bin/protos/ptpv2.posa +0 -0
  75. {pycapng-0.7 → pycapng-0.8}/bin/protos/rdp.posa +0 -0
  76. {pycapng-0.7 → pycapng-0.8}/bin/protos/ripv2.posa +0 -0
  77. {pycapng-0.7 → pycapng-0.8}/bin/protos/rsvp.posa +0 -0
  78. {pycapng-0.7 → pycapng-0.8}/bin/protos/rtp.posa +0 -0
  79. {pycapng-0.7 → pycapng-0.8}/bin/protos/sctp.posa +0 -0
  80. {pycapng-0.7 → pycapng-0.8}/bin/protos/snap.posa +0 -0
  81. {pycapng-0.7 → pycapng-0.8}/bin/protos/socks5.posa +0 -0
  82. {pycapng-0.7 → pycapng-0.8}/bin/protos/stp.posa +0 -0
  83. {pycapng-0.7 → pycapng-0.8}/bin/protos/stun.posa +0 -0
  84. {pycapng-0.7 → pycapng-0.8}/bin/protos/vrrp.posa +0 -0
  85. {pycapng-0.7 → pycapng-0.8}/bin/protos/wol.posa +0 -0
  86. {pycapng-0.7 → pycapng-0.8}/bin/tests/run_tests.sh +0 -0
  87. {pycapng-0.7 → pycapng-0.8}/bin/tests/test_cstring_security.pcapsh +0 -0
  88. {pycapng-0.7 → pycapng-0.8}/bin/tests/test_dns.pcapsh +0 -0
  89. {pycapng-0.7 → pycapng-0.8}/bin/tests/test_forloop.pcapsh +0 -0
  90. {pycapng-0.7 → pycapng-0.8}/bin/tests/test_inline_protocol.pcapsh +0 -0
  91. {pycapng-0.7 → pycapng-0.8}/bin/tests/test_posa_custom.pcapsh +0 -0
  92. {pycapng-0.7 → pycapng-0.8}/bin/tests/test_protocols.pcapsh +0 -0
  93. {pycapng-0.7 → pycapng-0.8}/bin/tests/test_raw_inspect.pcapsh +0 -0
  94. {pycapng-0.7 → pycapng-0.8}/bin/tests/test_tcp_session.pcapsh +0 -0
  95. {pycapng-0.7 → pycapng-0.8}/bin/tests/test_tftp.pcapsh +0 -0
  96. {pycapng-0.7 → pycapng-0.8}/bin/tests/test_wireshark_samples.pcapsh +0 -0
  97. {pycapng-0.7 → pycapng-0.8}/bin/tests/tftp_protos.posa +0 -0
  98. {pycapng-0.7 → pycapng-0.8}/bindings/CMakeLists.txt +0 -0
  99. {pycapng-0.7 → pycapng-0.8}/bindings/python/CMakeLists.txt +0 -0
  100. {pycapng-0.7 → pycapng-0.8}/bindings/python/embed_protos.py +0 -0
  101. {pycapng-0.7 → pycapng-0.8}/bindings/python/examples/capture_tui.py +0 -0
  102. {pycapng-0.7 → pycapng-0.8}/bindings/python/examples/live_capture.py +0 -0
  103. {pycapng-0.7 → pycapng-0.8}/bindings/python/examples/pcapsh_callback.py +0 -0
  104. {pycapng-0.7 → pycapng-0.8}/bindings/python/examples/pcapsh_custom_protocol.py +0 -0
  105. {pycapng-0.7 → pycapng-0.8}/bindings/python/examples/pcapsh_inline.py +0 -0
  106. {pycapng-0.7 → pycapng-0.8}/bindings/python/examples/pcapsh_run_script.py +0 -0
  107. {pycapng-0.7 → pycapng-0.8}/bindings/python/examples/pcapsh_tls_https.py +0 -0
  108. {pycapng-0.7 → pycapng-0.8}/bindings/python/examples/read.py +0 -0
  109. {pycapng-0.7 → pycapng-0.8}/bindings/python/examples/write_rdp.py +0 -0
  110. {pycapng-0.7 → pycapng-0.8}/bindings/python/examples/write_tcp.py +0 -0
  111. {pycapng-0.7 → pycapng-0.8}/bindings/python/pycapng.hpp +0 -0
  112. {pycapng-0.7 → pycapng-0.8}/bindings/python/pycapture.cpp +0 -0
  113. {pycapng-0.7 → pycapng-0.8}/bindings/python/pypcapsh.cpp +0 -0
  114. {pycapng-0.7 → pycapng-0.8}/bindings/python/tests/__init__.py +0 -0
  115. {pycapng-0.7 → pycapng-0.8}/bindings/python/tests/test_pcapsh.py +0 -0
  116. {pycapng-0.7 → pycapng-0.8}/lib/blocks.c +0 -0
  117. {pycapng-0.7 → pycapng-0.8}/lib/easyapi.c +0 -0
  118. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/blocks.h +0 -0
  119. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/capture.h +0 -0
  120. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/dissect.h +0 -0
  121. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/easyapi.h +0 -0
  122. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/io.h +0 -0
  123. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/libpcapng.h +0 -0
  124. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/linktypes.h +0 -0
  125. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/objects.h +0 -0
  126. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/posa.h +0 -0
  127. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/asn1.h +0 -0
  128. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/bootp.h +0 -0
  129. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/dhcp.h +0 -0
  130. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/dns.h +0 -0
  131. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/ethernet.h +0 -0
  132. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/flow.h +0 -0
  133. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/http2.h +0 -0
  134. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/http2_hpack.h +0 -0
  135. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/http2_stream.h +0 -0
  136. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/icmp.h +0 -0
  137. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/ipv4.h +0 -0
  138. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/ntp.h +0 -0
  139. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/rdp.h +0 -0
  140. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/ssh.h +0 -0
  141. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/ssl.h +0 -0
  142. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/tcp.h +0 -0
  143. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/tcp_mss.h +0 -0
  144. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/tls_stream.h +0 -0
  145. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/protocols/udp.h +0 -0
  146. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/reassembly.h +0 -0
  147. {pycapng-0.7 → pycapng-0.8}/lib/include/libpcapng/reassembly_tcp.h +0 -0
  148. {pycapng-0.7 → pycapng-0.8}/lib/io.c +0 -0
  149. {pycapng-0.7 → pycapng-0.8}/lib/objects.c +0 -0
  150. {pycapng-0.7 → pycapng-0.8}/lib/posa.c +0 -0
  151. {pycapng-0.7 → pycapng-0.8}/lib/protocols/asn1.c +0 -0
  152. {pycapng-0.7 → pycapng-0.8}/lib/protocols/ethernet.c +0 -0
  153. {pycapng-0.7 → pycapng-0.8}/lib/protocols/flow.c +0 -0
  154. {pycapng-0.7 → pycapng-0.8}/lib/protocols/http2.c +0 -0
  155. {pycapng-0.7 → pycapng-0.8}/lib/protocols/http2_hpack.c +0 -0
  156. {pycapng-0.7 → pycapng-0.8}/lib/protocols/http2_stream.c +0 -0
  157. {pycapng-0.7 → pycapng-0.8}/lib/protocols/ssh.c +0 -0
  158. {pycapng-0.7 → pycapng-0.8}/lib/protocols/tcp_mss.c +0 -0
  159. {pycapng-0.7 → pycapng-0.8}/lib/protocols/tls_stream.c +0 -0
  160. {pycapng-0.7 → pycapng-0.8}/lib/reassembly.c +0 -0
  161. {pycapng-0.7 → pycapng-0.8}/lib/reassembly_tcp.c +0 -0
  162. {pycapng-0.7 → pycapng-0.8}/lib/tests/CMakeLists.txt +0 -0
  163. {pycapng-0.7 → pycapng-0.8}/lib/tests/dhcp-write.c +0 -0
  164. {pycapng-0.7 → pycapng-0.8}/lib/tests/dns-write.c +0 -0
  165. {pycapng-0.7 → pycapng-0.8}/lib/tests/ntp-write.c +0 -0
  166. {pycapng-0.7 → pycapng-0.8}/lib/tests/pcapng-spec.c +0 -0
  167. {pycapng-0.7 → pycapng-0.8}/lib/tests/rdp-write.c +0 -0
  168. {pycapng-0.7 → pycapng-0.8}/lib/tests/read.c +0 -0
  169. {pycapng-0.7 → pycapng-0.8}/lib/tests/reasm.c +0 -0
  170. {pycapng-0.7 → pycapng-0.8}/lib/tests/ssl-http2-write.c +0 -0
  171. {pycapng-0.7 → pycapng-0.8}/lib/tests/tcp-sequence.c +0 -0
  172. {pycapng-0.7 → pycapng-0.8}/lib/tests/writeall.c +0 -0
  173. {pycapng-0.7 → pycapng-0.8}/libpcapng.pc.cmake +0 -0
  174. {pycapng-0.7 → pycapng-0.8}/pyproject.toml +0 -0
@@ -0,0 +1,118 @@
1
+ name: windows library
2
+
3
+ # Publishes libpcapng as a consumable Windows C library — the DLL, the MinGW
4
+ # import library, a static lib and the headers — attached to the GitHub release.
5
+ # (The wheels in release.yml are the Python story; this is the C one.)
6
+ #
7
+ # Live capture has no Windows backend: capture.c compiles its "unsupported
8
+ # platform" stubs there, so the library is file-analysis only. See win_compat.h.
9
+
10
+ on:
11
+ push:
12
+ tags: ['v*']
13
+ workflow_dispatch:
14
+
15
+ jobs:
16
+ windows-library:
17
+ name: windows-x86_64
18
+ runs-on: windows-latest
19
+ permissions:
20
+ contents: write # to attach assets to the release
21
+ defaults:
22
+ run:
23
+ shell: msys2 {0}
24
+
25
+ steps:
26
+ - uses: msys2/setup-msys2@v2
27
+ with:
28
+ msystem: UCRT64
29
+ update: true
30
+ # libpcapng has no external dependencies — just a toolchain.
31
+ pacboy: toolchain:p cmake:p ninja:p
32
+ install: zip
33
+
34
+ - uses: actions/checkout@v4
35
+
36
+ - name: Build
37
+ run: |
38
+ # The Python bindings need pybind11 at configure time and are off by
39
+ # default on Windows; be explicit so this doesn't depend on that.
40
+ cmake -S . -B build -G Ninja \
41
+ -DCMAKE_BUILD_TYPE=Release \
42
+ -DLIBPCAPNG_BINDINGS=OFF
43
+ cmake --build build --target pcapng pcapng_static -j "$(nproc)"
44
+
45
+ - name: Package
46
+ id: pkg
47
+ run: |
48
+ VERSION="${GITHUB_REF_NAME#v}"
49
+ case "$GITHUB_REF" in refs/tags/*) ;; *) VERSION="dev" ;; esac
50
+ NAME="libpcapng-$VERSION-windows-x86_64"
51
+ OUT="dist/$NAME"
52
+ mkdir -p "$OUT/bin" "$OUT/lib" "$OUT/include"
53
+
54
+ cp build/lib/libpcapng.dll "$OUT/bin/"
55
+ cp build/lib/libpcapng.dll.a "$OUT/lib/"
56
+ cp build/lib/libpcapng_static.a "$OUT/lib/" 2>/dev/null || true
57
+ cp -R lib/include/libpcapng "$OUT/include/"
58
+
59
+ # Ship the MinGW runtime DLLs the library was linked against, so the
60
+ # zip works without an MSYS2 install. /c/Windows DLLs are the OS's.
61
+ ldd "$OUT/bin/libpcapng.dll" | awk '/=>/ {print $3}' | while read -r dll; do
62
+ [ -f "$dll" ] || continue
63
+ case "$(printf '%s' "$dll" | tr 'A-Z' 'a-z')" in /c/windows/*) continue ;; esac
64
+ cp -f "$dll" "$OUT/bin/"
65
+ done
66
+
67
+ cat > "$OUT/README.txt" <<'TXT'
68
+ libpcapng — Windows (MinGW-w64 / UCRT64) C library
69
+
70
+ include/ headers — add to your include path
71
+ lib/ libpcapng.dll.a (import lib), libpcapng_static.a
72
+ bin/ libpcapng.dll + the MinGW runtime DLLs it needs
73
+
74
+ Link with -lpcapng -lws2_32 (the dissectors use ntohs/inet_ntop).
75
+
76
+ Built with MinGW-w64/UCRT64. The import library is ELF-style .dll.a for
77
+ GCC/Clang; MSVC users must generate a .lib from the DLL themselves.
78
+
79
+ Live capture is NOT supported on Windows — the capture API compiles to
80
+ stubs that fail cleanly. Reading and dissecting capture files works.
81
+ TXT
82
+
83
+ ( cd dist && zip -qr "$NAME.zip" "$NAME" )
84
+ echo "zip=dist/$NAME.zip" >> "$GITHUB_OUTPUT"
85
+
86
+ - name: Smoke-test the import library
87
+ run: |
88
+ # Link a real consumer against the packaged import lib + headers: this
89
+ # is what proves the zip is actually usable, not just that it built.
90
+ NAME="$(basename "${{ steps.pkg.outputs.zip }}" .zip)"
91
+ cat > /tmp/consumer.c <<'C'
92
+ #include <libpcapng/capture.h>
93
+ #include <stdio.h>
94
+ int main(void) {
95
+ char err[PCAPNG_CAPTURE_ERRBUF_SIZE] = {0};
96
+ int n = -1;
97
+ /* Windows has no capture backend: expect an empty device list and
98
+ a clean error, not a crash. */
99
+ pcapng_capture_list_devices(&n, err);
100
+ printf("devices=%d err=%s\n", n, err);
101
+ return n == 0 ? 0 : 1;
102
+ }
103
+ C
104
+ gcc /tmp/consumer.c -o /tmp/consumer.exe \
105
+ -I"dist/$NAME/include" -L"dist/$NAME/lib" -lpcapng -lws2_32
106
+ cp dist/$NAME/bin/*.dll /tmp/
107
+ /tmp/consumer.exe
108
+
109
+ - uses: actions/upload-artifact@v4
110
+ with:
111
+ name: libpcapng-windows-x86_64
112
+ path: ${{ steps.pkg.outputs.zip }}
113
+
114
+ - name: Attach to release
115
+ if: startsWith(github.ref, 'refs/tags/')
116
+ uses: softprops/action-gh-release@v2
117
+ with:
118
+ files: ${{ steps.pkg.outputs.zip }}
@@ -37,7 +37,14 @@ install(FILES "${libpcapng_BINARY_DIR}/libpcapng.pc" DESTINATION "${CMAKE_INSTAL
37
37
 
38
38
  include_directories(AFTER ${libpcapng_SOURCE_DIR}/lib/include)
39
39
 
40
- option(LIBPCAPNG_BINDINGS "Build the Python (pybind11) bindings" ON)
40
+ # The Python bindings need pybind11 at configure time; the Windows packaging
41
+ # build only wants the C library, so default them off there.
42
+ if(WIN32)
43
+ set(_bindings_default OFF)
44
+ else()
45
+ set(_bindings_default ON)
46
+ endif()
47
+ option(LIBPCAPNG_BINDINGS "Build the Python (pybind11) bindings" ${_bindings_default})
41
48
  if(LIBPCAPNG_BINDINGS)
42
49
  find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
43
50
  set(PYBIND11_FINDPYTHON ON)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pycapng
3
- Version: 0.7
3
+ Version: 0.8
4
4
  Summary: Python bindings for libpcapng — read/write pcapng files and live packet capture
5
5
  Keywords: pcapng,pcap,packet-capture,network,packet,wireshark
6
6
  Author-Email: Seb Tricaud <sebastien.tricaud@proton.me>
@@ -708,6 +708,24 @@ int PcapNG::foreach_packet_cb(uint32_t block_counter, uint32_t block_type, uint3
708
708
  return 0;
709
709
  }
710
710
 
711
+ if (block_type == PCAPNG_SIMPLE_PACKET_BLOCK) {
712
+ /*
713
+ * SPB body: orig_len(4) + pkt_data(min(orig_len, block_total_length-16) bytes, padded)
714
+ *
715
+ * Pass orig_len(4) + exact captured bytes (no padding) to Python.
716
+ * Using the block size avoids libpcapng_padded_count, which incorrectly
717
+ * strips payload bytes whose values happen to be 0x00.
718
+ */
719
+ if (block_total_length < 16) return 0;
720
+ uint32_t orig_len;
721
+ memcpy(&orig_len, data, 4);
722
+ uint32_t captured = block_total_length - 16;
723
+ uint32_t pkt_len = (orig_len < captured) ? orig_len : captured;
724
+ cb_func(block_counter, block_type, block_total_length,
725
+ py::bytes((const char *)data, 4 + pkt_len));
726
+ return 0;
727
+ }
728
+
711
729
  // For other block types (SHB, CDB, …) use the generic CDB-based extraction.
712
730
  uint32_t start_offset = libpcapng_custom_data_block_start_offset();
713
731
  uint32_t data_length = libpcapng_custom_data_block_data_length(block_total_length);
@@ -77,6 +77,14 @@ set(CMAKE_INSTALL_RPATH "@rpath")
77
77
  add_library(pcapng_static STATIC ${LIBPCAPNG_SOURCES})
78
78
  set_target_properties(pcapng_static PROPERTIES SOVERSION 1 POSITION_INDEPENDENT_CODE ON)
79
79
 
80
+ if(WIN32)
81
+ # ntohs/inet_ntop & friends live in ws2_32 (see win_compat.h). Exporting all
82
+ # symbols spares us __declspec(dllexport) annotations on the whole public API.
83
+ target_link_libraries(pcapng PRIVATE ws2_32)
84
+ target_link_libraries(pcapng_static PRIVATE ws2_32)
85
+ set_target_properties(pcapng PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
86
+ endif()
87
+
80
88
  install(TARGETS pcapng LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} COMPONENT Libraries)
81
89
  install(TARGETS pcapng_static LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} COMPONENT Libraries)
82
90
  # Install the header tree preserving the protocols/ subdirectory, so consumers
@@ -24,16 +24,24 @@
24
24
  #include <time.h>
25
25
 
26
26
  #include <sys/types.h>
27
- #include <sys/socket.h>
28
- #include <sys/mman.h>
29
- #include <sys/ioctl.h>
30
- #include <net/if.h>
31
- #include <ifaddrs.h>
32
- #include <poll.h>
33
- #include <unistd.h>
34
- #include <fcntl.h>
35
- #include <arpa/inet.h>
36
- #include <netinet/in.h>
27
+
28
+ /* Windows has no capture backend (see the platform stubs at the bottom of this
29
+ file), so it needs none of the POSIX socket/mmap machinery — only the byte
30
+ order + inet_ntop helpers the display-filter engine uses. */
31
+ #ifdef _WIN32
32
+ # include <libpcapng/win_compat.h>
33
+ #else
34
+ # include <sys/socket.h>
35
+ # include <sys/mman.h>
36
+ # include <sys/ioctl.h>
37
+ # include <net/if.h>
38
+ # include <ifaddrs.h>
39
+ # include <poll.h>
40
+ # include <unistd.h>
41
+ # include <fcntl.h>
42
+ # include <arpa/inet.h>
43
+ # include <netinet/in.h>
44
+ #endif
37
45
 
38
46
  #if defined(__linux__)
39
47
  # include <linux/if_packet.h>
@@ -725,6 +733,11 @@ struct pcapng_capture {
725
733
  int fd;
726
734
  uint8_t *bpf_buf;
727
735
  size_t bpf_buf_size;
736
+ #else
737
+ /* Unsupported platform (e.g. Windows): the stub backend never opens
738
+ anything, but the platform-independent layer still tests cap->fd to
739
+ decide whether to activate, so the member has to exist. */
740
+ int fd;
728
741
  #endif
729
742
  };
730
743
 
@@ -734,18 +747,50 @@ static void sigint_handler(int sig) { (void)sig; g_sigint = 1; }
734
747
 
735
748
  static void install_sigint_handler(void)
736
749
  {
750
+ #ifdef _WIN32
751
+ /* No sigaction on Windows; the CRT's signal() is enough to set the flag. */
752
+ signal(SIGINT, sigint_handler);
753
+ #else
737
754
  struct sigaction sa;
738
755
  memset(&sa, 0, sizeof sa);
739
756
  sa.sa_handler = sigint_handler;
740
757
  sigemptyset(&sa.sa_mask);
741
758
  sa.sa_flags = SA_RESTART;
742
759
  sigaction(SIGINT, &sa, NULL);
760
+ #endif
743
761
  }
744
762
 
745
763
  /* ========================================================================
746
764
  * Device enumeration
747
765
  * ======================================================================== */
748
766
 
767
+ #ifdef _WIN32
768
+
769
+ /* Windows has no capture backend, so there is nothing to enumerate. Report the
770
+ empty list rather than a hard error: callers (carcal's interface chooser)
771
+ show the message and carry on with file-based analysis. */
772
+ pcapng_device_t *pcapng_capture_list_devices(int *count, char *errbuf)
773
+ {
774
+ if (errbuf) snprintf(errbuf, PCAPNG_CAPTURE_ERRBUF_SIZE,
775
+ "live capture not supported on this platform");
776
+ if (count) *count = 0;
777
+ return NULL;
778
+ }
779
+
780
+ void pcapng_capture_free_devices(pcapng_device_t *devs)
781
+ {
782
+ free(devs);
783
+ }
784
+
785
+ const char *pcapng_capture_default_device(char *errbuf)
786
+ {
787
+ if (errbuf) snprintf(errbuf, PCAPNG_CAPTURE_ERRBUF_SIZE,
788
+ "live capture not supported on this platform");
789
+ return NULL;
790
+ }
791
+
792
+ #else /* !_WIN32 */
793
+
749
794
  pcapng_device_t *pcapng_capture_list_devices(int *count, char *errbuf)
750
795
  {
751
796
  struct ifaddrs *ifa_head = NULL, *ifa;
@@ -817,6 +862,8 @@ const char *pcapng_capture_default_device(char *errbuf)
817
862
  return found;
818
863
  }
819
864
 
865
+ #endif /* !_WIN32 */
866
+
820
867
  /* ========================================================================
821
868
  * Open / configure
822
869
  * ======================================================================== */
@@ -852,6 +899,8 @@ pcapng_capture_t *pcapng_capture_open(const char *device, char *errbuf)
852
899
  cap->fd = -1;
853
900
  cap->bpf_buf = NULL;
854
901
  cap->bpf_buf_size = CAP_BPF_BUF_SIZE;
902
+ #else
903
+ cap->fd = -1; /* stub backend: never opened, but tested before use */
855
904
  #endif
856
905
 
857
906
  return cap;
@@ -1323,7 +1372,7 @@ int pcapng_capture_dispatch(pcapng_capture_t *cap, int count,
1323
1372
  defined(__OpenBSD__) || defined(__NetBSD__)
1324
1373
  return bsd_dispatch(cap, count, cb, userdata);
1325
1374
  #else
1326
- return -1;
1375
+ return stub_dispatch(cap, count, cb, userdata);
1327
1376
  #endif
1328
1377
  }
1329
1378
 
@@ -1351,7 +1400,7 @@ int pcapng_capture_loop(pcapng_capture_t *cap, int count,
1351
1400
  defined(__OpenBSD__) || defined(__NetBSD__)
1352
1401
  int n = bsd_dispatch(cap, count > 0 ? count - total : -1, cb, userdata);
1353
1402
  #else
1354
- int n = -1;
1403
+ int n = stub_dispatch(cap, count > 0 ? count - total : -1, cb, userdata);
1355
1404
  #endif
1356
1405
  if (n < 0) return -1;
1357
1406
  total += n;
@@ -1375,7 +1424,7 @@ int pcapng_capture_get_stats(pcapng_capture_t *cap,
1375
1424
  defined(__OpenBSD__) || defined(__NetBSD__)
1376
1425
  return bsd_get_stats(cap, st);
1377
1426
  #else
1378
- return -1;
1427
+ return stub_get_stats(cap, st);
1379
1428
  #endif
1380
1429
  }
1381
1430
 
@@ -1387,6 +1436,8 @@ void pcapng_capture_close(pcapng_capture_t *cap)
1387
1436
  #elif defined(__APPLE__) || defined(__FreeBSD__) || \
1388
1437
  defined(__OpenBSD__) || defined(__NetBSD__)
1389
1438
  bsd_close(cap);
1439
+ #else
1440
+ stub_close(cap);
1390
1441
  #endif
1391
1442
  filter_free(cap->filter);
1392
1443
  free(cap);
@@ -10,7 +10,11 @@
10
10
  #include <stdlib.h>
11
11
  #include <string.h>
12
12
  #include <stdarg.h>
13
- #include <arpa/inet.h>
13
+ #ifdef _WIN32
14
+ # include <libpcapng/win_compat.h>
15
+ #else
16
+ # include <arpa/inet.h>
17
+ #endif
14
18
 
15
19
  #include <libpcapng/protocols/ntp.h> /* struct libpcapng_ntp_hdr (wire layout) */
16
20
  #include <libpcapng/protocols/bootp.h> /* struct libpcapng_bootp_hdr (DHCP/BOOTP) */
@@ -0,0 +1,44 @@
1
+ #ifndef _LIBPCAPNG_WIN_COMPAT_H_
2
+ #define _LIBPCAPNG_WIN_COMPAT_H_
3
+
4
+ /*
5
+ * Windows compatibility shim for libpcapng.
6
+ *
7
+ * The dissectors need only a handful of things from <arpa/inet.h> and
8
+ * <netinet/in.h> — the byte-order helpers, inet_ntop/inet_pton, struct in_addr
9
+ * and AF_INET/AF_INET6. On Windows all of those live in <winsock2.h> and
10
+ * <ws2tcpip.h> instead, so the sources include this header behind #ifdef _WIN32
11
+ * and the real POSIX headers otherwise. Mirrors gtcaca's win_compat.h.
12
+ *
13
+ * Note ntohs/ntohl/htons/htonl come from winsock2 as functions in ws2_32, so a
14
+ * Windows build must link ws2_32 (the CMakeLists does). They do not require
15
+ * WSAStartup — neither do inet_ntop/inet_pton, which are pure conversions.
16
+ *
17
+ * Live capture is a separate matter: it has no Windows backend at all, and
18
+ * capture.c compiles its "unsupported platform" stubs instead. See capture.c.
19
+ */
20
+ #ifdef _WIN32
21
+
22
+ /* Keep <windows.h> lean and stop it dragging in the old <winsock.h>, which
23
+ would collide with the <winsock2.h> we actually want. */
24
+ #ifndef WIN32_LEAN_AND_MEAN
25
+ #define WIN32_LEAN_AND_MEAN
26
+ #endif
27
+ #ifndef NOMINMAX
28
+ #define NOMINMAX
29
+ #endif
30
+
31
+ #include <winsock2.h> /* ntohs/ntohl/htons/htonl, AF_INET, struct in_addr */
32
+ #include <ws2tcpip.h> /* inet_ntop, inet_pton, AF_INET6, struct in6_addr */
33
+ #include <windows.h>
34
+
35
+ /* POSIX spelling used by the dissectors (MSVC lacks it; MinGW has _stricmp). */
36
+ #ifndef strcasecmp
37
+ #define strcasecmp(a, b) _stricmp((a), (b))
38
+ #endif
39
+ #ifndef strncasecmp
40
+ #define strncasecmp(a, b, n) _strnicmp((a), (b), (n))
41
+ #endif
42
+
43
+ #endif /* _WIN32 */
44
+ #endif /* _LIBPCAPNG_WIN_COMPAT_H_ */
@@ -2,7 +2,11 @@
2
2
  #include <stdlib.h>
3
3
  #include <string.h>
4
4
  #include <stdint.h>
5
- #include <arpa/inet.h>
5
+ #ifdef _WIN32
6
+ # include <libpcapng/win_compat.h>
7
+ #else
8
+ # include <arpa/inet.h>
9
+ #endif
6
10
 
7
11
  #include <libpcapng/protocols/udp.h>
8
12
  #include <libpcapng/protocols/dhcp.h>
@@ -2,7 +2,11 @@
2
2
  #include <stdlib.h>
3
3
  #include <string.h>
4
4
  #include <stdint.h>
5
- #include <arpa/inet.h>
5
+ #ifdef _WIN32
6
+ # include <libpcapng/win_compat.h>
7
+ #else
8
+ # include <arpa/inet.h>
9
+ #endif
6
10
 
7
11
  #include <libpcapng/protocols/udp.h>
8
12
  #include <libpcapng/protocols/dns.h>
@@ -2,7 +2,11 @@
2
2
  #include <stdlib.h>
3
3
  #include <string.h>
4
4
  #include <stdint.h>
5
- #include <arpa/inet.h>
5
+ #ifdef _WIN32
6
+ # include <libpcapng/win_compat.h>
7
+ #else
8
+ # include <arpa/inet.h>
9
+ #endif
6
10
 
7
11
  #include <libpcapng/protocols/ethernet.h>
8
12
  #include <libpcapng/protocols/ipv4.h>
@@ -2,7 +2,11 @@
2
2
  #include <stdlib.h>
3
3
  #include <string.h>
4
4
  #include <stdint.h>
5
- #include <arpa/inet.h>
5
+ #ifdef _WIN32
6
+ # include <libpcapng/win_compat.h>
7
+ #else
8
+ # include <arpa/inet.h>
9
+ #endif
6
10
 
7
11
  #include <libpcapng/protocols/ipv4.h>
8
12
 
@@ -1,5 +1,9 @@
1
1
  #include <string.h>
2
- #include <arpa/inet.h>
2
+ #ifdef _WIN32
3
+ # include <libpcapng/win_compat.h>
4
+ #else
5
+ # include <arpa/inet.h>
6
+ #endif
3
7
  #include <time.h>
4
8
 
5
9
  #include <libpcapng/protocols/udp.h>
@@ -2,7 +2,11 @@
2
2
  #include <stdlib.h>
3
3
  #include <string.h>
4
4
  #include <stdint.h>
5
- #include <arpa/inet.h>
5
+ #ifdef _WIN32
6
+ # include <libpcapng/win_compat.h>
7
+ #else
8
+ # include <arpa/inet.h>
9
+ #endif
6
10
 
7
11
  #include <libpcapng/easyapi.h>
8
12
  #include <libpcapng/protocols/asn1.h>
@@ -1,7 +1,11 @@
1
1
  #include <stdio.h>
2
2
  #include <string.h>
3
3
  #include <stdint.h>
4
- #include <arpa/inet.h>
4
+ #ifdef _WIN32
5
+ # include <libpcapng/win_compat.h>
6
+ #else
7
+ # include <arpa/inet.h>
8
+ #endif
5
9
 
6
10
  #include <libpcapng/protocols/ssl.h>
7
11
 
@@ -2,7 +2,11 @@
2
2
  #include <stdlib.h>
3
3
  #include <string.h>
4
4
  #include <stdint.h>
5
- #include <arpa/inet.h>
5
+ #ifdef _WIN32
6
+ # include <libpcapng/win_compat.h>
7
+ #else
8
+ # include <arpa/inet.h>
9
+ #endif
6
10
 
7
11
  #include <libpcapng/protocols/ethernet.h>
8
12
  #include <libpcapng/protocols/tcp.h>
@@ -2,7 +2,11 @@
2
2
  #include <stdlib.h>
3
3
  #include <string.h>
4
4
  #include <stdint.h>
5
- #include <arpa/inet.h>
5
+ #ifdef _WIN32
6
+ # include <libpcapng/win_compat.h>
7
+ #else
8
+ # include <arpa/inet.h>
9
+ #endif
6
10
 
7
11
  #include <libpcapng/protocols/ethernet.h>
8
12
  #include <libpcapng/protocols/udp.h>
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes