Skip to content

Commit 54bf792

Browse files
committed
expose needed ETH_FRAME_LEN, fix socket_sendto, test.
1 parent fc54cc9 commit 54bf792

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
@@ -1656,6 +1656,7 @@ PHP_FUNCTION(socket_recvfrom)
16561656
object_init_ex(arg2, socket_ethinfo_ce);
16571657
zend_update_property_string(Z_OBJCE_P(arg2), Z_OBJ_P(arg2), ZEND_STRL("macsrc"), ether_ntoa((struct ether_addr *)e->h_source));
16581658
zend_update_property_string(Z_OBJCE_P(arg2), Z_OBJ_P(arg2), ZEND_STRL("macdst"), ether_ntoa((struct ether_addr *)e->h_dest));
1659+
zend_update_property_long(Z_OBJCE_P(arg2), Z_OBJ_P(arg2), ZEND_STRL("ethprotocol"), protocol);
16591660
array_init(&zpayload);
16601661

16611662
switch (protocol) {
@@ -1825,7 +1826,7 @@ PHP_FUNCTION(socket_sendto)
18251826
sll.sll_halen = ETH_ALEN;
18261827

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

ext/sockets/sockets.stub.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,11 @@
20132013
* @cvalue ETH_P_ALL
20142014
*/
20152015
const ETH_P_ALL = UNKNOWN;
2016+
/**
2017+
* @var int
2018+
* @cvalue ETH_FRAME_LEN
2019+
*/
2020+
const ETH_FRAME_LEN = UNKNOWN;
20162021
#endif
20172022

20182023
/**
@@ -2163,6 +2168,8 @@ final class SocketEthernetInfo
21632168
/** @readonly **/
21642169
public Socket $socket;
21652170
/** @readonly **/
2171+
public int $ethprotocol;
2172+
/** @readonly **/
21662173
public string $macsrc;
21672174
/** @readonly **/
21682175
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)