Skip to content

Commit 76e40d1

Browse files
committed
additional tests
1 parent 5f50035 commit 76e40d1

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

ext/sockets/sockets.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,8 @@
20212021
* @cvalue ETH_P_ALL
20222022
*/
20232023
const ETH_P_ALL = UNKNOWN;
2024+
#endif
2025+
#if defined(ETH_FRAME_LEN)
20242026
/**
20252027
* @var int
20262028
* @cvalue ETH_FRAME_LEN

ext/sockets/sockets_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/sockets/tests/socket_afpacket_error.phpt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,69 @@ if (PHP_INT_SIZE != 8) {
201201
echo $e->getMessage(), PHP_EOL;
202202
}
203203

204+
socket_close($s_s);
205+
socket_close($s_c);
206+
207+
$s_c = socket_create(AF_PACKET, SOCK_RAW, ETH_P_LOOP);
208+
$s_bind = socket_bind($s_c, 'lo');
209+
210+
$s_s = socket_create(AF_PACKET, SOCK_RAW, ETH_P_LOOP);
211+
$v_bind = socket_bind($s_s, 'lo');
212+
213+
$payload = hex2bin(
214+
"f500" .
215+
"0000" .
216+
"0000" .
217+
"0000" .
218+
"4006" .
219+
"0000" .
220+
"acde" .
221+
"7a000000"
222+
) . str_repeat("p", 1);
223+
224+
$buf = pack("H12H12n", "ffffffffffff", "000000000000", ETH_P_LOOP);
225+
$buf .= $payload;
226+
227+
try {
228+
socket_sendto($s_s, $buf, strlen($buf), 0, "lo", 1);
229+
} catch(\ValueError $e) {
230+
echo $e->getMessage(), PHP_EOL;
231+
}
232+
233+
socket_close($s_s);
234+
socket_close($s_c);
235+
236+
$s_c = socket_create(AF_PACKET, SOCK_RAW, ETH_P_ALL);
237+
$s_bind = socket_bind($s_c, 'lo');
238+
239+
$s_s = socket_create(AF_PACKET, SOCK_RAW, ETH_P_ALL);
240+
$v_bind = socket_bind($s_s, 'lo');
241+
242+
$payload = hex2bin(
243+
"AF00" .
244+
"0028" .
245+
"0000" .
246+
"4000" .
247+
"4006" .
248+
"0000" .
249+
"7f000001" .
250+
"7f000001"
251+
) . str_repeat("A", 1024);
252+
253+
$buf = pack("H12H12n", "ffffffffffff", "000000000000", ETH_P_LOOP);
254+
$buf .= $payload;
255+
256+
var_dump(socket_sendto($s_s, $buf, strlen($buf), 0, "lo", 1));
257+
258+
try {
259+
socket_recvfrom($s_c, $rsp, strlen($buf), 0, $addr);
260+
} catch (\ValueError $e) {
261+
echo $e->getMessage(), PHP_EOL;
262+
}
204263

205264
socket_close($s_s);
206265
socket_close($s_c);
266+
207267
?>
208268
--EXPECTF--
209269
int(%d)
@@ -221,3 +281,6 @@ bool(true)
221281
bool(true)
222282
int(%d)
223283
invalid ethernet loop header
284+
socket_sendto(): Argument #3 ($length) must be at least 60 for AF_PACKET
285+
int(%d)
286+
invalid ethernet loop header

0 commit comments

Comments
 (0)