Skip to content

Commit 605c469

Browse files
committed
add ipv6 test
1 parent 7431721 commit 605c469

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

ext/sockets/tests/socket_afpacket_error.phpt

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,53 @@ if (PHP_INT_SIZE != 8) {
112112
socket_close($s_s);
113113
socket_close($s_c);
114114

115+
$s_c = socket_create(AF_PACKET, SOCK_RAW, ETH_P_IPV6);
116+
$s_bind = socket_bind($s_c, 'lo');
117+
$s_s = socket_create(AF_PACKET, SOCK_RAW, ETH_P_IPV6);
118+
$v_bind = socket_bind($s_s, 'lo');
119+
120+
$ethhdr = pack("H12H12n", "ffffffffffff", "000000000000", ETH_P_IPV6);
121+
122+
$ipv6_first_4 = hex2bin("60000000");
123+
124+
$ipv6_payload_len = hex2bin("0014");
125+
126+
$ipv6_nexthdr = chr(6);
127+
128+
$ipv6_hop_limit = chr(64);
129+
130+
$src_ip = hex2bin("00000000000000000000000000000001");
131+
132+
$dst_ip = hex2bin("00000000000000000000000000000001");
133+
$udp_hdr = pack('nZnnAhCn', 1024, 1025, "TEST", 4, 0, "ABCD", 128, "5");
134+
135+
$buf = $ethhdr
136+
. $ipv6_first_4
137+
. $ipv6_payload_len
138+
. $ipv6_nexthdr
139+
. $ipv6_hop_limit
140+
. $src_ip
141+
. $dst_ip
142+
. $udp_hdr;
143+
144+
$buf .= str_repeat("\x00", max(0, 60 - strlen($buf)));
145+
146+
var_dump(socket_sendto($s_s, $buf, strlen($buf), 0, "lo", 1));
147+
var_dump(socket_recvfrom($s_c, $rsp, strlen($buf), 0, $addr));
148+
149+
var_dump($rsp->ethProtocol == ETH_P_IPV6);
150+
var_dump(filter_var($rsp->payload->srcAddr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== null);
151+
152+
115153
?>
116-
--EXPECT--
154+
--EXPECTF--
117155
int(1084)
118156
unsupported ethernet protocol
119157
int(60)
120158
invalid transport header length
121159
socket_sendto(): Argument #3 ($length) must be at least 64 for AF_PACKET
122160
invalid ethernet loop header
161+
int(%d)
162+
int(%d)
163+
bool(true)
164+
bool(true)

0 commit comments

Comments
 (0)