From a0b4348abc09e00170a334c6f67ef399e8b36a1e Mon Sep 17 00:00:00 2001 From: Damjan Cvetko Date: Mon, 10 Jun 2013 12:11:14 +0200 Subject: [PATCH] Implements feature Bug #63472 ability to set SO_BINDTODEVICE on socket. --- NEWS | 4 ++ ext/sockets/sockets.c | 17 +++++++- .../tests/socket_set_option_bindtodevice.phpt | 40 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 ext/sockets/tests/socket_set_option_bindtodevice.phpt diff --git a/NEWS b/NEWS index be774f84f7..5c6f6b92be 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,10 @@ PHP NEWS . Fixed bug #65066 (Cli server not responsive when responding with 422 http status code). (Adam) +- Sockets: + . Implemented FR #63472 (Setting SO_BINDTODEVICE with socket_set_option). + (Damjan Cvetko) + ?? ??? 2013, PHP 5.4.17 - Core: diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index b3bcbf2600..0c0380861a 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -843,6 +843,9 @@ PHP_MINIT_FUNCTION(sockets) REGISTER_LONG_CONSTANT("SO_RCVTIMEO", SO_RCVTIMEO, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SO_TYPE", SO_TYPE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SO_ERROR", SO_ERROR, CONST_CS | CONST_PERSISTENT); +#ifdef SO_BINDTODEVICE + REGISTER_LONG_CONSTANT("SO_BINDTODEVICE", SO_BINDTODEVICE, CONST_CS | CONST_PERSISTENT); +#endif REGISTER_LONG_CONSTANT("SOL_SOCKET", SOL_SOCKET, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SOMAXCONN", SOMAXCONN, CONST_CS | CONST_PERSISTENT); #ifdef TCP_NODELAY @@ -2355,7 +2358,19 @@ ipv6_loop_hops: #endif break; } - +#ifdef SO_BINDTODEVICE + case SO_BINDTODEVICE: { + if (Z_TYPE_PP(arg4) == IS_STRING) { + opt_ptr = Z_STRVAL_PP(arg4); + optlen = Z_STRLEN_PP(arg4); + } else { + opt_ptr = ""; + optlen = 0; + } + break; + } +#endif + default: convert_to_long_ex(arg4); ov = Z_LVAL_PP(arg4); diff --git a/ext/sockets/tests/socket_set_option_bindtodevice.phpt b/ext/sockets/tests/socket_set_option_bindtodevice.phpt new file mode 100644 index 0000000000..05d718ce63 --- /dev/null +++ b/ext/sockets/tests/socket_set_option_bindtodevice.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test if socket_set_option() works, option:SO_BINDTODEVICE +--DESCRIPTION-- +-Bind to loopback 'lo' device (should exist) +-Bind to unexisting device +--SKIPIF-- + +--FILE-- + + +--EXPECTF-- +bool(true) + +Warning: socket_set_option(): unable to set socket option [19]: No such device in %s on line %d +bool(false) +--CREDITS-- +Damjan Cvetko, foreach.org -- 2.40.0