Skip to content

Commit 66bfd40

Browse files
committed
more 32 bits tests
1 parent fe47472 commit 66bfd40

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

ext/sockets/tests/socket_afpacket32.phpt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,65 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32-bit only");
5858

5959
socket_close($s_s);
6060
socket_close($s_c);
61+
62+
$s_c = socket_create(AF_PACKET, SOCK_RAW, ETH_P_IP);
63+
$s_bind = socket_bind($s_c, 'lo');
64+
65+
$s_s = socket_create(AF_PACKET, SOCK_RAW, ETH_P_IP);
66+
$v_bind = socket_bind($s_s, 'lo');
67+
68+
$ip = hex2bin(
69+
"4500" .
70+
str_repeat("0028", 16) .
71+
"0000" .
72+
"4000" .
73+
"4006" .
74+
"0000" .
75+
"7f000001" .
76+
"7f000001"
77+
);
78+
$p = str_repeat("A", 20);
79+
80+
$buf = pack("H12H12n", "ffffffffffff", "000000000000", ETH_P_IP);
81+
$buf .= $ip . $p;
82+
83+
$min_frame_size = 60;
84+
$buf .= str_repeat("\x00", max(0, $min_frame_size - strlen($buf)));
85+
86+
var_dump(socket_sendto($s_s, $buf, strlen($buf), 0, "lo", 1));
87+
88+
try {
89+
socket_recvfrom($s_c, $rsp, strlen($buf), 0, $addr);
90+
} catch (\ValueError $e) {
91+
echo $e->getMessage(), PHP_EOL;
92+
}
93+
94+
$ip = hex2bin(
95+
"9999" .
96+
"0028" .
97+
"0000" .
98+
"4000" .
99+
"4006" .
100+
"0000" .
101+
"FFFFFeFF" .
102+
"7f000001"
103+
);
104+
$p = str_repeat("Bb", 80);
105+
106+
$buf = pack("H12H12n", "ffffffffffffh", "aaaaaAAAAAAA", ETH_P_IP);
107+
$buf .= $ip . $p;
108+
109+
$min_frame_size = 60;
110+
$buf .= str_repeat("\x00", max(0, $min_frame_size - strlen($buf)));
111+
112+
var_dump(socket_sendto($s_s, $buf, strlen($buf), 0, "lo", 1));
113+
var_dump(socket_recvfrom($s_c, $rsp, strlen($buf), 0, $addr));
114+
115+
var_dump($addr);
116+
var_dump($rsp);
117+
118+
socket_close($s_s);
119+
socket_close($s_c);
61120
?>
62121
--EXPECTF--
63122
bool(true)

0 commit comments

Comments
 (0)