Skip to content

Commit 9090e26

Browse files
committed
sockets ext for solaris update.
socket filter support, system can support up to 32 filters giving the possibility to retrive the full list. Closes #8191.
1 parent baebb73 commit 9090e26

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ PHP NEWS
2727
. Fixed bug GH-9089 (Fix memory leak on Randomizer::__construct()
2828
call twice) (zeriyoshi)
2929

30+
- Sockets:
31+
. Added SOL_FILTER socket option for Solaris. (David Carlier)
32+
3033
21 Jul 2022, PHP 8.2.0beta1
3134

3235
- CLI:

ext/sockets/sockets.c

+48
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,11 @@ static PHP_MINIT_FUNCTION(sockets)
552552
#ifdef SO_ACCEPTFILTER
553553
REGISTER_LONG_CONSTANT("SO_ACCEPTFILTER", SO_ACCEPTFILTER, CONST_CS | CONST_PERSISTENT);
554554
#endif
555+
#ifdef SOL_FILTER
556+
REGISTER_LONG_CONSTANT("SOL_FILTER", SOL_FILTER, CONST_CS | CONST_PERSISTENT);
557+
REGISTER_LONG_CONSTANT("FIL_ATTACH", FIL_ATTACH, CONST_CS | CONST_PERSISTENT);
558+
REGISTER_LONG_CONSTANT("FIL_DETACH", FIL_DETACH, CONST_CS | CONST_PERSISTENT);
559+
#endif
555560
#ifdef SO_DONTTRUNC
556561
REGISTER_LONG_CONSTANT("SO_DONTTRUNC", SO_DONTTRUNC, CONST_CS | CONST_PERSISTENT);
557562
#endif
@@ -2004,6 +2009,32 @@ PHP_FUNCTION(socket_get_option)
20042009
}
20052010
}
20062011

2012+
#ifdef SOL_FILTER
2013+
if (level == SOL_FILTER) {
2014+
switch (optname) {
2015+
2016+
case FIL_LIST: {
2017+
size_t i;
2018+
struct fil_info fi[32] = {{0}};
2019+
optlen = sizeof(fi);
2020+
2021+
if (getsockopt(php_sock->bsd_socket, level, optname, (char*)fi, &optlen) != 0) {
2022+
PHP_SOCKET_ERROR(php_sock, "Unable to retrieve socket option", errno);
2023+
RETURN_FALSE;
2024+
}
2025+
2026+
array_init(return_value);
2027+
2028+
for (i = 0; i < optlen / sizeof(struct fil_info); i++) {
2029+
add_index_string(return_value, i, fi[i].fi_name);
2030+
}
2031+
2032+
return;
2033+
}
2034+
}
2035+
}
2036+
#endif
2037+
20072038
optlen = sizeof(other_val);
20082039

20092040
if (getsockopt(php_sock->bsd_socket, level, optname, (char*)&other_val, &optlen) != 0) {
@@ -2177,6 +2208,23 @@ PHP_FUNCTION(socket_set_option)
21772208
}
21782209
#endif
21792210

2211+
#ifdef FIL_ATTACH
2212+
case FIL_ATTACH:
2213+
case FIL_DETACH: {
2214+
if (level != SOL_FILTER) {
2215+
php_error_docref(NULL, E_WARNING, "Invalid level");
2216+
RETURN_FALSE;
2217+
}
2218+
if (Z_TYPE_P(arg4) != IS_STRING) {
2219+
php_error_docref(NULL, E_WARNING, "Invalid filter argument type");
2220+
RETURN_FALSE;
2221+
}
2222+
opt_ptr = Z_STRVAL_P(arg4);
2223+
optlen = Z_STRLEN_P(arg4);
2224+
break;
2225+
}
2226+
#endif
2227+
21802228
default:
21812229
default_case:
21822230
convert_to_long(arg4);

0 commit comments

Comments
 (0)