Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Feb 3, 2025
1 parent 8fd2cc2 commit 6245a4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,8 @@ PHP_FUNCTION(socket_recvfrom)
unsigned short protocol = ntohs(e->h_proto);
unsigned char *payload = ((unsigned char *)e + sizeof(struct ethhdr));

fprintf(stderr, "0x%04x\n", protocol);

zval obj;
object_init_ex(&obj, socket_ethinfo_ce);
array_init(&zpayload);
Expand Down Expand Up @@ -1708,8 +1710,8 @@ PHP_FUNCTION(socket_recvfrom)
}
default:
zend_string_efree(recv_buf);
zval_ptr_dtor(&zpayload);
zval_ptr_dtor(&obj);
zval_ptr_dtor(&zpayload);
zval_ptr_dtor(&obj);
zend_value_error("unsupported ethernet protocol");
RETURN_THROWS();
}
Expand Down
13 changes: 13 additions & 0 deletions ext/sockets/tests/socket_afpacket.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ if (!function_exists("posix_getuid") || posix_getuid() != 0) {
var_dump($iindex);

socket_getpeername($s_c, $istr2, $iindex2);

$s_s = socket_create(AF_PACKET, SOCK_RAW, ETH_P_ALL);
$v_bind = socket_bind($s_s, 'lo');

$buf = str_repeat("0", ETH_FRAME_LEN) .
str_repeat("\xFF", 6) .
str_repeat("\x11", 6) .
"\x08\x00" .
str_pad("TEST", 46, "\x00");

var_dump(socket_sendto($s_s, $buf, strlen($buf), 0, "lo", 1));

socket_close($s_c);
?>
--EXPECTF--
Expand All @@ -35,3 +47,4 @@ string(2) "lo"
int(%i)

Warning: socket_getpeername(): unable to retrieve peer name [95]: %sot supported in %s on line %d
int(1574)

0 comments on commit 6245a4b

Please sign in to comment.