mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
69 lines
1.5 KiB
PHP
69 lines
1.5 KiB
PHP
--TEST--
|
|
socket_getsockname from AF_PACKET socket
|
|
--EXTENSIONS--
|
|
sockets
|
|
posix
|
|
--SKIPIF--
|
|
<?php
|
|
|
|
if (!defined("AF_PACKET")) {
|
|
die('SKIP AF_PACKET not supported on this platform.');
|
|
}
|
|
if (!function_exists("posix_getuid") || posix_getuid() != 0) {
|
|
die('SKIP AF_PACKET requires root permissions.');
|
|
}
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
$s_c = socket_create(AF_PACKET, SOCK_RAW, ETH_P_ALL);
|
|
$s_bind = socket_bind($s_c, 'lo');
|
|
var_dump($s_bind);
|
|
|
|
// sock_getsockname in this context gets the interface rather than the address.
|
|
$s_conn = socket_getsockname($s_c, $istr, $iindex);
|
|
var_dump($s_conn);
|
|
var_dump($istr);
|
|
var_dump($iindex);
|
|
|
|
socket_getpeername($s_c, $istr2, $iindex2);
|
|
|
|
$s_s = socket_create(AF_PACKET, SOCK_RAW, ETH_P_LOOP);
|
|
$v_bind = socket_bind($s_s, 'lo');
|
|
|
|
$buf = pack("H12H12n", "ffffffffffff", "000000000000", ETH_P_LOOP);
|
|
$buf .= str_repeat("A", 46);
|
|
|
|
var_dump(socket_sendto($s_s, $buf, strlen($buf), 0, "lo", 1));
|
|
var_dump(socket_recvfrom($s_c, $rsp, strlen($buf), 0, $addr));
|
|
|
|
var_dump($addr);
|
|
var_dump($rsp);
|
|
|
|
socket_close($s_c);
|
|
?>
|
|
--EXPECTF--
|
|
bool(true)
|
|
bool(true)
|
|
string(2) "lo"
|
|
int(%i)
|
|
|
|
Warning: socket_getpeername(): unable to retrieve peer name [95]: %sot supported in %s on line %d
|
|
int(60)
|
|
int(60)
|
|
string(2) "lo"
|
|
object(SocketEthernetInfo)#3 (%d) {
|
|
["socket"]=>
|
|
object(Socket)#1 (0) {
|
|
}
|
|
["ethprotocol"]=>
|
|
int(%i)
|
|
["macsrc"]=>
|
|
string(11) "0:0:0:0:0:0"
|
|
["macdst"]=>
|
|
string(%d) "%s:%s:%s:%s:%s:%s"
|
|
["payload"]=>
|
|
array(%d) {
|
|
%a
|
|
}
|
|
}
|