Skip to content

Commit ba7350a

Browse files
committed
0.6.0-rc
1 parent 74a28d9 commit ba7350a

File tree

17 files changed

+1304
-2
lines changed

17 files changed

+1304
-2
lines changed

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
language: php
2+
3+
addons:
4+
apt:
5+
packages:
6+
- libpcap-dev
7+
8+
php:
9+
- 7.4
10+
- 8.0
11+
12+
env:
13+
- REPORT_EXIT_STATUS=1 NO_INTERACTION=1
14+
15+
# Compile
16+
before_script:
17+
- phpize && ./configure && make
18+
19+
# Run PHPs run-tests.php
20+
script: TEST_PHP_ARGS="-q --show-out" make test

CREDITS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pcap
2+
Ciprian Dosoftei

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM php:7.4-cli-alpine
2+
3+
RUN apk add $PHPIZE_DEPS && \
4+
cd /usr/src && \
5+
tar -xf php.tar.xz && \
6+
cd php-* && \
7+
apk add libpcap libpcap-dev
8+
9+
COPY . /usr/src/php-pcap-ext
10+
11+
WORKDIR /usr/src/php-pcap-ext
12+
13+
RUN phpize && \
14+
./configure && \
15+
make && \
16+
(TEST_PHP_ARGS="-q --show-out" make test || exit 0) && \
17+
make install && \
18+
echo "extension=pcap.so" > /usr/local/etc/php/conf.d/pcap.ini
19+
20+
CMD ["php", "-i"]

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is intended solely to facilitate development specific processes
2+
REPOSITORY=rtckit/php-pcap-ext-dev
3+
4+
image:
5+
docker build -t ${REPOSITORY} .
6+
7+
local-image:
8+
docker build -v `pwd`:/usr/src/php-pcap-ext:rw -t ${REPOSITORY} .
9+
10+
run: image
11+
docker run --rm -t ${REPOSITORY}

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,43 @@
1-
# php-pcap-ext
2-
PHP packet capture extension
1+
# PHP Packet Capture
2+
3+
Stream driven PHP packet capture extension.
4+
5+
[![Build Status](https://travis-ci.org/rtckit/php-pcap-ext.svg?branch=master)](https://travis-ci.org/rtckit/php-pcap-ext) ![Version](https://img.shields.io/badge/version-v0.6.0-green) ![License](https://img.shields.io/badge/license-MIT-blue)
6+
7+
## Usage
8+
9+
The `pcap` extension has been developed against PHP 7.4+ and regularly tested against the upcoming PHP 8.
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)).
12+
13+
It's also worth familiarizing yourself with [libpcap and tcpdump](https://www.tcpdump.org/index.html).
14+
15+
## Build
16+
17+
In order to build the extension from source, make sure the environment supports the typical C/C++ build essentials for your platform (`build-essential`), the PHP development files (`php-dev`) as well as the libpcap library and its respective development files (`libpcap-dev`).
18+
19+
```sh
20+
phpize
21+
./configure
22+
make
23+
```
24+
25+
## Tests
26+
27+
Before running the test suite, make sure the user has the ability to capture network packets (root or CAP_RAW).
28+
29+
```sh
30+
make test
31+
```
32+
33+
## License
34+
35+
MIT, see [LICENSE file](LICENSE).
36+
37+
### Acknowledgments
38+
39+
* [libpcap](https://github.com/the-tcpdump-group/libpcap)
40+
41+
### Contributing
42+
43+
Bug reports (and small patches) can be submitted via the [issue tracker](https://github.com/rtckit/php-pcap-ext/issues). Forking the repository and submitting a Pull Request is preferred for substantial patches.

config.m4

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
PHP_ARG_ENABLE([pcap],
2+
[whether to enable pcap support],
3+
[AS_HELP_STRING([--enable-pcap],
4+
[Enable pcap support])],
5+
[no])
6+
7+
if test "$PHP_PCAP" != "no"; then
8+
PHP_NEW_EXTENSION(pcap, pcap.c, $ext_shared)
9+
10+
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
11+
12+
AC_MSG_CHECKING(for libpcap)
13+
14+
if test $PHP_PCAP == "yes" && test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libpcap; then
15+
if $PKG_CONFIG libpcap --atleast-version 1.8.0; then
16+
LIBPCAP_INCLINE=`$PKG_CONFIG libpcap --cflags`
17+
LIBPCAP_LIBLINE=`$PKG_CONFIG libpcap --libs`
18+
LIBPCAP_VERSION=`$PKG_CONFIG libpcap --modversion`
19+
AC_MSG_RESULT(from pkgconfig: found version $LIBPCAP_VERSION)
20+
AC_DEFINE(HAVE_PCAPLIB,1,[ ])
21+
else
22+
AC_MSG_ERROR(system libpcap must be upgraded to version >= 1.8.0)
23+
fi
24+
PHP_EVAL_LIBLINE($LIBPCAP_LIBLINE, PCAP_SHARED_LIBADD)
25+
PHP_EVAL_INCLINE($LIBPCAP_INCLINE)
26+
27+
else
28+
SEARCH_PATH="/usr/local /usr"
29+
SEARCH_FOR="/include/pcap.h"
30+
if test -r $PHP_PCAP/$SEARCH_FOR; then # path given as parameter
31+
PCAP_DIR=$PHP_PCAP
32+
AC_MSG_RESULT(from option: found in $PCAP_DIR)
33+
else # search default path list
34+
for i in $SEARCH_PATH ; do
35+
if test -r $i/$SEARCH_FOR; then
36+
PCAP_DIR=$i
37+
AC_MSG_RESULT(from default path: found in $i)
38+
fi
39+
done
40+
fi
41+
PHP_ADD_INCLUDE($PCAP_DIR/include)
42+
PHP_CHECK_LIBRARY(pcap, pcap_version,
43+
[
44+
PHP_ADD_LIBRARY_WITH_PATH(pcap, $PCAP_DIR/$PHP_LIBDIR, PCAP_SHARED_LIBADD)
45+
AC_DEFINE(HAVE_PCAPLIB,1,[ ])
46+
],[
47+
AC_MSG_ERROR([wrong pcap library version or library not found])
48+
],[
49+
-L$PCAP_DIR/$PHP_LIBDIR -lm
50+
])
51+
fi
52+
53+
PHP_SUBST([CFLAGS])
54+
PHP_SUBST(PCAP_SHARED_LIBADD)
55+
fi

0 commit comments

Comments
 (0)