Permalink
Browse files

Added (optional) ifindex parameter to socket_connect()

  • Loading branch information...
1 parent 1bf9662 commit 049a5aa14eb895cac0d450f811a8b2cd680762a4 @takigama committed Oct 18, 2012
Showing with 7 additions and 4 deletions.
  1. +7 −4 ext/sockets/sockets.c
View
@@ -193,6 +193,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_socket_connect, 0, 0, 2)
ZEND_ARG_INFO(0, socket)
ZEND_ARG_INFO(0, addr)
ZEND_ARG_INFO(0, port)
+ ZEND_ARG_INFO(0, ifindex)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_socket_strerror, 0, 0, 1)
@@ -1488,18 +1489,18 @@ PHP_FUNCTION(socket_create)
}
/* }}} */
-/* {{{ proto bool socket_connect(resource socket, string addr [, int port])
+/* {{{ proto bool socket_connect(resource socket, string addr [, int port [, int ifindex]])
Opens a connection to addr:port on the socket specified by socket */
PHP_FUNCTION(socket_connect)
{
zval *arg1;
php_socket *php_sock;
char *addr;
int retval, addr_len;
- long port = 0;
+ long port = 0, ifindex = -1;
int argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc TSRMLS_CC, "rs|l", &arg1, &addr, &addr_len, &port) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "rs|ll", &arg1, &addr, &addr_len, &port, &ifindex) == FAILURE) {
return;
}
@@ -1510,7 +1511,7 @@ PHP_FUNCTION(socket_connect)
case AF_INET6: {
struct sockaddr_in6 sin6 = {0};
- if (argc != 3) {
+ if (argc != 3 && argc != 4) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Socket of type AF_INET6 requires 3 arguments");
RETURN_FALSE;
}
@@ -1520,6 +1521,8 @@ PHP_FUNCTION(socket_connect)
sin6.sin6_family = AF_INET6;
sin6.sin6_port = htons((unsigned short int)port);
+ if(ifindex != -1) sin6.sin6_scope_id = ifindex;
+
if (! php_set_inet6_addr(&sin6, addr, php_sock TSRMLS_CC)) {
RETURN_FALSE;
}

0 comments on commit 049a5aa

Please sign in to comment.