@@ -1516,6 +1516,8 @@ PHP_FUNCTION(socket_recvfrom)
1516
1516
#endif
1517
1517
#ifdef AF_PACKET
1518
1518
struct sockaddr_ll sll ;
1519
+ int protoid ;
1520
+ socklen_t protoidlen = sizeof (protoid );
1519
1521
#endif
1520
1522
char addrbuf [INET6_ADDRSTRLEN ];
1521
1523
socklen_t slen ;
@@ -1632,6 +1634,13 @@ PHP_FUNCTION(socket_recvfrom)
1632
1634
#endif
1633
1635
#ifdef AF_PACKET
1634
1636
case AF_PACKET :
1637
+ getsockopt (php_sock -> bsd_socket , SOL_SOCKET , SO_TYPE , (char * ) & protoid , & protoidlen );
1638
+
1639
+ // TODO: SOCK_DGRAM support
1640
+ if (protoid != SOCK_RAW ) {
1641
+ zend_argument_value_error (1 , "must be SOCK_RAW socket type" );
1642
+ RETURN_THROWS ();
1643
+ }
1635
1644
slen = sizeof (sll );
1636
1645
memset (& sll , 0 , sizeof (sll ));
1637
1646
sll .sll_family = AF_PACKET ;
@@ -1755,6 +1764,8 @@ PHP_FUNCTION(socket_sendto)
1755
1764
#ifdef AF_PACKET
1756
1765
struct sockaddr_ll sll ;
1757
1766
unsigned char halen ;
1767
+ int protoid ;
1768
+ socklen_t protoidlen = sizeof (protoid );
1758
1769
#endif
1759
1770
int retval ;
1760
1771
size_t buf_len ;
@@ -1841,12 +1852,19 @@ PHP_FUNCTION(socket_sendto)
1841
1852
#endif
1842
1853
#ifdef AF_PACKET
1843
1854
case AF_PACKET :
1855
+ getsockopt (php_sock -> bsd_socket , SOL_SOCKET , SO_TYPE , (char * ) & protoid , & protoidlen );
1856
+
1857
+ // TODO: SOCK_DGRAM support
1858
+ if (protoid != SOCK_RAW ) {
1859
+ zend_argument_value_error (1 , "must be SOCK_RAW socket type" );
1860
+ RETURN_THROWS ();
1861
+ }
1844
1862
if (port_is_null ) {
1845
1863
zend_argument_value_error (6 , "cannot be null when the socket type is AF_PACKET" );
1846
1864
RETURN_THROWS ();
1847
1865
}
1848
1866
1849
- halen = addr_len > ETH_ALEN ? ETH_ALEN : (unsigned char )addr_len ;
1867
+ halen = ZSTR_LEN ( addr ) > ETH_ALEN ? ETH_ALEN : (unsigned char )ZSTR_LEN ( addr ) ;
1850
1868
1851
1869
memset (& sll , 0 , sizeof (sll ));
1852
1870
memcpy (sll .sll_addr , addr , halen );
0 commit comments