This patch adds some quite useful functionalities to socket_get_options() function.
1st of all, it adds the constant SOL_IP to indicate IP layer in the level parameter. 2nd, and the most important, it adds the SO_ORIGINAL_DST constant for the optname parameter, and adds this functionality of c's getsockopt() It applies and compiles cleanly in php-5.0.2 sources under linux 2.4.26 (slackware linux current). I think it will apply cleanly also into cvs. Things NOT tested: I don't have solaris, bsd, etc. to test it. If someone can test it and report necessary changes, or errors so I can make the changes, It will be appreciated. Regards Leo -- Leonardo Pedretti Axon Sistemas Líder de Equipo Proyecto Basalto
*** php-5.0.2/ext/sockets/sockets.c 2004-06-07 02:00:37.000000000 -0300 --- php-5.0.2.new/ext/sockets/sockets.c 2004-09-30 12:32:05.000000000 -0300 *************** *** 46,55 **** --- 46,56 ---- # include <unistd.h> # include <errno.h> # include <fcntl.h> # include <signal.h> # include <sys/uio.h> + #include <linux/netfilter_ipv4.h> # define IS_INVALID_SOCKET(a) (a->bsd_socket < 0) # define set_errno(a) (errno = a) # define set_h_errno(a) (h_errno = a) #else /* windows */ # include "php_sockets.h" *************** *** 457,475 **** --- 458,478 ---- REGISTER_LONG_CONSTANT("SO_KEEPALIVE", SO_KEEPALIVE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SO_DONTROUTE", SO_DONTROUTE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SO_LINGER", SO_LINGER, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SO_BROADCAST", SO_BROADCAST, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SO_OOBINLINE", SO_OOBINLINE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SO_ORIGINAL_DST", SO_ORIGINAL_DST, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SO_SNDBUF", SO_SNDBUF, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SO_RCVBUF", SO_RCVBUF, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SO_SNDLOWAT", SO_SNDLOWAT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SO_RCVLOWAT", SO_RCVLOWAT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SO_SNDTIMEO", SO_SNDTIMEO, CONST_CS | CONST_PERSISTENT); 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); REGISTER_LONG_CONSTANT("SOL_SOCKET", SOL_SOCKET, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SOL_IP", SOL_IP, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SOMAXCONN", SOMAXCONN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PHP_NORMAL_READ", PHP_NORMAL_READ, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("PHP_BINARY_READ", PHP_BINARY_READ, CONST_CS | CONST_PERSISTENT); #ifndef WIN32 *************** *** 1487,1496 **** --- 1490,1500 ---- PHP_FUNCTION(socket_get_option) { zval *arg1; struct linger linger_val; struct timeval tv; + struct sockaddr_in addr; socklen_t optlen; php_socket *php_sock; int other_val; long level, optname; *************** *** 1527,1536 **** --- 1531,1554 ---- add_assoc_long(return_value, "sec", tv.tv_sec); add_assoc_long(return_value, "usec", tv.tv_usec); break; + case SO_ORIGINAL_DST: + optlen = sizeof(addr); + + if (getsockopt(php_sock->bsd_socket, level, optname, &addr, &optlen) != 0) { + PHP_SOCKET_ERROR(php_sock, "unable to retrieve socket option", errno); + RETURN_FALSE; + } + + array_init(return_value); + + add_assoc_string(return_value, "dst_ip", inet_ntoa(addr.sin_addr), 1); + add_assoc_long(return_value, "dst_port", ntohs(addr.sin_port)); + + break; default: optlen = sizeof(other_val); if (getsockopt(php_sock->bsd_socket, level, optname, (char*)&other_val, &optlen) != 0) { PHP_SOCKET_ERROR(php_sock, "unable to retrieve socket option", errno);
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php