Skip to content

Commit 1f1f204

Browse files
committed
re-establish lost test data and testing unsupported proto.
1 parent aea56f5 commit 1f1f204

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

ext/sockets/tests/socket_afpacket.phpt

+51-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (!function_exists("posix_getuid") || posix_getuid() != 0) {
1515
?>
1616
--FILE--
1717
<?php
18-
$s_c = socket_create(AF_PACKET, SOCK_RAW, ETH_P_IP);
18+
$s_c = socket_create(AF_PACKET, SOCK_RAW, ETH_P_ALL);
1919
$s_bind = socket_bind($s_c, 'lo');
2020
var_dump($s_bind);
2121

@@ -26,6 +26,34 @@ if (!function_exists("posix_getuid") || posix_getuid() != 0) {
2626
var_dump($iindex);
2727

2828
socket_getpeername($s_c, $istr2, $iindex2);
29+
30+
$s_s = socket_create(AF_PACKET, SOCK_RAW, ETH_P_LOOP);
31+
$v_bind = socket_bind($s_s, 'lo');
32+
33+
$buf = pack("H12H12n", "ffffffffffff", "000000000000", ETH_P_LOOP);
34+
$buf .= str_repeat("A", 46);
35+
36+
var_dump(socket_sendto($s_s, $buf, strlen($buf), 0, "lo", 1));
37+
var_dump(socket_recvfrom($s_c, $rsp, strlen($buf), 0, $addr));
38+
39+
var_dump($addr);
40+
var_dump($rsp);
41+
42+
socket_close($s_c);
43+
// purposely unsupported ethernet protocol (ARP)
44+
$s_c = socket_create(AF_PACKET, SOCK_RAW, 0x0806);
45+
$s_bind = socket_bind($s_c, 'lo');
46+
$buf = pack("H12H12n", "ffffffffffff", "000000000000", 0x0806);
47+
$buf .= str_repeat("A", 46);
48+
49+
var_dump(socket_sendto($s_s, $buf, strlen($buf), 0, "lo", 1));
50+
51+
try {
52+
socket_recvfrom($s_c, $rsp2, strlen($buf), 0, $addr2);
53+
} catch (\ValueError $e) {
54+
echo $e->getMessage();
55+
}
56+
2957
socket_close($s_c);
3058
?>
3159
--EXPECTF--
@@ -35,3 +63,25 @@ string(2) "lo"
3563
int(%i)
3664

3765
Warning: socket_getpeername(): unable to retrieve peer name [95]: %sot supported in %s on line %d
66+
int(60)
67+
int(60)
68+
string(2) "lo"
69+
object(SocketEthernetInfo)#3 (%d) {
70+
["socket"]=>
71+
object(Socket)#1 (0) {
72+
}
73+
["ethprotocol"]=>
74+
int(%i)
75+
["macsrc"]=>
76+
string(%d) "%s:%s:%s:%s:%s:%s"
77+
["macdst"]=>
78+
string(%d) "%s:%s:%s:%s:%s:%s"
79+
["rawpayload"]=>
80+
string(%d) "%A"
81+
["payload"]=>
82+
object(stdClass)#4 (%d) {
83+
%a
84+
}
85+
}
86+
int(60)
87+
unsupported ethernet protocol

0 commit comments

Comments
 (0)