Skip to content

Commit 03afbe2

Browse files
authored
v0.6.2 (#1)
Release
1 parent db5bf7c commit 03afbe2

23 files changed

+2209
-3
lines changed

.editorconfig

+240
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
[*]
2+
charset = utf-8
3+
end_of_line = lf
4+
indent_size = 4
5+
indent_style = space
6+
insert_final_newline = true
7+
max_line_length = 120
8+
tab_width = 4
9+
trim_trailing_whitespace = true
10+
ij_continuation_indent_size = 8
11+
ij_formatter_off_tag = @formatter:off
12+
ij_formatter_on_tag = @formatter:on
13+
ij_formatter_tags_enabled = false
14+
ij_smart_tabs = false
15+
ij_wrap_on_typing = false
16+
17+
[{*.ctp,*.hphp,*.inc,*.module,*.php,*.php4,*.php5,*.phtml}]
18+
ij_continuation_indent_size = 4
19+
ij_php_align_assignments = false
20+
ij_php_align_class_constants = false
21+
ij_php_align_group_field_declarations = false
22+
ij_php_align_inline_comments = false
23+
ij_php_align_key_value_pairs = false
24+
ij_php_align_multiline_array_initializer_expression = false
25+
ij_php_align_multiline_binary_operation = false
26+
ij_php_align_multiline_chained_methods = false
27+
ij_php_align_multiline_extends_list = false
28+
ij_php_align_multiline_for = true
29+
ij_php_align_multiline_parameters = true
30+
ij_php_align_multiline_parameters_in_calls = false
31+
ij_php_align_multiline_ternary_operation = false
32+
ij_php_align_phpdoc_comments = false
33+
ij_php_align_phpdoc_param_names = false
34+
ij_php_anonymous_brace_style = end_of_line
35+
ij_php_api_weight = 28
36+
ij_php_array_initializer_new_line_after_left_brace = false
37+
ij_php_array_initializer_right_brace_on_new_line = false
38+
ij_php_array_initializer_wrap = off
39+
ij_php_assignment_wrap = off
40+
ij_php_author_weight = 28
41+
ij_php_binary_operation_sign_on_next_line = false
42+
ij_php_binary_operation_wrap = off
43+
ij_php_blank_lines_after_class_header = 0
44+
ij_php_blank_lines_after_function = 1
45+
ij_php_blank_lines_after_imports = 1
46+
ij_php_blank_lines_after_opening_tag = 0
47+
ij_php_blank_lines_after_package = 0
48+
ij_php_blank_lines_around_class = 1
49+
ij_php_blank_lines_around_constants = 0
50+
ij_php_blank_lines_around_field = 0
51+
ij_php_blank_lines_around_method = 1
52+
ij_php_blank_lines_before_class_end = 0
53+
ij_php_blank_lines_before_imports = 1
54+
ij_php_blank_lines_before_method_body = 0
55+
ij_php_blank_lines_before_package = 1
56+
ij_php_blank_lines_before_return_statement = 0
57+
ij_php_blank_lines_between_imports = 0
58+
ij_php_block_brace_style = end_of_line
59+
ij_php_call_parameters_new_line_after_left_paren = false
60+
ij_php_call_parameters_right_paren_on_new_line = false
61+
ij_php_call_parameters_wrap = off
62+
ij_php_catch_on_new_line = false
63+
ij_php_category_weight = 28
64+
ij_php_class_brace_style = next_line
65+
ij_php_comma_after_last_array_element = false
66+
ij_php_concat_spaces = true
67+
ij_php_copyright_weight = 28
68+
ij_php_deprecated_weight = 28
69+
ij_php_do_while_brace_force = never
70+
ij_php_else_if_style = as_is
71+
ij_php_else_on_new_line = false
72+
ij_php_example_weight = 28
73+
ij_php_extends_keyword_wrap = off
74+
ij_php_extends_list_wrap = off
75+
ij_php_fields_default_visibility = private
76+
ij_php_filesource_weight = 28
77+
ij_php_finally_on_new_line = false
78+
ij_php_for_brace_force = never
79+
ij_php_for_statement_new_line_after_left_paren = false
80+
ij_php_for_statement_right_paren_on_new_line = false
81+
ij_php_for_statement_wrap = off
82+
ij_php_force_short_declaration_array_style = false
83+
ij_php_global_weight = 28
84+
ij_php_group_use_wrap = on_every_item
85+
ij_php_if_brace_force = never
86+
ij_php_if_lparen_on_next_line = false
87+
ij_php_if_rparen_on_next_line = false
88+
ij_php_ignore_weight = 28
89+
ij_php_import_sorting = alphabetic
90+
ij_php_indent_break_from_case = true
91+
ij_php_indent_case_from_switch = true
92+
ij_php_indent_code_in_php_tags = false
93+
ij_php_internal_weight = 28
94+
ij_php_keep_blank_lines_after_lbrace = 2
95+
ij_php_keep_blank_lines_before_right_brace = 2
96+
ij_php_keep_blank_lines_in_code = 2
97+
ij_php_keep_blank_lines_in_declarations = 2
98+
ij_php_keep_control_statement_in_one_line = true
99+
ij_php_keep_first_column_comment = true
100+
ij_php_keep_indents_on_empty_lines = false
101+
ij_php_keep_line_breaks = true
102+
ij_php_keep_rparen_and_lbrace_on_one_line = false
103+
ij_php_keep_simple_methods_in_one_line = false
104+
ij_php_lambda_brace_style = end_of_line
105+
ij_php_license_weight = 28
106+
ij_php_line_comment_add_space = false
107+
ij_php_line_comment_at_first_column = true
108+
ij_php_link_weight = 28
109+
ij_php_lower_case_boolean_const = false
110+
ij_php_lower_case_keywords = true
111+
ij_php_lower_case_null_const = false
112+
ij_php_method_brace_style = next_line
113+
ij_php_method_call_chain_wrap = off
114+
ij_php_method_parameters_new_line_after_left_paren = false
115+
ij_php_method_parameters_right_paren_on_new_line = false
116+
ij_php_method_parameters_wrap = off
117+
ij_php_method_weight = 28
118+
ij_php_modifier_list_wrap = false
119+
ij_php_multiline_chained_calls_semicolon_on_new_line = false
120+
ij_php_namespace_brace_style = 1
121+
ij_php_new_line_after_php_opening_tag = false
122+
ij_php_null_type_position = in_the_end
123+
ij_php_package_weight = 28
124+
ij_php_param_weight = 0
125+
ij_php_parentheses_expression_new_line_after_left_paren = false
126+
ij_php_parentheses_expression_right_paren_on_new_line = false
127+
ij_php_phpdoc_blank_line_before_tags = false
128+
ij_php_phpdoc_blank_lines_around_parameters = false
129+
ij_php_phpdoc_keep_blank_lines = true
130+
ij_php_phpdoc_param_spaces_between_name_and_description = 1
131+
ij_php_phpdoc_param_spaces_between_tag_and_type = 1
132+
ij_php_phpdoc_param_spaces_between_type_and_name = 1
133+
ij_php_phpdoc_use_fqcn = false
134+
ij_php_phpdoc_wrap_long_lines = false
135+
ij_php_place_assignment_sign_on_next_line = false
136+
ij_php_place_parens_for_constructor = 0
137+
ij_php_property_read_weight = 28
138+
ij_php_property_weight = 28
139+
ij_php_property_write_weight = 28
140+
ij_php_return_type_on_new_line = false
141+
ij_php_return_weight = 1
142+
ij_php_see_weight = 28
143+
ij_php_since_weight = 28
144+
ij_php_sort_phpdoc_elements = true
145+
ij_php_space_after_colon = true
146+
ij_php_space_after_colon_in_return_type = true
147+
ij_php_space_after_comma = true
148+
ij_php_space_after_for_semicolon = true
149+
ij_php_space_after_quest = true
150+
ij_php_space_after_type_cast = false
151+
ij_php_space_after_unary_not = false
152+
ij_php_space_before_array_initializer_left_brace = false
153+
ij_php_space_before_catch_keyword = true
154+
ij_php_space_before_catch_left_brace = true
155+
ij_php_space_before_catch_parentheses = true
156+
ij_php_space_before_class_left_brace = true
157+
ij_php_space_before_closure_left_parenthesis = true
158+
ij_php_space_before_colon = true
159+
ij_php_space_before_colon_in_return_type = false
160+
ij_php_space_before_comma = false
161+
ij_php_space_before_do_left_brace = true
162+
ij_php_space_before_else_keyword = true
163+
ij_php_space_before_else_left_brace = true
164+
ij_php_space_before_finally_keyword = true
165+
ij_php_space_before_finally_left_brace = true
166+
ij_php_space_before_for_left_brace = true
167+
ij_php_space_before_for_parentheses = true
168+
ij_php_space_before_for_semicolon = false
169+
ij_php_space_before_if_left_brace = true
170+
ij_php_space_before_if_parentheses = true
171+
ij_php_space_before_method_call_parentheses = false
172+
ij_php_space_before_method_left_brace = true
173+
ij_php_space_before_method_parentheses = false
174+
ij_php_space_before_quest = true
175+
ij_php_space_before_short_closure_left_parenthesis = false
176+
ij_php_space_before_switch_left_brace = true
177+
ij_php_space_before_switch_parentheses = true
178+
ij_php_space_before_try_left_brace = true
179+
ij_php_space_before_unary_not = false
180+
ij_php_space_before_while_keyword = true
181+
ij_php_space_before_while_left_brace = true
182+
ij_php_space_before_while_parentheses = true
183+
ij_php_space_between_ternary_quest_and_colon = false
184+
ij_php_spaces_around_additive_operators = true
185+
ij_php_spaces_around_arrow = false
186+
ij_php_spaces_around_assignment_in_declare = false
187+
ij_php_spaces_around_assignment_operators = true
188+
ij_php_spaces_around_bitwise_operators = true
189+
ij_php_spaces_around_equality_operators = true
190+
ij_php_spaces_around_logical_operators = true
191+
ij_php_spaces_around_multiplicative_operators = true
192+
ij_php_spaces_around_null_coalesce_operator = true
193+
ij_php_spaces_around_relational_operators = true
194+
ij_php_spaces_around_shift_operators = true
195+
ij_php_spaces_around_unary_operator = false
196+
ij_php_spaces_around_var_within_brackets = false
197+
ij_php_spaces_within_array_initializer_braces = false
198+
ij_php_spaces_within_brackets = false
199+
ij_php_spaces_within_catch_parentheses = false
200+
ij_php_spaces_within_for_parentheses = false
201+
ij_php_spaces_within_if_parentheses = false
202+
ij_php_spaces_within_method_call_parentheses = false
203+
ij_php_spaces_within_method_parentheses = false
204+
ij_php_spaces_within_parentheses = false
205+
ij_php_spaces_within_short_echo_tags = true
206+
ij_php_spaces_within_switch_parentheses = false
207+
ij_php_spaces_within_while_parentheses = false
208+
ij_php_special_else_if_treatment = false
209+
ij_php_subpackage_weight = 28
210+
ij_php_ternary_operation_signs_on_next_line = false
211+
ij_php_ternary_operation_wrap = off
212+
ij_php_throws_weight = 2
213+
ij_php_todo_weight = 28
214+
ij_php_unknown_tag_weight = 28
215+
ij_php_upper_case_boolean_const = false
216+
ij_php_upper_case_null_const = false
217+
ij_php_uses_weight = 28
218+
ij_php_var_weight = 28
219+
ij_php_variable_naming_style = mixed
220+
ij_php_version_weight = 28
221+
ij_php_while_brace_force = never
222+
ij_php_while_on_new_line = false
223+
224+
[{*.har,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.stylelintrc,bowerrc,composer.lock,jest.config}]
225+
indent_size = 2
226+
ij_json_keep_blank_lines_in_code = 0
227+
ij_json_keep_indents_on_empty_lines = false
228+
ij_json_keep_line_breaks = true
229+
ij_json_space_after_colon = true
230+
ij_json_space_after_comma = true
231+
ij_json_space_before_colon = true
232+
ij_json_space_before_comma = false
233+
ij_json_spaces_within_braces = false
234+
ij_json_spaces_within_brackets = false
235+
ij_json_wrap_long_lines = false
236+
237+
[{*.yaml,*.yml}]
238+
indent_size = 2
239+
ij_yaml_keep_indents_on_empty_lines = false
240+
ij_yaml_keep_line_breaks = true

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.phpunit.result.cache
2+
reports
3+
vendor
4+
composer.lock

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Configuration
2+
os: linux
3+
4+
script: make ci

Dockerfile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM composer:1.10.10 as composer
2+
3+
WORKDIR /usr/src/php-pcap-ffi
4+
5+
COPY composer.* /usr/src/php-pcap-ffi/
6+
7+
RUN apk add libffi libffi-dev && \
8+
docker-php-ext-install ffi && \
9+
composer install --no-scripts --no-suggest --no-interaction --prefer-dist --optimize-autoloader
10+
11+
COPY . /usr/src/php-pcap-ffi
12+
13+
RUN composer dump-autoload --optimize --classmap-authoritative
14+
15+
FROM php:7.4-cli-alpine
16+
17+
RUN apk add bind-tools libffi libffi-dev libpcap && \
18+
docker-php-ext-install ffi sockets
19+
20+
WORKDIR /usr/src/php-pcap-ffi
21+
22+
COPY . /usr/src/php-pcap-ffi
23+
24+
COPY --from=composer /usr/src/php-pcap-ffi/vendor /usr/src/php-pcap-ffi/vendor
25+
26+
CMD ["php", "-i"]

Dockerfile.buster

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM composer:1.10.10 as composer
2+
3+
WORKDIR /usr/src/php-pcap-ffi
4+
5+
COPY composer.* /usr/src/php-pcap-ffi/
6+
7+
RUN apk add libffi libffi-dev && \
8+
docker-php-ext-install ffi && \
9+
composer install --no-scripts --no-suggest --no-interaction --prefer-dist --optimize-autoloader
10+
11+
COPY . /usr/src/php-pcap-ffi
12+
13+
RUN composer dump-autoload --optimize --classmap-authoritative
14+
15+
FROM php:7.4-cli-buster
16+
17+
RUN apt-get update && \
18+
apt-get install -y inetutils-ping dnsutils libffi-dev libpcap-dev && \
19+
docker-php-ext-install ffi sockets
20+
21+
WORKDIR /usr/src/php-pcap-ffi
22+
23+
COPY . /usr/src/php-pcap-ffi
24+
25+
COPY --from=composer /usr/src/php-pcap-ffi/vendor /usr/src/php-pcap-ffi/vendor
26+
27+
ENV LIBPCAP_NAME=libpcap.so.1.8.1
28+
29+
CMD ["php", "-i"]

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 rtckit
3+
Copyright (c) 2020 Ciprian Dosoftei
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This file is intended solely to facilitate development specific processes
2+
REPOSITORY=rtckit/php-pcap-ffi-dev
3+
RUN_CMD=docker run --name php-pcap-ffi-dev --rm -it -v `pwd`/reports:/usr/src/php-pcap-ffi/reports:rw ${REPOSITORY}
4+
RUN_PHP_CMD=${RUN_CMD} php -d memory_limit=-1
5+
6+
image:
7+
docker build -t ${REPOSITORY} .
8+
9+
test: image
10+
${RUN_PHP_CMD} -d memory_limit=-1 ./vendor/bin/phpunit --debug
11+
12+
cover: image
13+
rm -rf reports/coverage
14+
${RUN_PHP_CMD} ./vendor/bin/phpunit --coverage-text --coverage-html=reports/coverage
15+
16+
stan: image
17+
${RUN_PHP_CMD} ./vendor/bin/phpstan analyse -n -vvv --ansi --level=max src
18+
19+
psalm: image
20+
${RUN_PHP_CMD} ./vendor/bin/psalm --show-info=true
21+
22+
buster:
23+
docker build -t ${REPOSITORY}:buster -f Dockerfile.buster .
24+
25+
buster-test: buster
26+
${RUN_CMD}:buster php -d memory_limit=-1 -d memory_limit=-1 ./vendor/bin/phpunit --debug
27+
28+
ci: stan psalm test buster-test
29+
30+
clean:
31+
rm -rf `cat .gitignore`

README.md

+47-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,47 @@
1-
# php-pcap-ffi
2-
FFI libpcap bindings for PHP
1+
# PHP Packet Capture via FFI
2+
3+
Stream driven PHP packet capture library, leveraging libpcap via FFI.
4+
5+
[![Build Status](https://travis-ci.com/rtckit/php-pcap-ffi.svg?branch=master)](https://travis-ci.com/rtckit/php-pcap-ffi) ![Version](https://img.shields.io/badge/version-v0.6.2-green) ![License](https://img.shields.io/badge/license-MIT-blue)
6+
7+
## Pcap Extension
8+
9+
Whenever possible, you should use the native [pcap PHP extension](https://github.com/rtckit/php-pcap-ext), this library is provided as an alternative to it for select/edge cases. Otherwise, the FFI based packet capture library is fully compatible with the `pcap` extension. As a result, all changes applied to the extension are reflected here too, and the library version will always match its extension counterpart.
10+
11+
## Requirements
12+
13+
This library makes use of features introduced as of PHP 7.4, it will not work with obsolete versions. Of course, the [PHP FFI extension](https://www.php.net/manual/en/book.ffi.php) must be installed and enabled.
14+
15+
The libpcap library must be installed on the target environment; some Linux distributions meddle with the library naming protocols and this can confuse the FFI initialization process. Should that be the case, one can set the `LIBPCAP_NAME` environment variable to the actual library name, or even the absolute path to the library's .so file for custom builds or non-standard directory layouts.
16+
17+
For example, for Debian Buster, one would set `LIBPCAP_NAME` to `libpcap.so.1.8.1`.
18+
19+
## Install
20+
21+
The recommended way to install this library is [through Composer](https://getcomposer.org). [New to Composer?](https://getcomposer.org/doc/00-intro.md)
22+
23+
This will install the latest supported version:
24+
25+
```sh
26+
composer require rtckit/pcap-ffi:^0.6.2
27+
```
28+
29+
## Tests
30+
31+
Before running the test suite, make sure the user has the ability to capture network packets (root or `CAP_NET_RAW`).
32+
33+
```sh
34+
make test
35+
```
36+
37+
## License
38+
39+
MIT, see [LICENSE file](LICENSE).
40+
41+
### Acknowledgments
42+
43+
* [libpcap](https://github.com/the-tcpdump-group/libpcap) by The Tcpdump Group, BSD licensed.
44+
45+
### Contributing
46+
47+
Bug reports (and small patches) can be submitted via the [issue tracker](https://github.com/rtckit/php-pcap-ffi/issues). Forking the repository and submitting a Pull Request is preferred for substantial patches.

0 commit comments

Comments
 (0)