Skip to content

Commit 2ba3926

Browse files
committed
Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4: fix bug #65808 the socket_connect() won't work with IPv6 address 5.4.22-dev now Conflicts: configure.in ext/sockets/sockets.c main/php_version.h
2 parents 60e38b3 + 9209c19 commit 2ba3926

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

ext/sockets/multicast.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ static const char *_php_source_op_to_string(enum source_op sop);
6363
static int _php_source_op_to_ipv4_op(enum source_op sop);
6464
#endif
6565

66+
int php_string_to_if_index(const char *val, unsigned *out TSRMLS_DC)
67+
{
68+
#if HAVE_IF_NAMETOINDEX
69+
unsigned int ind;
70+
71+
ind = if_nametoindex(val);
72+
if (ind == 0) {
73+
php_error_docref(NULL TSRMLS_CC, E_WARNING,
74+
"no interface with name \"%s\" could be found", val);
75+
return FAILURE;
76+
} else {
77+
*out = ind;
78+
return SUCCESS;
79+
}
80+
#else
81+
php_error_docref(NULL TSRMLS_CC, E_WARNING,
82+
"this platform does not support looking up an interface by "
83+
"name, an integer interface index must be supplied instead");
84+
return FAILURE;
85+
#endif
86+
}
87+
6688
static int php_get_if_index_from_zval(zval *val, unsigned *out TSRMLS_DC)
6789
{
6890
int ret;
@@ -78,31 +100,17 @@ static int php_get_if_index_from_zval(zval *val, unsigned *out TSRMLS_DC)
78100
ret = SUCCESS;
79101
}
80102
} else {
81-
#if HAVE_IF_NAMETOINDEX
82-
unsigned int ind;
83103
zval_add_ref(&val);
84104
convert_to_string_ex(&val);
85-
ind = if_nametoindex(Z_STRVAL_P(val));
86-
if (ind == 0) {
87-
php_error_docref(NULL TSRMLS_CC, E_WARNING,
88-
"no interface with name \"%s\" could be found", Z_STRVAL_P(val));
89-
ret = FAILURE;
90-
} else {
91-
*out = ind;
92-
ret = SUCCESS;
93-
}
105+
ret = php_string_to_if_index(Z_STRVAL_P(val), out TSRMLS_CC);
94106
zval_ptr_dtor(&val);
95-
#else
96-
php_error_docref(NULL TSRMLS_CC, E_WARNING,
97-
"this platform does not support looking up an interface by "
98-
"name, an integer interface index must be supplied instead");
99-
ret = FAILURE;
100-
#endif
101107
}
102108

103109
return ret;
104110
}
105111

112+
113+
106114
static int php_get_if_index_from_array(const HashTable *ht, const char *key,
107115
php_socket *sock, unsigned int *if_index TSRMLS_DC)
108116
{

ext/sockets/multicast.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ int php_add4_to_if_index(
6565
php_socket *php_sock,
6666
unsigned *if_index TSRMLS_DC);
6767

68+
int php_string_to_if_index(const char *val, unsigned *out TSRMLS_DC);
69+
6870
int php_mcast_join(
6971
php_socket *sock,
7072
int level,

ext/sockets/sockaddr_conv.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_
1818
struct addrinfo hints;
1919
struct addrinfo *addrinfo = NULL;
2020
#endif
21+
char *scope = strchr(string, '%');
2122

2223
if (inet_pton(AF_INET6, string, &tmp)) {
2324
memcpy(&(sin6->sin6_addr.s6_addr), &(tmp.s6_addr), sizeof(struct in6_addr));
@@ -53,6 +54,22 @@ int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_
5354

5455
}
5556

57+
if (scope++) {
58+
long lval = 0;
59+
double dval = 0;
60+
unsigned scope_id = 0;
61+
62+
if (IS_LONG == is_numeric_string(scope, strlen(scope), &lval, &dval, 0)) {
63+
if (lval > 0 && lval <= UINT_MAX) {
64+
scope_id = lval;
65+
}
66+
} else {
67+
php_string_to_if_index(scope, &scope_id TSRMLS_CC);
68+
}
69+
70+
sin6->sin6_scope_id = scope_id;
71+
}
72+
5673
return 1;
5774
}
5875
/* }}} */

0 commit comments

Comments
 (0)