Skip to content

Commit 8abcb80

Browse files
committed
expose needed ETH_FRAME_LEN, fix socket_sendto, test.
1 parent d2cdf04 commit 8abcb80

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

ext/sockets/sockets.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,7 @@ PHP_FUNCTION(socket_recvfrom)
16581658
object_init_ex(arg2, socket_ethinfo_ce);
16591659
zend_update_property_string(Z_OBJCE_P(arg2), Z_OBJ_P(arg2), ZEND_STRL("macsrc"), ether_ntoa((struct ether_addr *)e->h_source));
16601660
zend_update_property_string(Z_OBJCE_P(arg2), Z_OBJ_P(arg2), ZEND_STRL("macdst"), ether_ntoa((struct ether_addr *)e->h_dest));
1661+
zend_update_property_long(Z_OBJCE_P(arg2), Z_OBJ_P(arg2), ZEND_STRL("ethprotocol"), protocol);
16611662
array_init(&zpayload);
16621663

16631664
switch (protocol) {
@@ -1826,7 +1827,7 @@ PHP_FUNCTION(socket_sendto)
18261827
sll.sll_halen = ETH_ALEN;
18271828

18281829
// TODO allows to use more user friendly type to replace raw buffer usage
1829-
retval = sendto(php_sock->bsd_socket, buf, ((size_t)len > buf_len) ? buf_len : (size_t)len, flags, (struct sockaddr *) &sin, sizeof(sin));
1830+
retval = sendto(php_sock->bsd_socket, buf, ((size_t)len > buf_len) ? buf_len : (size_t)len, flags, (struct sockaddr *) &sll, sizeof(sll));
18301831
break;
18311832
#endif
18321833
default:

ext/sockets/sockets.stub.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,11 @@
20062006
* @cvalue ETH_P_ALL
20072007
*/
20082008
const ETH_P_ALL = UNKNOWN;
2009+
/**
2010+
* @var int
2011+
* @cvalue ETH_FRAME_LEN
2012+
*/
2013+
const ETH_FRAME_LEN = UNKNOWN;
20092014
#endif
20102015

20112016
/**
@@ -2156,6 +2161,8 @@ final class SocketEthernetInfo
21562161
/** @readonly **/
21572162
public Socket $socket;
21582163
/** @readonly **/
2164+
public int $ethprotocol;
2165+
/** @readonly **/
21592166
public string $macsrc;
21602167
/** @readonly **/
21612168
public string $macdst;

ext/sockets/sockets_arginfo.h

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/sockets/tests/socket_afpacket.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ 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_ALL);
31+
$v_bind = socket_bind($s_s, 'lo');
32+
33+
$buf = str_pad(str_repeat("0", ETH_FRAME_LEN) .
34+
str_repeat("\xFF", 6) .
35+
str_repeat("\x11", 6) .
36+
"\x08\x00TEST ethernet", 2048, "\x00");
37+
38+
var_dump(socket_sendto($s_s, $buf, strlen($buf), 0, "lo", 1));
39+
40+
socket_close($s_s);
2941
socket_close($s_c);
3042
?>
3143
--EXPECTF--
@@ -35,3 +47,4 @@ string(2) "lo"
3547
int(%i)
3648

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

0 commit comments

Comments
 (0)