8000 Add IPv6 support to Redis proper · jrtkcoder/phpredis@f974793 · GitHub
[go: up one dir, main page]

Skip to content

Commit f974793

Browse files
Add IPv6 support to Redis proper
1 parent 0d4b421 commit f974793

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

library.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,7 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
15621562
struct timeval tv, read_tv, *tv_ptr = NULL;
15631563
char *host = NULL, *persistent_id = NULL;
15641564
zend_string *errstr;
1565+
const char *fmtstr = "%s:%d";
15651566
int host_len, err = 0;
15661567
php_netstream_data_t *sock;
15671568
int tcp_flag = 1;
@@ -1584,8 +1585,15 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
15841585
} else {
15851586
if(redis_sock->port == 0)
15861587
redis_sock->port = 6379;
1587-
host_len = spprintf(&host, 0, "%s:%d", redis_sock->host,
1588-
redis_sock->port);
1588+
1589+
#ifdef HAVE_IPV6
1590+
/* If we've got IPv6 and find a colon in our address, convert to proper
1591+
* IPv6 [host]:port format */
1592+
if (strchr(redis_sock->host, ':') != NULL) {
1593+
fmtstr = "[%s]:%d";
1594+
}
1595+
#endif
1596+
host_len = spprintf(&host, 0, fmtstr, redis_sock->host, redis_sock->port);
15891597
}
15901598

15911599
if (redis_sock->persistent) {

0 commit comments

Comments
 (0)
0