Skip to content

Commit 6a8bff1

Browse files
committed
additional tests
1 parent 4218191 commit 6a8bff1

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

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)