|
2 | 2 |
|
3 | 3 | Stream driven PHP packet capture extension.
|
4 | 4 |
|
5 |
| -[](https://travis-ci.com/rtckit/php-pcap-ext)   |
| 5 | +[](https://travis-ci.com/rtckit/php-pcap-ext)   |
6 | 6 |
|
7 | 7 | ## Usage
|
8 | 8 |
|
9 |
| -The `pcap` extension has been developed against PHP 7.4+ and regularly tested against the upcoming PHP 8. |
| 9 | +The `pcap` extension has been developed against PHP 7.4+ and regularly tested against the nightly PHP 8 build; from an operating system perspective, the ubiquity of Linux makes it the only target. The supported architectures are x86_64 and arm64. |
10 | 10 |
|
11 |
| -The extension provides bindings for [libpcap](https://github.com/the-tcpdump-group/libpcap) and exposes its functionality via PHP streams; the packet formatting is consistent with the `pcap` file format (learn more [here](https://wiki.wireshark.org/Development/LibpcapFileFormat) and [here](https://formats.kaitai.io/pcap/index.html)). The functionality is deliberately limited to I/O operations, the actual packet parsing/crafting should be performed using pure PHP; such supporting libraries will be open sourced soon. |
| 11 | +The extension provides bindings for [libpcap](https://github.com/the-tcpdump-group/libpcap) and exposes its functionality via PHP streams; the packet formatting is consistent with the `pcap` file format (learn more [here](https://wiki.wireshark.org/Development/LibpcapFileFormat) and [here](https://formats.kaitai.io/pcap/index.html)). The functionality is deliberately limited to I/O operations, the actual packet parsing/crafting should be performed using pure PHP (some relevant supporting libraries to be published soon). |
12 | 12 |
|
13 | 13 | It's also worth familiarizing yourself with [libpcap and tcpdump](https://www.tcpdump.org/index.html).
|
14 | 14 |
|
@@ -60,6 +60,9 @@ array(4) {
|
60 | 60 | */
|
61 | 61 |
|
62 | 62 | // process($frame) ...
|
| 63 | + |
| 64 | +// Inject raw packets (including the link layer data) by writing to the stream |
| 65 | +$count = fwrite($fp, $packet); |
63 | 66 | ```
|
64 | 67 |
|
65 | 68 | The [tests](https://github.com/rtckit/php-pcap-ext/tree/master/tests) directory show cases some usage examples.
|
|
76 | 79 |
|
77 | 80 | ## Tests
|
78 | 81 |
|
79 |
| -Before running the test suite, make sure the user has the ability to capture network packets (root or CAP_RAW). |
| 82 | +Before running the test suite, make sure the user has the ability to capture network packets (root or `CAP_NET_RAW`). |
80 | 83 |
|
81 | 84 | ```sh
|
82 | 85 | make test
|
83 | 86 | ```
|
84 | 87 |
|
| 88 | +## FFI Alternative |
| 89 | + |
| 90 | +A fully compilable [FFI packet capture](https://github.com/rtckit/php-pcap-ffi) package is also available; the underlying environment would still have the provide the libpcap library as well as the FFI dependencies (libffi and the PHP FFI extension). Otherwise, the FFI package can be used as a drop-in replacement when it makes sense to do so. |
| 91 | + |
85 | 92 | ## License
|
86 | 93 |
|
87 | 94 | MIT, see [LICENSE file](LICENSE).
|
88 | 95 |
|
89 | 96 | ### Acknowledgments
|
90 | 97 |
|
91 |
| -* [libpcap](https://github.com/the-tcpdump-group/libpcap) |
| 98 | +* [libpcap](https://github.com/the-tcpdump-group/libpcap) by The Tcpdump Group, BSD licensed. |
92 | 99 |
|
93 | 100 | ### Contributing
|
94 | 101 |
|
|
0 commit comments